diff --git a/include/v8-internal.h b/include/v8-internal.h index c56130300f..88de43cf57 100644 --- a/include/v8-internal.h +++ b/include/v8-internal.h @@ -17,6 +17,79 @@ namespace v8 { +enum CpuFeature { +#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64 + SSE4_2, + SSE4_1, + SSSE3, + SSE3, + SAHF, + AVX, + AVX2, + FMA3, + BMI1, + BMI2, + LZCNT, + POPCNT, + INTEL_ATOM, + CETSS, + +#elif V8_TARGET_ARCH_ARM + // - Standard configurations. The baseline is ARMv6+VFPv2. + ARMv7, // ARMv7-A + VFPv3-D32 + NEON + ARMv7_SUDIV, // ARMv7-A + VFPv4-D32 + NEON + SUDIV + ARMv8, // ARMv8-A (+ all of the above) + + // ARM feature aliases (based on the standard configurations above). + VFPv3 = ARMv7, + NEON = ARMv7, + VFP32DREGS = ARMv7, + SUDIV = ARMv7_SUDIV, + +#elif V8_TARGET_ARCH_ARM64 + JSCVT, + +#elif V8_TARGET_ARCH_MIPS64 + FPU, + FP64FPU, + MIPSr1, + MIPSr2, + MIPSr6, + MIPS_SIMD, // MSA instructions + +#elif V8_TARGET_ARCH_LOONG64 + FPU, + +#elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 + PPC_6_PLUS, + PPC_7_PLUS, + PPC_8_PLUS, + PPC_9_PLUS, + PPC_10_PLUS, + +#elif V8_TARGET_ARCH_S390X + FPU, + DISTINCT_OPS, + GENERAL_INSTR_EXT, + FLOATING_POINT_EXT, + VECTOR_FACILITY, + VECTOR_ENHANCE_FACILITY_1, + VECTOR_ENHANCE_FACILITY_2, + MISC_INSTR_EXT2, + +#elif V8_TARGET_ARCH_RISCV64 + FPU, + FP64FPU, + RISCV_SIMD, +#elif V8_TARGET_ARCH_RISCV32 + FPU, + FP64FPU, + RISCV_SIMD, +#endif + + NUMBER_OF_CPU_FEATURES +}; + class Array; class Context; class Data; diff --git a/include/v8-isolate.h b/include/v8-isolate.h index 9659300751..6dfcb25e51 100644 --- a/include/v8-isolate.h +++ b/include/v8-isolate.h @@ -199,6 +199,10 @@ enum class MemoryPressureLevel { kNone, kModerate, kCritical }; */ using StackState = cppgc::EmbedderStackState; +V8_EXPORT size_t GetCPUFeatureMask(); +V8_EXPORT size_t GetCPUFeatureMaskRescan(); +V8_EXPORT void SetCPUFeatureMask(size_t features); + /** * Isolate represents an isolated instance of the V8 engine. V8 isolates have * completely separate states. Objects from one isolate must not be used in diff --git a/src/api/api.cc b/src/api/api.cc index f291bd8e85..3f585eedf7 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -1128,6 +1128,20 @@ bool Data::IsFunctionTemplate() const { bool Data::IsContext() const { return Utils::OpenHandle(this)->IsContext(); } +size_t GetCPUFeatureMask() { + return internal::CpuFeatures::SupportedFeatures(); +} + +size_t GetCPUFeatureMaskRescan() { + internal::CpuFeatures::initialized_ = 0; + internal::CpuFeatures::supported_ = 0; + return internal::CpuFeatures::SupportedFeatures(); +} + +void SetCPUFeatureMask(size_t features) { + internal::CpuFeatures::supported_ = features; +} + void Context::Enter() { i::DisallowGarbageCollection no_gc; i::Context env = *Utils::OpenHandle(this); @@ -2998,7 +3012,7 @@ MaybeLocal ScriptCompiler::CompileModule( uint32_t ScriptCompiler::CachedDataVersionTag() { return static_cast(base::hash_combine( internal::Version::Hash(), internal::FlagList::Hash(), - static_cast(internal::CpuFeatures::SupportedFeatures()))); + static_cast(0))); } ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache( diff --git a/src/codegen/compiler.cc b/src/codegen/compiler.cc index 4b0cd12437..ae46901837 100644 --- a/src/codegen/compiler.cc +++ b/src/codegen/compiler.cc @@ -3457,6 +3457,8 @@ MaybeHandle GetSharedFunctionInfoForScriptImpl( MaybeHandle maybe_result; MaybeHandle