Skip to content

Add support for x86 FMA intrinsics#27183

Open
fanchenkong1 wants to merge 1 commit into
emscripten-core:mainfrom
fanchenkong1:enable-fma-support
Open

Add support for x86 FMA intrinsics#27183
fanchenkong1 wants to merge 1 commit into
emscripten-core:mainfrom
fanchenkong1:enable-fma-support

Conversation

@fanchenkong1

Copy link
Copy Markdown

This change follows #23035. It adds support for compiling x86 FMA intrinsics to WebAssembly. All 32 FMA intrinsics are implemented in a new <fmaintrin.h>, wired into <immintrin.h> and gated on __FMA__. Enable with -msimd128 -mfma.

Each intrinsic has a dual implementation:

  • With -mrelaxed-simd, it lowers to Wasm relaxed SIMD fused multiply-add.
  • With -msimd128 only, it is emulated with separate multiply and add/subtract.
    The 256-bit AVX variants are emulated by applying the 128-bit operation to each half of the vector. Compiler wiring adds -mfma to the SIMD Intel feature tower and defines __FMA__.

Tests:

  • test/sse/test_fma.cpp: self-contained correctness checks covering all 32 intrinsics (emulated path).
  • test/sse/test_fma_relaxed.cpp: exhaustive comparison against native x86 (relaxed SIMD path, x64 host only).

Implement all 32 FMA intrinsics in a new <fmaintrin.h>, wired into
<immintrin.h> and gated on __FMA__. Pass -msimd128 -mfma to enable.

Each intrinsic has a dual implementation:
- With -mrelaxed-simd, it lowers to Wasm relaxed SIMD fused multiply-add
  (relaxed_madd / relaxed_nmadd).
- With -msimd128 only, it is emulated with separate multiply and
  add/subtract.

The 256-bit AVX variants are emulated by applying the 128-bit operation
to each half of the vector.

Compiler wiring adds -mfma to the SIMD Intel feature tower and defines
__FMA__ accordingly. Documentation is added to the SIMD porting guide
and ChangeLog.

Tests:
- test/sse/test_fma.cpp: self-contained correctness checks covering all
  32 intrinsics, run with the emulated path.
- test/sse/test_fma_relaxed.cpp: exhaustive comparison against native x86,
  run with relaxed SIMD.
@sbc100 sbc100 requested a review from tlively June 25, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant