Skip to content

Commit f45f801

Browse files
authored
Remove type checks for SIMD constant intrinsics (#9789)
These checks are not consistent with how C is expected to behave and cause more friction than they are worth, as evidenced by #9768.
1 parent 47e8474 commit f45f801

File tree

2 files changed

+56
-70
lines changed

2 files changed

+56
-70
lines changed

system/include/wasm_simd128.h

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ typedef double __f64x2 __attribute__((__vector_size__(16), __aligned__(16)));
3232

3333
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("simd128"), __min_vector_width__(128)))
3434

35-
#ifdef __cplusplus
36-
#include <type_traits>
37-
#define __SAME_TYPE(t1, t2) (std::is_same<t1, t2>::value)
38-
#else
39-
#define __SAME_TYPE(t1, t2) (__builtin_types_compatible_p(t1, t2))
40-
#endif
41-
42-
#define __REQUIRE_CONSTANT(e, ty, msg) _Static_assert(__builtin_constant_p(e) && __SAME_TYPE(__typeof__(e), ty), msg)
35+
#define __REQUIRE_CONSTANT(e) _Static_assert(__builtin_constant_p(e), "Expected constant")
4336

4437
// v128 wasm_v128_load(void* mem)
4538
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_v128_load(const void* __mem) {
@@ -196,78 +189,78 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f64x2_make(double c0, double c1
196189
// v128_t wasm_i8x16_constant(...)
197190
#define wasm_i8x16_const(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15) \
198191
__extension__({ \
199-
__REQUIRE_CONSTANT(c0, int8_t, "expected constant int8_t"); \
200-
__REQUIRE_CONSTANT(c1, int8_t, "expected constant int8_t"); \
201-
__REQUIRE_CONSTANT(c2, int8_t, "expected constant int8_t"); \
202-
__REQUIRE_CONSTANT(c3, int8_t, "expected constant int8_t"); \
203-
__REQUIRE_CONSTANT(c4, int8_t, "expected constant int8_t"); \
204-
__REQUIRE_CONSTANT(c5, int8_t, "expected constant int8_t"); \
205-
__REQUIRE_CONSTANT(c6, int8_t, "expected constant int8_t"); \
206-
__REQUIRE_CONSTANT(c7, int8_t, "expected constant int8_t"); \
207-
__REQUIRE_CONSTANT(c8, int8_t, "expected constant int8_t"); \
208-
__REQUIRE_CONSTANT(c9, int8_t, "expected constant int8_t"); \
209-
__REQUIRE_CONSTANT(c10, int8_t, "expected constant int8_t"); \
210-
__REQUIRE_CONSTANT(c11, int8_t, "expected constant int8_t"); \
211-
__REQUIRE_CONSTANT(c12, int8_t, "expected constant int8_t"); \
212-
__REQUIRE_CONSTANT(c13, int8_t, "expected constant int8_t"); \
213-
__REQUIRE_CONSTANT(c14, int8_t, "expected constant int8_t"); \
214-
__REQUIRE_CONSTANT(c15, int8_t, "expected constant int8_t"); \
192+
__REQUIRE_CONSTANT(c0); \
193+
__REQUIRE_CONSTANT(c1); \
194+
__REQUIRE_CONSTANT(c2); \
195+
__REQUIRE_CONSTANT(c3); \
196+
__REQUIRE_CONSTANT(c4); \
197+
__REQUIRE_CONSTANT(c5); \
198+
__REQUIRE_CONSTANT(c6); \
199+
__REQUIRE_CONSTANT(c7); \
200+
__REQUIRE_CONSTANT(c8); \
201+
__REQUIRE_CONSTANT(c9); \
202+
__REQUIRE_CONSTANT(c10); \
203+
__REQUIRE_CONSTANT(c11); \
204+
__REQUIRE_CONSTANT(c12); \
205+
__REQUIRE_CONSTANT(c13); \
206+
__REQUIRE_CONSTANT(c14); \
207+
__REQUIRE_CONSTANT(c15); \
215208
(v128_t)(__i8x16){c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15}; \
216209
})
217210

218211
// v128_t wasm_i16x8_constant(...)
219-
#define wasm_i16x8_const(c0, c1, c2, c3, c4, c5, c6, c7) \
220-
__extension__({ \
221-
__REQUIRE_CONSTANT(c0, int16_t, "expected constant int16_t"); \
222-
__REQUIRE_CONSTANT(c1, int16_t, "expected constant int16_t"); \
223-
__REQUIRE_CONSTANT(c2, int16_t, "expected constant int16_t"); \
224-
__REQUIRE_CONSTANT(c3, int16_t, "expected constant int16_t"); \
225-
__REQUIRE_CONSTANT(c4, int16_t, "expected constant int16_t"); \
226-
__REQUIRE_CONSTANT(c5, int16_t, "expected constant int16_t"); \
227-
__REQUIRE_CONSTANT(c6, int16_t, "expected constant int16_t"); \
228-
__REQUIRE_CONSTANT(c7, int16_t, "expected constant int16_t"); \
229-
(v128_t)(__i16x8){c0, c1, c2, c3, c4, c5, c6, c7}; \
212+
#define wasm_i16x8_const(c0, c1, c2, c3, c4, c5, c6, c7) \
213+
__extension__({ \
214+
__REQUIRE_CONSTANT(c0); \
215+
__REQUIRE_CONSTANT(c1); \
216+
__REQUIRE_CONSTANT(c2); \
217+
__REQUIRE_CONSTANT(c3); \
218+
__REQUIRE_CONSTANT(c4); \
219+
__REQUIRE_CONSTANT(c5); \
220+
__REQUIRE_CONSTANT(c6); \
221+
__REQUIRE_CONSTANT(c7); \
222+
(v128_t)(__i16x8){c0, c1, c2, c3, c4, c5, c6, c7}; \
230223
})
231224

232225
// v128_t wasm_i32x4_constant(...)
233-
#define wasm_i32x4_const(c0, c1, c2, c3) \
234-
__extension__({ \
235-
__REQUIRE_CONSTANT(c0, int32_t, "expected constant int32_t"); \
236-
__REQUIRE_CONSTANT(c1, int32_t, "expected constant int32_t"); \
237-
__REQUIRE_CONSTANT(c2, int32_t, "expected constant int32_t"); \
238-
__REQUIRE_CONSTANT(c3, int32_t, "expected constant int32_t"); \
239-
(v128_t)(__i32x4){c0, c1, c2, c3}; \
226+
#define wasm_i32x4_const(c0, c1, c2, c3) \
227+
__extension__({ \
228+
__REQUIRE_CONSTANT(c0); \
229+
__REQUIRE_CONSTANT(c1); \
230+
__REQUIRE_CONSTANT(c2); \
231+
__REQUIRE_CONSTANT(c3); \
232+
(v128_t)(__i32x4){c0, c1, c2, c3}; \
240233
})
241234

242235
// v128_t wasm_f32x4_constant(...)
243-
#define wasm_f32x4_const(c0, c1, c2, c3) \
244-
__extension__({ \
245-
__REQUIRE_CONSTANT(c0, float, "expected constant float"); \
246-
__REQUIRE_CONSTANT(c1, float, "expected constant float"); \
247-
__REQUIRE_CONSTANT(c2, float, "expected constant float"); \
248-
__REQUIRE_CONSTANT(c3, float, "expected constant float"); \
249-
(v128_t)(__f32x4){c0, c1, c2, c3}; \
236+
#define wasm_f32x4_const(c0, c1, c2, c3) \
237+
__extension__({ \
238+
__REQUIRE_CONSTANT(c0); \
239+
__REQUIRE_CONSTANT(c1); \
240+
__REQUIRE_CONSTANT(c2); \
241+
__REQUIRE_CONSTANT(c3); \
242+
(v128_t)(__f32x4){c0, c1, c2, c3}; \
250243
})
251244

252245
#ifdef __wasm_unimplemented_simd128__
253246

254247
// v128_t wasm_i64x2_constant(...)
255-
#define wasm_i64x2_const(c0, c1) \
256-
__extension__({ \
257-
__REQUIRE_CONSTANT(c0, int64_t, "expected constant int64_t"); \
258-
__REQUIRE_CONSTANT(c1, int64_t, "expected constant int64_t"); \
259-
(v128_t)(__i64x2){c0, c1}; \
248+
#define wasm_i64x2_const(c0, c1) \
249+
__extension__({ \
250+
__REQUIRE_CONSTANT(c0); \
251+
__REQUIRE_CONSTANT(c1); \
252+
(v128_t)(__i64x2){c0, c1}; \
260253
})
261254

262255
// v128_t wasm_f64x2_constant(...)
263256
#define wasm_f64x2_const(c0, c1) \
264257
__extension__({ \
265-
__REQUIRE_CONSTANT(c0, double, "expected constant double"); \
266-
__REQUIRE_CONSTANT(c1, double, "expected constant double"); \
258+
__REQUIRE_CONSTANT(c0); \
259+
__REQUIRE_CONSTANT(c1); \
267260
(v128_t)(__f64x2){c0, c1}; \
268261
})
269262

270-
#endif // __wasm_unimplemented_sidm128__
263+
#endif // __wasm_unimplemented_simd128__
271264

272265
// v128_t wasm_i8x16_splat(int8_t a)
273266
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_splat(int8_t a) {

tests/test_wasm_intrinsics_simd.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,25 @@ void TESTFN i8x16_store(void *ptr, v128_t vec) {
5050
}
5151
v128_t TESTFN i8x16_const(void) {
5252
return wasm_i8x16_const(
53-
(int8_t)1, (int8_t)2, (int8_t)3, (int8_t)4,
54-
(int8_t)5, (int8_t)6, (int8_t)7, (int8_t)8,
55-
(int8_t)9, (int8_t)10, (int8_t)11, (int8_t)12,
56-
(int8_t)13, (int8_t)14, (int8_t)15, (int8_t)16
57-
);
53+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
5854
}
5955
v128_t TESTFN i16x8_const(void) {
60-
return wasm_i16x8_const(
61-
(int16_t)1, (int16_t)2, (int16_t)3, (int16_t)4,
62-
(int16_t)5, (int16_t)6, (int16_t)7, (int16_t)8
63-
);
56+
return wasm_i16x8_const(1, 2, 3, 4, 5, 6, 7, 8);
6457
}
6558
v128_t TESTFN i32x4_const(void) {
66-
return wasm_i32x4_const((int32_t)1, (int32_t)2, (int32_t)3, (int32_t)4);
59+
return wasm_i32x4_const(1, 2, 3, 4);
6760
}
6861
v128_t TESTFN f32x4_const(void) {
69-
return wasm_f32x4_const(1.f, 2.f, 3.f, 4.f);
62+
return wasm_f32x4_const(1, 2, 3, 4);
7063
}
7164

7265
#ifdef __wasm_unimplemented_simd128__
7366

7467
v128_t TESTFN i64x2_const(void) {
75-
return wasm_i64x2_const((int64_t)1, (int64_t)2);
68+
return wasm_i64x2_const(1, 2);
7669
}
7770
v128_t TESTFN f64x2_const(void) {
78-
return wasm_f64x2_const(1., 2.);
71+
return wasm_f64x2_const(1, 2);
7972
}
8073

8174
#endif // __wasm_unimplemented_sidm128__

0 commit comments

Comments
 (0)