simde icon indicating copy to clipboard operation
simde copied to clipboard

wasm fallback for _mm_alignr_epi8()?

Open liquidaty opened this issue 3 years ago • 4 comments

Hi,

Could anyone help me to construct a wasm fallback for _mm_alignr_epi8() (using emscripten)?

I see from https://emscripten.org/docs/porting/simd.html that it can be "emulated with a SIMD or+two shifts". However, not being particularly versed in SIMD operations, I'm not sure how to translate this into actual code.

Any suggestions as to how to exactly emulate _mm_alignr_epi8() in wasm?

liquidaty avatar Sep 21 '22 19:09 liquidaty

_mm_alignr_epi8() would map to wasm_i8x16_shuffle().

If for some reason you need a ~~dynamic~~ variable shift by bytes then that can be emulated using wasm_i8x16_swizzle().

aqrit avatar Sep 21 '22 21:09 aqrit

@liquidaty Did you see https://github.com/emscripten-core/emscripten/blame/9eff02bc816c50ab0e3b70a3bd5b72a8dc2893a2/system/include/compat/tmmintrin.h#L34-L37 ?

mr-c avatar May 10 '23 14:05 mr-c

at the least v8/turbofan should lower a wasm_i8x16_shuffle in this instance to 1 instruction on both SSSE3 and NEON: https://github.com/zeux/wasm-simd/blob/master/Shuffles.md#concats

However, I'm having trouble getting the disassembly to prove this...

aqrit avatar May 10 '23 23:05 aqrit

@aqrit If you use emscripten to compile the tests (perhaps by using the SIMDe development container) then you can run wasm2wat tests/x86/ssse3-native-c.wasm to get an assembly dump. It can be interesting to compare that to the non-native version at tests/x86/ssse3-emul-c.wasm. If you have diffoscope installed, then you can make the diff in one command: diffoscope tests/x86/ssse3-{emul,native}-c.wasm.

Note for using the docker container: To make it easier to examine the artifacts, use the PERSISTENT_BUILD_DIR option so you can inspect the build directory on your host system.

mr-c avatar May 11 '23 16:05 mr-c