-
Notifications
You must be signed in to change notification settings - Fork 352
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
Wasm32 SIMD Rust implementation #341
base: master
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for putting this together! This must've been a lot of work. And the benchmarks look wonderful.
One high-level question we should think about is whether we want to add Wasm support to the C implementation at the same time we add it to the Rust implementation. On the one hand, so far we've always done them both at the same time. On the other hand, Wasm is a very different beast from other SIMD extensions, dealing with different levels of support across different versions of GCC/Clang/MSVC seems like it would be a huge pain. What are your thoughts?
By the way, the MIPS build failure in CI is already fixed, and it should go away if you rebase. |
This code is based on rust_sse2.rs of the same distribution, and is subject to further improvements. Some comments are left intact even if their applicability is questioned. SIMD implementation is gated by `wasm32-simd` feature, portable version is used otherwise. Performance measurements with a primitive benchmark with ~16Kb of data: | M1 native | 11,610 ns | | M1 WASM SIMD | 13,355 ns | | M1 WASM | 22,037 ns | | x64 native | 6,713 ns | | x64 WASM SIMD | 11,985 ns | | x64 WASM | 25,978 ns | wasmtime v12.0.1 was used on both platforms. Closes BLAKE3-team#187.
Wasm SIMD API has certain function safe.
Well, it took about 4 evenings, given that I have very little experience with SIMD instructions beyond general idea. I'm still surprised it works :) I have very limited knowledge of C support in WASM land, but I've googled nothing except Emscripten compiler. And it seems it can translate SSE4 intrinsics to WASM: |
Certain functions' unsafety comes from v128 loads and store. If argument types guarantee that these loads and stores are safe, function is declared safe, and internal unsafe blocks are commented.
Apologies for the delay in reviewing this PR. I just wanted to mention that I haven't forgotten about it :) |
@oconnor663 Can it be a Christmas gift, please? |
@oconnor663 friendly ping :) |
Meanwhile one may use https://crates.io/crates/fluence-blake3 |
This code is based on
rust_sse2.rs
of the same distribution, and is subject to further improvements. Some comments are left intact even if their applicability is questionable.SIMD implementation is gated by
wasm32_simd
feature, portable version is used otherwise.Performance measurements with a primitive benchmark with ~16Kb of data:
wasmtime v12.0.1 was used on both platforms.
Closes #187.