v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
clobber-registers.cc
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
5
7
8// Check both {HOST_ARCH} and {TARGET_ARCH} to disable the functionality of this
9// file for cross-compilation. The reason is that the inline assembly code below
10// does not work for cross-compilation.
11#if V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM
13#elif V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64
15#elif V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32
17#elif V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64
19#elif V8_HOST_ARCH_LOONG64 && V8_TARGET_ARCH_LOONG64
21#elif V8_HOST_ARCH_MIPS64 && V8_TARGET_ARCH_MIPS64
23#endif
24
25namespace v8 {
26namespace internal {
27
28#if V8_CC_MSVC
29// msvc only support inline assembly on x86
30#if V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32
31#define CLOBBER_REGISTER(R) __asm xorps R, R
32
33#endif
34
35#else // !V8_CC_MSVC
36
37#if (V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64) || \
38 (V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32)
39#define CLOBBER_REGISTER(R) \
40 __asm__ volatile( \
41 "xorps " \
42 "%%" #R \
43 "," \
44 "%%" #R :: \
45 :);
46
47#elif V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64
48#define CLOBBER_REGISTER(R) __asm__ volatile("fmov " #R ",xzr" :::);
49
50#elif V8_HOST_ARCH_LOONG64 && V8_TARGET_ARCH_LOONG64
51#define CLOBBER_REGISTER(R) __asm__ volatile("movgr2fr.d $" #R ",$zero" :::);
52
53#elif V8_HOST_ARCH_MIPS64 && V8_TARGET_ARCH_MIPS64
54#define CLOBBER_USE_REGISTER(R) __asm__ volatile("dmtc1 $zero,$" #R :::);
55
56#endif // V8_HOST_ARCH_XXX && V8_TARGET_ARCH_XXX
57
58#endif // V8_CC_MSVC
59
60double ClobberDoubleRegisters(double x1, double x2, double x3, double x4) {
61 // clobber all double registers
62
63#if defined(CLOBBER_REGISTER)
64 DOUBLE_REGISTERS(CLOBBER_REGISTER)
65#undef CLOBBER_REGISTER
66 return 0;
67
68#elif defined(CLOBBER_USE_REGISTER)
69 DOUBLE_USE_REGISTERS(CLOBBER_USE_REGISTER)
70#undef CLOBBER_USE_REGISTER
71 return 0;
72
73#else
74 // TODO(v8:11798): This clobbers only subset of registers depending on
75 // compiler, Rewrite this in assembly to really clobber all registers. GCC for
76 // ia32 uses the FPU and does not touch XMM registers.
77 return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04;
78#endif // CLOBBER_REGISTER
79}
80
81} // namespace internal
82} // namespace v8
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4)
#define DOUBLE_REGISTERS(V)
#define DOUBLE_USE_REGISTERS(V)