emscripten-core / emscripten-core/emscripten
Update double/float <=> int SIMD operations to use new WASM SIMD operations
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
For example `_mm_cvtss_si32` ([intel doco link](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_si32&ig_expand=2335,2335,4294,4284,4294,4272,2529,2203,2335)) is implemented as:
```
static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvtss_si32(__m128 __a)
{
int x = lrint(((__f32x4)__a)[0]);
if (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f)
return x;
else
return (int)0x80000000;
}
```
This is obviously going to be slow. Likely slower than not using SIMD.
The WASM SIMS spec was updated at some point ([link](https://github.com/WebAssembly/simd/blob/main/proposals/simd/SIMD.md#conversions)) with double/float <=> int conversions.
The above code could probably be implemented like:
```
static __inline__ int __attribute__((__always_inline__, __nodebug__)) _mm_cvtss_si32(__m128 __a)
{
return wasm_i32x4_trunc_sat_f32x4((v128_t)__a);
}
```
[Browser support is tracked here (sadly without version numbers)](https://github.com/WebAssembly/simd/blob/main/proposals/simd/ImplementationStatus.md), and these conversion operations appear to all be in the latest wasm_simd128.h from llvm.
@tlively you seem like the expert on this stuff.
Contributor guide
Assessment
This issue has not been assessed yet.