emscripten-core / emscripten-core/emscripten
Definition of __m128i in compat/xmmintrin.h doesn't match Clang's emmintrin.h
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I might be completely off here so please correct my understanding:
we have this typedef for `__m128i`:
https://github.com/emscripten-core/emscripten/blob/388a83650902250927a8ef80ab9a9c1ae4ad3825/system/include/compat/xmmintrin.h#L24
and `__i32x4` is:
```cpp
typedef int __i32x4 __attribute__((__vector_size__(16), __aligned__(16)));
```
https://github.com/llvm/llvm-project/blob/a92dbadffe4ff81cbae7303b0f3e723e26fa77b1/clang/lib/Headers/wasm_simd128.h#L28
So the base type is int.
But in native header, `__m128i` is defined in `emmintrin.h`:
```cpp
typedef long long __m128i __attribute__((__vector_size__(16), __aligned__(16)));
```
https://github.com/llvm/llvm-project/blob/a92dbadffe4ff81cbae7303b0f3e723e26fa77b1/clang/lib/Headers/emmintrin.h#L16
And the base type here is long long, which doesn't match int.
This cause some problem with porting some native code, e.g. there are macros used in this project:
https://github.com/ermig1979/Simd/blob/master/src/Simd/SimdConst.h#L108-L117
to broadcast bytes to the 128-bit register, and it boils down to [bit shifts and setting 2 long long,](
https://github.com/ermig1979/Simd/blob/7b2e0afc53c76cc1e26cb446786ceb4a520e1ff5/src/Simd/SimdInit.h#L61) which then causes a problem:
```
src/Simd/SimdConst.h:110:31: error: constant expression evaluates to 217020518514230019 which cannot be narrowed to type 'int' [-Wc++11-narrowing]
const __m128i K8_03 = SIMD_MM_SET1_EPI8(0x03);
```
I guess I can work around this, but just curious about this difference in the typedefs (should we have `typedef __i64x2 __m128i;` instead?
@juj @tlively
Contributor guide
Assessment
This issue has not been assessed yet.