Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIMD extensions support in Emscripten?

I'm trying to use _mm_comieq_ss in a project that compiles using Emscripten (currently using 1.21.0 at the time of writing this), but it seems like the function is not available. I see that Emscripten provides emmintrin.h/xmmintrin.h and it looks quite complete, however some functions are missing (such as _mm_comieq_ss) so I am wondering what are my options here?

Should I use a different function, or is the Emscripten support for SIMD extensions not usable yet?

Thank you.

like image 779
Deathicon Avatar asked Sep 11 '25 04:09

Deathicon


1 Answers

See the emscripten docs on "Porting SIMD code targetting webassembly". At the time of this writing, _mm_comieq_ss is scalarized (uses of it will be converted into non-SIMD instructions).

If you're interested in why some instructions on that page are supported and some aren't, it explains that what Emscripten supports is correlated to the WASM SIMD proposal. For x86 SSE instructions that aren't directly in the proposal, it sometimes emulates them using combinations of other WASM SIMD instructions.

Inlining a comment by @PeterCordes:

Ironically, _mm_comieq_ss already is a scalar operation, reading the low float of two vectors, and producing integer FLAGS. (The comiss instruction, the same instruction a compiler would use for comparing two scalar float like for if (x == y)). Unlike cmpss, which produces a 0 or -1 (all-bits set) result in the low element of an XMM vector reg, leaving the others unchanged.

like image 198
starball Avatar answered Sep 13 '25 11:09

starball