Repository navigation
Support SIMD on the Emscripten target - #50
Open
guybedford wants to merge 1 commit into
Open
guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
Emscripten lowers the SSE2 and SSE4.1 intrinsics to wasm simd128, and cpu.h derives WEBP_HAVE_SSE2/SSE41 from the compiler's __SSE2__ and __SSE4_1__, so passing -msimd128 -msse2 (and -msse4.1 with the sse41 feature) when the Rust target has the simd128 feature is all that is needed. The vendored libwebp still selects its wasm CPU-info path on the legacy EMSCRIPTEN macro that emcc no longer defines; libwebp moved to __EMSCRIPTEN__ in v1.6.0-167 (53394835). Until the submodule is past that, -DEMSCRIPTEN in CFLAGS is additionally needed for the SSE2 paths to be selected at runtime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today
build.rshas no wasm32 arm, so libwebp is built as plain C instead of SIMD there.This adds support for
wasm32-unknown-emscripten, along with the SSE intrinsics flags. Emscripten lowers SSE2 and SSE4.1 intrinsics to wasm simd128 through its emulation headers, andcpu.hderivesWEBP_HAVE_SSE2/WEBP_HAVE_SSE41from the compiler's__SSE2__/__SSE4_1__.Note also that the vendored libwebp still selects its wasm CPU-info path on the legacy
EMSCRIPTENmacro, which emcc no longer defines - libwebp updated use to__EMSCRIPTEN__in v1.6.0-167 (53394835). Until the submodule moves past that commit,-DEMSCRIPTENis needed inCFLAGSadditionally, but I didn't want to hard-code that here since it will be ironed out in the next release and can be set manually in the mean time.All tests are passing on Node.js, to run them, first set env vars:
Then run:
cargo test --target wasm32-unknown-emscripten --no-default-features --features stdIn terms of performance, decoding a 4 MP lossy WebP went from 141 ms (plain C) to about 105 ms with the SSE2 paths active, with identical output.