v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
cpu-features.h
Go to the documentation of this file.
1// Copyright 2018 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.
4
5#ifndef V8_CODEGEN_CPU_FEATURES_H_
6#define V8_CODEGEN_CPU_FEATURES_H_
7
9
10namespace v8 {
11
12namespace internal {
13
14// CPU feature flags.
16#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
17 SSE4_2,
18 SSE4_1,
19 SSSE3,
20 SSE3,
21 SAHF,
22 AVX,
23 AVX2,
24 AVX_VNNI,
25 AVX_VNNI_INT8,
26 FMA3,
27 BMI1,
28 BMI2,
29 LZCNT,
30 POPCNT,
31 INTEL_ATOM,
32 INTEL_JCC_ERRATUM_MITIGATION,
33 CETSS,
34 F16C,
35
36#elif V8_TARGET_ARCH_ARM
37 // - Standard configurations. The baseline is ARMv6+VFPv2.
38 ARMv7, // ARMv7-A + VFPv3-D32 + NEON
39 ARMv7_SUDIV, // ARMv7-A + VFPv4-D32 + NEON + SUDIV
40 ARMv8, // ARMv8-A (+ all of the above)
41
42 // ARM feature aliases (based on the standard configurations above).
43 VFPv3 = ARMv7,
44 NEON = ARMv7,
45 VFP32DREGS = ARMv7,
46 SUDIV = ARMv7_SUDIV,
47
48#elif V8_TARGET_ARCH_ARM64
49 JSCVT,
50 DOTPROD,
51 // Large System Extension, include atomic operations on memory: CAS, LDADD,
52 // STADD, SWP, etc.
53 LSE,
54 // A form of PMULL{2} with a 128-bit (1Q) result.
55 PMULL1Q,
56 // Half-precision NEON ops support.
57 FP16,
58 SHA3,
59
60#elif V8_TARGET_ARCH_MIPS64
61 FPU,
62 FP64FPU,
63 MIPSr1,
64 MIPSr2,
65 MIPSr6,
66 MIPS_SIMD, // MSA instructions
67
68#elif V8_TARGET_ARCH_LOONG64
69 FPU,
70
71#elif V8_TARGET_ARCH_PPC64
72 PPC_8_PLUS,
73 PPC_9_PLUS,
74 PPC_10_PLUS,
75
76#elif V8_TARGET_ARCH_S390X
77 FPU,
78 DISTINCT_OPS,
79 GENERAL_INSTR_EXT,
80 FLOATING_POINT_EXT,
81 VECTOR_FACILITY,
82 VECTOR_ENHANCE_FACILITY_1,
83 VECTOR_ENHANCE_FACILITY_2,
84 MISC_INSTR_EXT2,
85
86#elif V8_TARGET_ARCH_RISCV64 || V8_TARGET_ARCH_RISCV32
87 FPU,
88 FP64FPU,
89 RISCV_SIMD,
90 ZBA,
91 ZBB,
92 ZBS,
93 ZICOND,
94#endif
95
97};
98
99// CpuFeatures keeps track of which features are supported by the target CPU.
100// Supported features must be enabled by a CpuFeatureScope before use.
101// Example:
102// if (assembler->IsSupported(SSE3)) {
103// CpuFeatureScope fscope(assembler, SSE3);
104// // Generate code containing SSE3 instructions.
105// } else {
106// // Generate alternative code.
107// }
109 public:
110 CpuFeatures(const CpuFeatures&) = delete;
112
113 static void Probe(bool cross_compile) {
114 static_assert(NUMBER_OF_CPU_FEATURES <= kBitsPerInt);
115 if (initialized_) return;
116 initialized_ = true;
117 ProbeImpl(cross_compile);
118 }
119
120 static unsigned SupportedFeatures() {
121 Probe(false);
122 return supported_;
123 }
124
125 static bool IsSupported(CpuFeature f) {
126 return (supported_ & (1u << f)) != 0;
127 }
128
129 static void SetSupported(CpuFeature f) { supported_ |= 1u << f; }
130 static void SetUnsupported(CpuFeature f) { supported_ &= ~(1u << f); }
131
132 static bool SupportsWasmSimd128();
133
134 static inline bool SupportsOptimizer();
135
136 static inline unsigned icache_line_size() {
137 DCHECK_NE(icache_line_size_, 0);
138 return icache_line_size_;
139 }
140
141 static inline unsigned dcache_line_size() {
142 DCHECK_NE(dcache_line_size_, 0);
143 return dcache_line_size_;
144 }
145
146 static void PrintTarget();
147 static void PrintFeatures();
148
149 private:
150 friend void V8_EXPORT_PRIVATE FlushInstructionCache(void*, size_t);
151 friend class ExternalReference;
152 // Flush instruction cache.
153 static void FlushICache(void* start, size_t size);
154
155 // Platform-dependent implementation.
156 static void ProbeImpl(bool cross_compile);
157
158 static unsigned supported_;
159 static unsigned icache_line_size_;
160 static unsigned dcache_line_size_;
161 static bool initialized_;
162 // This variable is only used for certain archs to query SupportWasmSimd128()
163 // at runtime in builtins using an extern ref. Other callers should use
164 // CpuFeatures::SupportWasmSimd128().
166 static bool supports_cetss_;
167};
168
169} // namespace internal
170} // namespace v8
171#endif // V8_CODEGEN_CPU_FEATURES_H_
static bool IsSupported(CpuFeature f)
static unsigned SupportedFeatures()
static bool supports_wasm_simd_128_
static void Probe(bool cross_compile)
static unsigned supported_
static unsigned icache_line_size_
static unsigned dcache_line_size_
CpuFeatures & operator=(const CpuFeatures &)=delete
CpuFeatures(const CpuFeatures &)=delete
static unsigned dcache_line_size()
static unsigned icache_line_size()
static void SetSupported(CpuFeature f)
static void SetUnsupported(CpuFeature f)
int start
void FlushInstructionCache(void *start, size_t size)
constexpr int kBitsPerInt
Definition globals.h:687
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define V8_EXPORT_PRIVATE
Definition macros.h:460