Emscripten compilation error when SIMD support is enabled
Summary
Currently it's impossible to build any Eigen code with Emscripten compiler unless EIGEN_DONT_VECTORIZE is defined.
Environment
- Operating System : Ubuntu 20.04.4 LTS
- Architecture : x64
- Eigen Version : 3.4.0
- Emscripten Version : 3.1.8
- Target architecture : wasm
- Compiler flags : -msimd128 -msse4.1
Minimal Example
Basically including anything Eigen causes compilation failure.
//#define EIGEN_DONT_VECTORIZE
#include <Eigen/Core>
Steps to reproduce
- Build with emscripten
What is the current bug behavior?
In file included from /home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:345:
/home/ovostrikov/emsdk/upstream/lib/clang/15.0.0/include/mmintrin.h:14:2: error: "This header is only meant to be used on x86 and x64 architecture"
#error "This header is only meant to be used on x86 and x64 architecture"
In file included from /home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/Core:205:
/home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h:457:36: error: invalid output constraint '+x' in asm
asm("minps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
^
/home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h:476:36: error: invalid output constraint '+x' in asm
asm("minpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
^
/home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h:507:36: error: invalid output constraint '+x' in asm
asm("maxps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
^
/home/ovostrikov/.conan/data/eigen/3.4.0/matsdk/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3/Eigen/src/Core/arch/SSE/PacketMath.h:526:36: error: invalid output constraint '+x' in asm
asm("maxpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
What is the expected correct behavior?
Build should succeed.
Anything else that might help
Seems like there are two separate issues here
-
#include <mmintrin.h>in Eigen/src/Core/util/ConfigureVectorization.h. This header is platform dependent. Including justimmintrin.h, as done for Intel compiler, should work just fine for Emscripten. - Four snippets of asm code in Eigen/src/Core/arch/SSE/PacketMath.h. They use
#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63to check if we are building with older version of GCC, but should probably use#if EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC < 63instead.