Skip to content

Relaxed SIMD support#6151

Open
syrusakbary wants to merge 3 commits intomainfrom
relaxed-simd
Open

Relaxed SIMD support#6151
syrusakbary wants to merge 3 commits intomainfrom
relaxed-simd

Conversation

@syrusakbary
Copy link
Member

Added support for Relaxed SIMD in Cranelift and LLVM compilers

Copilot AI review requested due to automatic review settings February 1, 2026 19:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for the WebAssembly Relaxed SIMD proposal to Wasmer, implementing the feature in both the Cranelift and LLVM compiler backends.

Changes:

  • Added comprehensive test suite for Relaxed SIMD operations including relaxed min/max, multiply-add, lane selection, dot products, swizzle, truncation, and Q15 multiply-round
  • Implemented Relaxed SIMD operator support in both LLVM and Cranelift compilers
  • Added test infrastructure to support "either" assertions for non-deterministic relaxed SIMD results and enabled the relaxed_simd feature flag

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/wast/spec/proposals/relaxed-simd/*.wast Seven test files containing comprehensive spec tests for all relaxed SIMD operations
tests/lib/wast/src/wast.rs Added support for "either" assertions to handle non-deterministic relaxed SIMD behavior
tests/ignores.txt Added test ignores for singlepass (no SIMD support) and cranelift+riscv64 (no SIMD on riscv)
tests/compilers/wast.rs Added relaxed_simd feature flag detection and enablement
build.rs Registered relaxed-simd test directory for test generation
lib/compiler-llvm/src/translator/code.rs Implemented all relaxed SIMD operators in LLVM backend (min/max, madd/nmadd, laneselect, dot products, swizzle, truncation, q15mulr)
lib/compiler-cranelift/src/translator/code_translator.rs Implemented all relaxed SIMD operators in Cranelift backend with type_of function updates

Comment on lines +75 to +76
;; form https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "form" should be "from" in this comment. This appears to be a typo in the test file comment.

Suggested change
;; form https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +159
;; form https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "form" should be "from" in this comment. This appears to be a typo in the test file comment.

Suggested change
;; form https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c
;; from https://www.vinc17.net/software/fma-tests.c

Copilot uses AI. Check for mistakes.
(either (v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))

;; out of range, returns 0 or modulo 15 if < 128
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "modulo 15" but should say "modulo 16" since i8x16 has 16 elements with valid indices 0-15. When indices 16-31 are provided and taken modulo 16, they map to indices 0-15, which matches the expected result in line 24.

Copilot uses AI. Check for mistakes.

;; Check that multiple calls to the relaxed instruction with same inputs returns same results.

;; out of range, returns 0 or modulo 15 if < 128
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "modulo 15" but should say "modulo 16" since i8x16 has 16 elements with valid indices 0-15. When indices 16-31 are provided and taken modulo 16, they map to indices 0-15, which matches the expected result in line 39.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@marxin marxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve just read the WA proposal (1) and noticed that the primary motivation for the extension is to allow more relaxed semantics for already existing WA instructions. For example, for the Operator::I8x16Swizzle instruction we currently clamp indices to the valid range (0–15) before generating the extract/insert sequence. In the relaxed variant, however, we can emit more aggressive code that is allowed to select a defined value, often resulting in fewer assembly instructions. This is essentially the core motivation behind Relaxed SIMD, and we should aim for implementations that are as fast as possible.

Aside from the newly introduced fused multiply-add (and negative multiply-add) instructions, all other instructions mainly serve as optimization opportunities, since their output semantics are intentionally more permissive.

It would also be beneficial to include the IMPLEMENTATION_DEFINED_ONE_OF documentation entry from the spec for each instruction. This would better document the expected "contract" and make the relaxed behavior more explicit. For example:

def relaxed_i8x16_swizzle(a: i8x16, s: i8x16):
    result = []
    for i in range(16):
        if s[i] < 16:
            result[i] = a[s[i]]
        elif s[i] < 128:
            result[i] = IMPLEMENTATION_DEFINED_ONE_OF(0, a[s[i] % 16])
        else:
            result[i] = 0
    return result

Footnotes

  1. https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md

ashvardanian added a commit to ashvardanian/SimSIMD that referenced this pull request Feb 2, 2026
With new FMA instructions in Relaxed WASM SIMD,
we can implement fast dot products and spatial metrics
for USearch in the browser & on edge.

Wasmer is about to gain support:
wasmerio/wasmer#6151
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.

2 participants