Skip to content

Commit e79efe3

Browse files
authored
Implement _mm_abs_epi* with wasm_*_abs (#12372)
1 parent 0bc5869 commit e79efe3

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

site/source/docs/porting/simd.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,11 @@ The following table highlights the availability and expected performance of diff
783783
* - Intrinsic name
784784
- WebAssembly SIMD support
785785
* - _mm_abs_epi8
786-
- ⚠️ emulated with a SIMD shift+xor+add
786+
- ✅ wasm_i8x16_abs
787787
* - _mm_abs_epi16
788-
- ⚠️ emulated with a SIMD shift+xor+add
788+
- ✅ wasm_i16x8_abs
789789
* - _mm_abs_epi32
790-
- ⚠️ emulated with a SIMD shift+xor+add
790+
- ✅ wasm_i32x4_abs
791791
* - _mm_alignr_epi8
792792
- ⚠️ emulated with a SIMD or+two shifts
793793
* - _mm_hadd_epi16

system/include/SSE/tmmintrin.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,19 @@
1616
static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
1717
_mm_abs_epi8(__m128i __a)
1818
{
19-
__m128i __mask = (__m128i)wasm_i8x16_shr((v128_t)__a, 7);
20-
return _mm_xor_si128(_mm_add_epi8(__a, __mask), __mask);
19+
return (__m128i)wasm_i8x16_abs((v128_t)__a);
2120
}
2221

2322
static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
2423
_mm_abs_epi16(__m128i __a)
2524
{
26-
__m128i __mask = _mm_srai_epi16(__a, 15);
27-
return _mm_xor_si128(_mm_add_epi16(__a, __mask), __mask);
25+
return (__m128i)wasm_i16x8_abs((v128_t)__a);
2826
}
2927

3028
static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
3129
_mm_abs_epi32(__m128i __a)
3230
{
33-
__m128i __mask = _mm_srai_epi32(__a, 31);
34-
return _mm_xor_si128(_mm_add_epi32(__a, __mask), __mask);
31+
return (__m128i)wasm_i32x4_abs((v128_t)__a);
3532
}
3633

3734
#define _mm_alignr_epi8(__a, __b, __count) \

0 commit comments

Comments
 (0)