diff --git a/js/moz.configure b/js/moz.configure index 62318474dbe2..f446abab37c5 100644 --- a/js/moz.configure +++ b/js/moz.configure @@ -833,6 +833,54 @@ def wasm_simd(value, jit_enabled, simulator, cranelift_enabled, target): set_config("ENABLE_WASM_SIMD", wasm_simd) set_define("ENABLE_WASM_SIMD", wasm_simd) + +# Support for Intel AVX instruction. +# +# AVX is exclusively used in WebAssembly SIMD instructions at the moment: +# set direct dependency on "--enable-wasm-simd". +# ===================================================== + + +@depends(milestone.is_nightly, "--enable-wasm-simd", "--enable-simulator", target) +def default_wasm_avx(is_nightly, wasm_simd_enabled, simulator, target): + if not wasm_simd_enabled: + return + + if simulator: + return + + if target.cpu in ("x86_64", "x86"): + return is_nightly + + +option( + "--enable-wasm-avx", + default=default_wasm_avx, + help="{Enable|Disable} AVX support for WebAssembly SIMD", +) + + +@depends("--enable-wasm-avx", "--enable-wasm-simd", "--enable-simulator", target) +def wasm_avx(value, wasm_simd_enabled, simulator, target): + if not value: + return + + if not wasm_simd_enabled: + die("--enable-wasm-avx requires --enable-wasm-simd") + + if simulator: + die("--enable-wasm-avx is not supported for simulators") + + if target.cpu in ("x86_64", "x86"): + return True + + die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits") + + +set_config("ENABLE_WASM_AVX", wasm_avx) +set_define("ENABLE_WASM_AVX", wasm_avx) + + # Wormhole opcodes are Intel-only. They are private to Firefox, but we need them for some # experiments on release and so they ride the trains. diff --git a/js/public/Initialization.h b/js/public/Initialization.h index b2c41938f228..79c6cf28ece6 100644 --- a/js/public/Initialization.h +++ b/js/public/Initialization.h @@ -179,7 +179,7 @@ extern JS_PUBLIC_API void JS_ShutDown(void); namespace JS { // Enable support for AVX instructions in the JIT/Wasm backend on x86/x64 // platforms. Must be called before JS_Init*. -void SetAVXEnabled(); +void SetAVXEnabled(bool enabled); } // namespace JS #endif diff --git a/js/src/jit/x86-shared/Assembler-x86-shared.cpp b/js/src/jit/x86-shared/Assembler-x86-shared.cpp index 6b73ad72ed78..9a829f380574 100644 --- a/js/src/jit/x86-shared/Assembler-x86-shared.cpp +++ b/js/src/jit/x86-shared/Assembler-x86-shared.cpp @@ -203,7 +203,11 @@ AssemblerX86Shared::DoubleCondition AssemblerX86Shared::InvertCondition( CPUInfo::SSEVersion CPUInfo::maxSSEVersion = UnknownSSE; CPUInfo::SSEVersion CPUInfo::maxEnabledSSEVersion = UnknownSSE; bool CPUInfo::avxPresent = false; +#ifdef ENABLE_WASM_AVX +bool CPUInfo::avxEnabled = true; +#else bool CPUInfo::avxEnabled = false; +#endif bool CPUInfo::popcntPresent = false; bool CPUInfo::bmi1Present = false; bool CPUInfo::bmi2Present = false; diff --git a/js/src/jit/x86-shared/Assembler-x86-shared.h b/js/src/jit/x86-shared/Assembler-x86-shared.h index f8eab0db4788..edd52c7c5238 100644 --- a/js/src/jit/x86-shared/Assembler-x86-shared.h +++ b/js/src/jit/x86-shared/Assembler-x86-shared.h @@ -263,6 +263,10 @@ class CPUInfo { SetMaxEnabledSSEVersion(SSE4_1); avxEnabled = false; } + static void SetAVXDisabled() { + MOZ_ASSERT(!FlagsHaveBeenComputed()); + avxEnabled = false; + } static void SetAVXEnabled() { MOZ_ASSERT(!FlagsHaveBeenComputed()); avxEnabled = true; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index fb8f3fd01bad..61654ad998cf 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -12197,11 +12197,20 @@ int main(int argc, char** argv) { '\0', "no-sse42", "Pretend CPU does not support SSE4.2 instructions " "to test JIT codegen (no-op on platforms other than x86 and x64).") || +#ifdef ENABLE_WASM_AVX + !op.addBoolOption('\0', "enable-avx", + "No-op. AVX is enabled by default, if available.") || + !op.addBoolOption( + '\0', "no-avx", + "Pretend CPU does not support AVX or AVX2 instructions " + "to test JIT codegen (no-op on platforms other than x86 and x64).") || +#else !op.addBoolOption('\0', "enable-avx", "AVX is disabled by default. Enable AVX. " "(no-op on platforms other than x86 and x64).") || !op.addBoolOption('\0', "no-avx", "No-op. AVX is currently disabled by default.") || +#endif !op.addBoolOption('\0', "more-compartments", "Make newGlobal default to creating a new " "compartment.") || @@ -12389,6 +12398,12 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } } + if (op.getBoolOption("no-avx")) { + js::jit::CPUInfo::SetAVXDisabled(); + if (!sCompilerProcessFlags.append("--no-avx")) { + return EXIT_FAILURE; + } + } if (op.getBoolOption("enable-avx")) { js::jit::CPUInfo::SetAVXEnabled(); if (!sCompilerProcessFlags.append("--enable-avx")) { diff --git a/js/src/vm/Initialization.cpp b/js/src/vm/Initialization.cpp index e5552134a337..f96f24052db5 100644 --- a/js/src/vm/Initialization.cpp +++ b/js/src/vm/Initialization.cpp @@ -329,7 +329,13 @@ JS_PUBLIC_API bool JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, #if defined(ENABLE_WASM_SIMD) && \ (defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86)) -void JS::SetAVXEnabled() { js::jit::CPUInfo::SetAVXEnabled(); } +void JS::SetAVXEnabled(bool enabled) { + if (enabled) { + js::jit::CPUInfo::SetAVXEnabled(); + } else { + js::jit::CPUInfo::SetAVXDisabled(); + } +} #endif JS_PUBLIC_API void JS::DisableJitBackend() { diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index e5644f850c1a..1b0026cc8bac 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -6802,7 +6802,7 @@ # Changing these prefs requires a restart. - name: javascript.options.wasm_simd_avx type: bool - value: false + value: @IS_NIGHTLY_BUILD@ mirror: always #endif #endif diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index 043a42a9351b..2b7934e7848d 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -256,9 +256,7 @@ static void InitializeJS() { (defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86)) // Update static engine preferences, such as AVX, before // `JS_InitWithFailureDiagnostic` is called. - if (mozilla::StaticPrefs::javascript_options_wasm_simd_avx()) { - JS::SetAVXEnabled(); - } + JS::SetAVXEnabled(mozilla::StaticPrefs::javascript_options_wasm_simd_avx()); #endif const char* jsInitFailureReason = JS_InitWithFailureDiagnostic();