simd-everywhere / simde

Implementations of SIMD instruction sets for systems which don't natively support them.
https://simd-everywhere.github.io/blog/
MIT License
2.27k stars 236 forks source link

Build fails for wasm32-wasi target: _Float16 is not supported on this target #1187

Open UnitedMarsupials opened 1 month ago

UnitedMarsupials commented 1 month ago

Hello. As you may know, Mozilla bundles an older version of simde with their sources, and it works. I'm trying to use the latest version (0.8.2) installed by the FreeBSD port on my machine.

Unfortunately, compiling for the wasm32-wasi fails:

clang++18 --target=wasm32-wasi --sysroot=/opt/share/wasi-sysroot -o sse_optimized.wasm -c -I/n/home/ports/www/firefox/work/firefox-126.0.2/media/libsoundtouch/src -I/n/home/ports/www/firefox/work/.build/media/libsoundtouch/src -I/n/home/ports/www/firefox/work/.build/security/rlbox -I/n/home/ports/www/firefox/work/.build/dist/include -I/opt/include/nspr -I/opt/include -I/opt/include/nss -I/opt/include/nspr -I/n/home/ports/www/firefox/work/.build/dist/include/nss -I/opt/include -I/opt/include/libpng16 -I/opt/include/pixman-1 -Os -fno-exceptions -fno-strict-aliasing -DNDEBUG=1 -DTRIMMED=1 -DMOZ_IN_WASM_SANDBOX -DMOZ_SAMPLE_TYPE_FLOAT32=1 -DSOUNDTOUCH_ALLOW_SSE=1 -DSOUNDTOUCH_WASM_SIMD=1 -DSIMDE_ENABLE_NATIVE_ALIASES=1 -DBUILDING_SOUNDTOUCH=1 -DST_NO_EXCEPTION_HANDLING=1 -msimd128 -I/n/home/ports/www/firefox/work/.build/dist/stl_wrappers -MD -MP -MF .deps/sse_optimized.wasm.pp   /n/home/ports/www/firefox/work/firefox-126.0.2/media/libsoundtouch/src/sse_optimized.cpp
In file included from /n/home/ports/www/firefox/work/firefox-126.0.2/media/libsoundtouch/src/sse_optimized.cpp:65:
In file included from /opt/include/simde/x86/avx2.h:33:
In file included from /opt/include/simde/x86/avx.h:28:
In file included from /opt/include/simde/x86/sse.h:34:
/opt/include/simde/x86/../simde-f16.h:98:11: error: _Float16 is not supported on this target
   98 |   typedef _Float16 simde_float16;
      |           ^
1 error generated.

Is this a bug? Perhaps, I can set the SIMDE_FLOAT16_API to something as a work-around?

mr-c commented 1 month ago

Hello @UnitedMarsupials and thank you for opening this issue.

Yes, you can #define SIMDE_FLOAT16_API 1 before importing any SIMDe header to work around this. Or as a compiler command line option -DSIMDE_FLOAT16_API=1.

What flags are set by the wasm32-wasi target? It would be good to add a fix near https://github.com/simd-everywhere/simde/blob/e30e6ec44cdbc85c04d6cb1f26fb6d93f43cc5ea/simde/simde-f16.h#L71

UnitedMarsupials commented 1 month ago

Yes, you can #define SIMDE_FLOAT16_API 1

Thanks! Let me try that.

What flags are set by the wasm32-wasi target?

Using the trick from here, I conclude, that, in case of clang, at least, these are:

#define __wasi__ 1
#define __wasm 1
#define __wasm32 1
#define __wasm32__ 1
#define __wasm__ 1
#define __wasm_mutable_globals__ 1
#define __wasm_sign_ext__ 1
mr-c commented 1 month ago

Yes, you can #define SIMDE_FLOAT16_API 1

Thanks! Let me try that.

Did that work?

How can we test SIMDE with WASI in our CI? We can make a PR to not use the _Float16 if __wasi__ is defined, but I'll want a CI build & run of the tests under WASI to confirm