Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WebAssembly Relaxed SIMD #126

Merged
merged 1 commit into from
Sep 5, 2024
Merged

Conversation

CryZe
Copy link
Contributor

@CryZe CryZe commented Jul 14, 2024

This makes use of the WebAssembly Relaxed SIMD instructions, which trade off consistent results across architectures for certain edge cases to gain better performance. These differing edge case behaviors already exist in the native equivalents that are used in the SIMD implementation, so this does not regress any correctness.

This is about to stabilize in nightly. So this will likely have to wait for the feature to ride to stable Rust.

@CryZe CryZe force-pushed the relaxed-simd branch 2 times, most recently from 1c0fd06 to ffb16e5 Compare July 14, 2024 11:26
@CryZe
Copy link
Contributor Author

CryZe commented Jul 14, 2024

I also looked into the relaxed multiply add instructions, which would be cool to use too. However, what's weird is that Skia itself uses fused multiply add (fma) as well when it's available, and it doesn't when it's not. This however means that Skia at least in theory should produce different results depending on whether those instructions are used or not. So depending on how you feel about that, I can add support for fma as well (which I have ready locally).

It seems like you perceived the same problem in #88

@RazrFalcon
Copy link
Collaborator

These differing edge case behaviors already exist in the native equivalents that are used in the SIMD implementation, so this does not regress any correctness.

Are you sure? x86 and amd64 should produce identical results.

@CryZe
Copy link
Contributor Author

CryZe commented Jul 15, 2024

Maybe I wasn't clear. This is actually already documented in the functions, that NaN and co. behave differently, but it doesn't seem like we ever run into those edge cases:
image

Relaxed SIMD maps to these exact same intrinsics, so it has the same edge cases.

@RazrFalcon
Copy link
Collaborator

Got it.

This makes use of the [WebAssembly Relaxed
SIMD](https://github.com/WebAssembly/relaxed-simd) instructions, trade
off consistent results across architectures for certain edge cases to
gain better performance. These differing edge case behaviors already
exist in the native equivalents that are used in the SIMD
implementation, so this does not regress any correctness.
@CryZe
Copy link
Contributor Author

CryZe commented Sep 5, 2024

I thought the just released Rust 1.81 is the one with relaxed SIMD, but it turns out to be 1.82 that releases with it. Technically the code at least still builds with 1.81, just doesn't make use of the new instructions yet, so this PR could technically already get merged and released, but we can also wait until 1.82.

@CryZe
Copy link
Contributor Author

CryZe commented Sep 5, 2024

I guess fused multiply should be a separate PR anyway, because it concerns x86 and ARM as well.

@RazrFalcon RazrFalcon merged commit 01c86ce into linebender:master Sep 5, 2024
3 checks passed
@RazrFalcon
Copy link
Collaborator

Thanks! Looks good to me.

What is the difference between wasi and wasip1? I'm not following WASM development.

@CryZe CryZe deleted the relaxed-simd branch September 5, 2024 18:43
@CryZe
Copy link
Contributor Author

CryZe commented Sep 5, 2024

There is WASI Preview 1, which is now renamed into WASI 0.1 and also WASI 0.2 that is about to release in 1.82 (was supposed to release today, but they messed up). They renamed the target to wasip1 and wasip2 respectively (p standing for either "point" or "preview") with a warning if you still use the old one to ensure you get the WASI version that you expect.

Theoretically CI could eventually start using WASI 0.2, but it's a lot more complex of a target (they have a whole new component system going on), which doesn't really buy us anything, if what we want to do is just test the actual wasm architecture, rather than any WASI relevant features themselves.

@RazrFalcon
Copy link
Collaborator

Got it. Thanks for the explanation!

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