-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The current build system uses the wasm_f64x2_relaxed_madd intrinsic, which requires the -mrelaxed-simd compiler flag. This leads to build failures in environments where relaxed SIMD is not supported or enabled, including common CI environments such as ubuntu-latest on GitHub Actions.
Details
-
The following compiler error occurs when building without
-mrelaxed-simd:error: always_inline function 'wasm_f64x2_relaxed_madd' requires target feature 'relaxed-simd', but would be inlined into function 'mul_residue_fma' that is compiled without support for 'relaxed-simd' -
Additionally,
wat2wasmfails to parse binaries generated with relaxed SIMD instructions, even with the--enable-allflag:parse exception: invalid code after SIMD prefix: 263 -
Relaxed SIMD is not yet supported by all WebAssembly engines or toolchains. Relying on it by default limits portability and breaks GitHub Actions and other automated build environments.
What Works
-
Replacing
wasm_f64x2_relaxed_madd(wasm_f64x2_neg(c), b, a)with the portable alternative:wasm_f64x2_add(wasm_f64x2_mul(a, b), wasm_f64x2_neg(c))
allows the build to complete without needing
-mrelaxed-simd. -
All tests (
randomx_single.js,randomx_threaded.js,superscalarhash.js) pass with this substitution.
Proposed Solution
Introduce a preprocessor guard or build-time toggle to control usage of relaxed SIMD:
Option 1: Use preprocessor fallback in C code
#ifdef __wasm_relaxed_simd__
return wasm_f64x2_relaxed_madd(wasm_f64x2_neg(c), b, a);
#else
return wasm_f64x2_add(wasm_f64x2_mul(a, b), wasm_f64x2_neg(c));
#endifOption 2: Add USE_RELAXED_SIMD flag to Makefile
ifeq ($(USE_RELAXED_SIMD),1)
WASM_CFLAGS += -mrelaxed-simd
endifThen conditionally define the relaxed version or fallback in the C source.
Benefits
- Improves compatibility across compilers and runtimes.
- Allows GitHub Actions and other CI systems to build the project without patching source code.
- Maintains support for relaxed SIMD for advanced/local use.
Temporary CI workaround example:
# Remove the SIMD flag
sed -i 's/-mrelaxed-simd//g' Makefile
# Replace the relaxed intrinsic with standard instructions
sed -i 's/wasm_f64x2_relaxed_madd(wasm_f64x2_neg(c), b, a)/wasm_f64x2_add(wasm_f64x2_mul(a, b), wasm_f64x2_neg(c))/g' src/jit/stubs/semifloat.c