[runtime] ClobberDoubleRegisters rewritten in platform-specific assembly

Currently ClobberDoubleRegisters is implemented in C++ and is
not guaranteed to clobber all registers. Rewritten in assembly
to clobber all double registers

Bug: v8:11798
Change-Id: I11c09bd247c929d251e6e509ea5cc76b9981ea98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3490715
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79380}
This commit is contained in:
jameslahm 2022-03-07 13:36:32 +08:00 committed by V8 LUCI CQ
parent 48b443f692
commit daa3ce759f
6 changed files with 86 additions and 15 deletions

View File

@ -1216,6 +1216,8 @@ filegroup(
"src/execution/arguments-inl.h",
"src/execution/arguments.cc",
"src/execution/arguments.h",
"src/execution/clobber-registers.cc",
"src/execution/clobber-registers.h",
"src/execution/encoded-c-signature.cc",
"src/execution/encoded-c-signature.h",
"src/execution/embedder-state.h",

View File

@ -2912,6 +2912,7 @@ v8_header_set("v8_internal_headers") {
"src/diagnostics/unwinder.h",
"src/execution/arguments-inl.h",
"src/execution/arguments.h",
"src/execution/clobber-registers.h",
"src/execution/embedder-state.h",
"src/execution/encoded-c-signature.h",
"src/execution/execution.h",
@ -4171,6 +4172,7 @@ v8_source_set("v8_base_without_compiler") {
"src/diagnostics/perf-jit.cc",
"src/diagnostics/unwinder.cc",
"src/execution/arguments.cc",
"src/execution/clobber-registers.cc",
"src/execution/embedder-state.cc",
"src/execution/encoded-c-signature.cc",
"src/execution/execution.cc",

View File

@ -3,16 +3,3 @@
// found in the LICENSE file.
#include "src/execution/arguments.h"
namespace v8 {
namespace internal {
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4) {
// TODO(v8:11798): This clobbers only subset of registers depending on
// compiler, Rewrite this in assembly to really clobber all registers. GCC for
// ia32 uses the FPU and does not touch XMM registers.
return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04;
}
} // namespace internal
} // namespace v8

View File

@ -5,6 +5,7 @@
#ifndef V8_EXECUTION_ARGUMENTS_H_
#define V8_EXECUTION_ARGUMENTS_H_
#include "src/execution/clobber-registers.h"
#include "src/handles/handles.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/objects/objects.h"
@ -105,8 +106,6 @@ Handle<S> Arguments<T>::at(int index) const {
return Handle<S>::cast(obj);
}
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4);
#ifdef DEBUG
#define CLOBBER_DOUBLE_REGISTERS() ClobberDoubleRegisters(1, 2, 3, 4);
#else

View File

@ -0,0 +1,63 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/execution/clobber-registers.h"
#include "src/base/build_config.h"
#if V8_HOST_ARCH_ARM
#include "src/codegen/arm/register-arm.h"
#elif V8_HOST_ARCH_ARM64
#include "src/codegen/arm64/register-arm64.h"
#elif V8_HOST_ARCH_IA32
#include "src/codegen/ia32/register-ia32.h"
#elif V8_HOST_ARCH_X64
#include "src/codegen/x64/register-x64.h"
#endif
namespace v8 {
namespace internal {
#if V8_CC_MSVC
// msvc only support inline assembly on x86
#if V8_HOST_ARCH_IA32
#define CLOBBER_REGISTER(R) __asm xorps R, R
#endif
#else // !V8_CC_MSVC
#if V8_HOST_ARCH_X64 || V8_HOST_ARCH_IA32
#define CLOBBER_REGISTER(R) \
__asm__ volatile( \
"xorps " \
"%%" #R \
"," \
"%%" #R :: \
:);
#elif V8_HOST_ARCH_ARM64
#define CLOBBER_REGISTER(R) __asm__ volatile("fmov " #R ",xzr" :::);
#endif // V8_HOST_ARCH_X64 || V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM64
#endif // V8_CC_MSVC
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4) {
// clobber all double registers
#ifdef CLOBBER_REGISTER
DOUBLE_REGISTERS(CLOBBER_REGISTER)
#undef CLOBBER_REGISTER
return 0;
#else
// TODO(v8:11798): This clobbers only subset of registers depending on
// compiler, Rewrite this in assembly to really clobber all registers. GCC for
// ia32 uses the FPU and does not touch XMM registers.
return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04;
#endif // CLOBBER_REGISTER
}
} // namespace internal
} // namespace v8

View File

@ -0,0 +1,18 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_EXECUTION_CLOBBER_REGISTERS_H_
#define V8_EXECUTION_CLOBBER_REGISTERS_H_
namespace v8 {
namespace internal {
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4);
}
} // namespace v8
#endif // V8_EXECUTION_CLOBBER_REGISTERS_H_