Skip to content

Commit 5057a3b

Browse files
vksnkxnnpack-bot
authored andcommitted
Add floor, ceil, round, sqrt, abs simd wrappers for wasm,
PiperOrigin-RevId: 891830263
1 parent 2142e53 commit 5057a3b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ynnpack/base/simd/test/wasm_simd128.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,15 @@ TEST_MAX(wasm_simd128, f32, 4);
112112
TEST_MAX(wasm_simd128, s16, 8);
113113
TEST_MAX(wasm_simd128, u8, 16);
114114

115+
TEST_FLOOR(wasm_simd128, f32, 4);
116+
TEST_CEIL(wasm_simd128, f32, 4);
117+
TEST_ROUND(wasm_simd128, f32, 4);
118+
TEST_SQRT(wasm_simd128, f32, 4);
119+
120+
TEST_ABS(wasm_simd128, s8, 16);
121+
TEST_ABS(wasm_simd128, s16, 8);
122+
TEST_ABS(wasm_simd128, s32, 4);
123+
TEST_ABS(wasm_simd128, f32, 4);
124+
115125
} // namespace simd
116126
} // namespace ynn

ynnpack/base/simd/wasm_simd128.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ YNN_ALWAYS_INLINE u8x16 max(u8x16 a, u8x16 b) {
491491
return u8x16{wasm_u8x16_max(a.v, b.v)};
492492
}
493493

494+
YNN_ALWAYS_INLINE f32x4 abs(f32x4 a) { return f32x4{wasm_f32x4_abs(a.v)}; }
495+
YNN_ALWAYS_INLINE u32x4 abs(s32x4 a) { return u32x4{wasm_i32x4_abs(a.v)}; }
496+
YNN_ALWAYS_INLINE u16x8 abs(s16x8 a) { return u16x8{wasm_i16x8_abs(a.v)}; }
497+
YNN_ALWAYS_INLINE u8x16 abs(s8x16 a) { return u8x16{wasm_i8x16_abs(a.v)}; }
498+
499+
YNN_ALWAYS_INLINE f32x4 floor(f32x4 a) { return f32x4{wasm_f32x4_floor(a.v)}; }
500+
YNN_ALWAYS_INLINE f32x4 ceil(f32x4 a) { return f32x4{wasm_f32x4_ceil(a.v)}; }
501+
YNN_ALWAYS_INLINE f32x4 round(f32x4 a) {
502+
return f32x4{wasm_f32x4_nearest(a.v)};
503+
}
504+
YNN_ALWAYS_INLINE f32x4 sqrt(f32x4 a) { return f32x4{wasm_f32x4_sqrt(a.v)}; }
505+
494506
} // namespace simd
495507

496508
} // namespace ynn

0 commit comments

Comments
 (0)