wasm: use relaxed-simd madd for v_muladd when available - #6001
Open
MMesch wants to merge 1 commit into
Open
Conversation
When emcc is invoked with -mrelaxed-simd, __wasm_relaxed_simd__ is
defined and wasm_f{32x4,64x2}_relaxed_madd intrinsics are available.
These lower to hardware FMA on engines that support relaxed-simd
(Chrome >=114, Firefox >=120, Safari >=16.4, Node >=22) and to
separate mul+add otherwise, so callers get FMA where possible with
no ABI change.
Off by default: builds not passing -mrelaxed-simd fall through to
the existing separate mul+add definitions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When emcc is invoked with
-mrelaxed-simd,__wasm_relaxed_simd__is defined and thewasm_f{32x4,64x2}_relaxed_maddintrinsics become available. These lower to hardware FMA on engines that support wasm relaxed-simd (Chrome >=114, Firefox >=120, Safari >=16.4, Node >=22) and to a separate mul+add otherwise, so callers get FMA where possible with no ABI change.Off by default: builds that do not pass
-mrelaxed-simdfall through to the existing separate mul+add definitions ofv_muladd_f32/v_muladd_f64, so no behavior change for the default wasm build.Notes
kernel/simd/intrin_wasm.h(+8 lines).gemmkernel_4x4_wasm128.c,trmmkernel_4x4_wasm128.c,zgemmkernel_2x2_wasm128.c) already callwasm_f{32x4,64x2}_relaxed_madddirectly under__wasm_relaxed_simd__. This patch extends the same behavior to everything that goes throughv_muladd, so Level-1 kernels benefit too.-msimd128 -mrelaxed-simd, disassembled withwasm2wat): 25 additionalrelaxed_maddemissions attributable to this patch, insdsdot_k(10) andsdot_k/ddot_k/srot_k(5 each) viakernel/generic/dot.c.numpy.correlateworkload, wasm overhead vs. native drops from ~7x to ~3.5x on relaxed-simd-capable engines (roughly 2x speedup of the wasm build itself). More rigorous benchmarks needed to confirm.