Skip to content

Improved wasm benchmark support and add support for wasm +relaxed-simd#101

Merged
bluss merged 11 commits into
masterfrom
wasm
Jul 3, 2026
Merged

Improved wasm benchmark support and add support for wasm +relaxed-simd#101
bluss merged 11 commits into
masterfrom
wasm

Conversation

@bluss

@bluss bluss commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Add support for +relaxed-simd in wasm, which increases performance and should degrade gracefully when not available. relaxed-simd adds a fused multiply-add instruction, except that it doesn't guarantee fused operation; it can also be implemented by multiply then add (which leaves us where we started).

  • Add short contributing document
  • Support --wasm in the benchmark runner, selectable features (simd128 with or without relaxed)
  • Add justfile to simplify running tests through wasmtime

Small refactoring in the wasm loop.

Unrolling the loop by 2 was explored - with just +simd128 it is a negative, with +simd128,+relaxed-simd it helps a bit on my intel laptop and helps nothing on my apple m4 laptop. Decision: no unrolling for now, keep it simple.

@byeongjee

Copy link
Copy Markdown
Contributor

Sounds good! I'll take a look tonight

@byeongjee

byeongjee commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@bluss With +simd128 and without +relaxed-simd, there was about a 6.5% degradation on my M2 Pro Mac, compared to the current master branch. I guess there might be some microarchitectural differences between M2 and M4, making loop unrolling harmful in M2.

When I unrolled the loop only if +relaxed-simd is on, I could avoid this (at the cost of longer, duplicated code).

If supporting a byte-precise matmul variant is also a main goal (so people would use +simd128 without +relaxed-simd), you could try that?

@bluss

bluss commented Jun 30, 2026

Copy link
Copy Markdown
Owner Author

Thanks for testing! I don't have any goals myself for wasm, so it's actually better if you as a user decide this. Is your use case only for +simd128 so far? (+relaxed-simd seems to be held back by lack of Safari support?)

Changing unrolling only for +relaxed-simd seems like the only way forward (or not changing it at all).

@byeongjee

Copy link
Copy Markdown
Contributor

Is your use case only for +simd128 so far?

Not really so far, but I think it's good to change unrolling only for +relaxed-simd if it's not a big burden.
Thanks!

bluss added 6 commits July 3, 2026 14:30
Just small changes - use a shuffle to splat a lane. One less intrinsic,
but compiler already ensured the result was the same, so no effect in
practice.

Unrolling was investigated here. On a laptop m4, unrolling had no
effect; on laptop i5, it had a small positive effect. Keep it simple and
avoid extra code for unrolling if its effect is small.
@bluss

bluss commented Jul 3, 2026

Copy link
Copy Markdown
Owner Author

Decision is to skip unrolling since it has no benefit on my m4 system (I benchmarked the sensitivity to that now), keep it simple. Now the PR just remains as a benchmark tool improvement, refactoring and opt-in relaxed-simd benefit.

@bluss bluss merged commit d2318c6 into master Jul 3, 2026
16 checks passed
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