simde
simde copied to clipboard
wasm fallback for _mm_shuffle_epi8()?
Hi, I'm looking for a wasm fallback for _mm_shuffle_epi8() (using emscripten, for my case at least)
I see from https://emscripten.org/docs/porting/simd.html that it should be as simple as "emulated with a SIMD swizzle+and+const". However, not being particularly versed in SIMD operations, I'm not sure how to translate this into actual code.
I see that wasm/simd128.h has something similar in simde_wasm_i8x16_swizzle(), but it doesn't seem quite the same as _mm_shuffle_epi8().
Any suggestions as to how to exactly emulate _mm_shuffle_epi8() in wasm?
(BTW have the same question for _mm_alignr_epi8(), but will try to resolve this first before posting as a separate issue)
_mm_shuffle_epi8() zeros when index >u 0x7F. wasm_i8x16_swizzle() zeros when index >u 0x0F.
so you need to clear those three bits of the shuffle index.
_mm_shuffle_epi8(a, b) -> wasm_i8x16_swizzle(a, wasm_v128_and(b, wasm_i8x16_splat(0x8F)));
Will try it out thank you!