emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

AVX 256 functions accepting `__m{128,256}i_u` should accept `__m{128,256}i`

Open PaperStrike opened this issue 7 months ago • 7 comments

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.6 (1ddaae4d2d6dfbb678ecc193bc988820d1fc4633)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 4775e6d9099467df9363e1a3cd5950cc3d2fde05)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /data/home/sliphua/open/emsdk/upstream/bin

Failing command line in full: It fails to compile astc-encoder x86-64 AVX2 version. Below is the error and a working solution. The other steps to adapt to emscripten AVX seem irrelevant, so they are not written here.

The error:

$ cd ~/open/astc-encoder/build_avx2
$ emcmake cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../ -DASTCENC_ISA_AVX2=ON ..
$ emmake make
make: make
[  2%] Building CXX object Source/CMakeFiles/astcenc-avx2-static.dir/astcenc_averages_and_directions.cpp.o
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_averages_and_directions.cpp:23:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_internal.h:35:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_mathlib.h:460:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib.h:86:
/data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib_avx2_8.h:137:7: error: no matching function for call to '_mm256_loadu_si256'
  137 |                 m = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(p));
      |                     ^~~~~~~~~~~~~~~~~~
/data/home/sliphua/open/emsdk/upstream/emscripten/cache/sysroot/include/compat/avxintrin.h:1276:1: note: candidate function not viable: no known conversion from 'const __m256i *' to 'const __m256i_u *' for 1st argument
 1276 | _mm256_loadu_si256(__m256i_u const* __p) {
      | ^                  ~~~~~~~~~~~~~~~~~~~~
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_averages_and_directions.cpp:23:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_internal.h:35:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_mathlib.h:460:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib.h:86:
/data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib_avx2_8.h:189:16: error: no matching function for call to '_mm256_lddqu_si256'
  189 |                 return vint8(_mm256_lddqu_si256(reinterpret_cast<const __m256i*>(p)));
      |                              ^~~~~~~~~~~~~~~~~~
/data/home/sliphua/open/emsdk/upstream/emscripten/cache/sysroot/include/compat/avxintrin.h:1284:1: note: candidate function not viable: no known conversion from 'const __m256i *' to 'const __m256i_u *' for 1st argument
 1284 | _mm256_lddqu_si256(__m256i_u const* __p) {
      | ^                  ~~~~~~~~~~~~~~~~~~~~
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_averages_and_directions.cpp:23:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_internal.h:35:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_mathlib.h:460:
In file included from /data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib.h:86:
/data/home/sliphua/open/astc-encoder/Source/astcenc_vecmathlib_avx2_8.h:522:2: error: no matching function for call to '_mm256_storeu_si256'
  522 |         _mm256_storeu_si256(reinterpret_cast<__m256i*>(p), a.m);
      |         ^~~~~~~~~~~~~~~~~~~
/data/home/sliphua/open/emsdk/upstream/emscripten/cache/sysroot/include/compat/avxintrin.h:1322:1: note: candidate function not viable: no known conversion from '__m256i *' to '__m256i_u *' for 1st argument
 1322 | _mm256_storeu_si256(__m256i_u* __p, __m256i __a) {
      | ^                   ~~~~~~~~~~~~~~
3 errors generated.
make[2]: *** [Source/CMakeFiles/astcenc-avx2-static.dir/build.make:77: Source/CMakeFiles/astcenc-avx2-static.dir/astcenc_averages_and_directions.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:860: Source/CMakeFiles/astcenc-avx2-static.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
emmake: error: 'make' failed (returned 2)

A working solution: Manually adding the __m256i* overloads of the functions suggested by the error message to avxintrin.h resolves the error.

SIMDe uses void*, so it appears they don't have the issue. https://github.com/simd-everywhere/simde/blob/2af3dce9b2481b6b32139b1022cdfc02a633c898/simde/x86/avx.h#L4361

PaperStrike avatar Apr 09 '25 03:04 PaperStrike