Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emscripten: how can i compile a c file with an intrinsic header like immintrin.h?

I am trying to compile CLBG benchmarks with emscripten (C to WASM). However, most of them has included intrinsic headers (like <immintrin.h>) and that gave me a lot of errors (let`s use nbody.c as an example) like this:

nbody.c:137:20: error: use of undeclared identifier '__m128d' static alignas(__m128d) double

I already tried to compile with these flags

emcc nbody.c -o nbody.js -O2 -s WASM=1 -msse2 -msimd128

and it compiles. However, when I tried to run nbody.js with nodejs, it doesn`t work. I have also tried to run nodejs with

--experimental-wasm-simd

like this git tells, but it also doesn't work. It says:

failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Compiling function #4:"main" failed: invalid value type 'Simd128', enable with --experimental-wasm-simd @+422
CompileError: WebAssembly.instantiate(): Compiling function #4:"main" failed: invalid value type 'Simd128', enable with --experimental-wasm-simd @+422
RuntimeError: abort(CompileError: WebAssembly.instantiate(): Compiling function #4:"main" failed: invalid value type 'Simd128', enable with --experimental-wasm-simd @+422).
Build with -s ASSERTIONS=1 for more info.

Can anyone give me a hand? I am not understanding if this is already possible to do.

like image 706
João Macedo Avatar asked Oct 22 '25 12:10

João Macedo


1 Answers

Add these compile flags to C and CXX Flags

-fPIC -Wno-implicit-function-declaration -msse2 -msimd128 -experimental-wasm-simd
like image 193
Danoli3 Avatar answered Oct 24 '25 01:10

Danoli3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!