Conversation
There was a problem hiding this comment.
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 |
| ;; form https://www.vinc17.net/software/fma-tests.c | ||
| ;; from https://www.vinc17.net/software/fma-tests.c |
There was a problem hiding this comment.
The word "form" should be "from" in this comment. This appears to be a typo in the test file comment.
| ;; 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 |
| ;; form https://www.vinc17.net/software/fma-tests.c | ||
| ;; from https://www.vinc17.net/software/fma-tests.c |
There was a problem hiding this comment.
The word "form" should be "from" in this comment. This appears to be a typo in the test file comment.
| ;; 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 |
| (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 |
There was a problem hiding this comment.
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.
|
|
||
| ;; Check that multiple calls to the relaxed instruction with same inputs returns same results. | ||
|
|
||
| ;; out of range, returns 0 or modulo 15 if < 128 |
There was a problem hiding this comment.
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.
marxin
left a comment
There was a problem hiding this comment.
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 resultFootnotes
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
Added support for Relaxed SIMD in Cranelift and LLVM compilers