simde icon indicating copy to clipboard operation
simde copied to clipboard

wasm fallback for _mm_shuffle_epi8()?

Open liquidaty opened this issue 1 year ago • 2 comments

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)

liquidaty avatar Sep 08 '22 23:09 liquidaty

_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)));

aqrit avatar Sep 10 '22 21:09 aqrit

Will try it out thank you!

liquidaty avatar Sep 11 '22 18:09 liquidaty