summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/interp/interp-math.h4
-rw-r--r--src/prebuilt/wasm2c.include.c38
-rw-r--r--src/wasm2c.c.tmpl38
3 files changed, 40 insertions, 40 deletions
diff --git a/src/interp/interp-math.h b/src/interp/interp-math.h
index f0ff96ef..3ae2666e 100644
--- a/src/interp/interp-math.h
+++ b/src/interp/interp-math.h
@@ -285,9 +285,9 @@ T WABT_VECTORCALL FloatMax(T lhs, T rhs) {
template <typename R, typename T> bool WABT_VECTORCALL CanConvert(T val) { return true; }
template <> inline bool WABT_VECTORCALL CanConvert<s32, f32>(f32 val) { return val >= -2147483648.f && val < 2147483648.f; }
-template <> inline bool WABT_VECTORCALL CanConvert<s32, f64>(f64 val) { return val >= -2147483648. && val <= 2147483647.; }
+template <> inline bool WABT_VECTORCALL CanConvert<s32, f64>(f64 val) { return val > -2147483649. && val < 2147483648.; }
template <> inline bool WABT_VECTORCALL CanConvert<u32, f32>(f32 val) { return val > -1.f && val < 4294967296.f; }
-template <> inline bool WABT_VECTORCALL CanConvert<u32, f64>(f64 val) { return val > -1. && val <= 4294967295.; }
+template <> inline bool WABT_VECTORCALL CanConvert<u32, f64>(f64 val) { return val > -1. && val < 4294967296.; }
template <> inline bool WABT_VECTORCALL CanConvert<s64, f32>(f32 val) { return val >= -9223372036854775808.f && val < 9223372036854775808.f; }
template <> inline bool WABT_VECTORCALL CanConvert<s64, f64>(f64 val) { return val >= -9223372036854775808. && val < 9223372036854775808.; }
template <> inline bool WABT_VECTORCALL CanConvert<u64, f32>(f32 val) { return val > -1.f && val < 18446744073709551616.f; }
diff --git a/src/prebuilt/wasm2c.include.c b/src/prebuilt/wasm2c.include.c
index bc0bc105..0f1b4b31 100644
--- a/src/prebuilt/wasm2c.include.c
+++ b/src/prebuilt/wasm2c.include.c
@@ -121,25 +121,25 @@ const char SECTION_NAME(declarations)[] =
" : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \\\n"
" : (x > y) ? x : y)\n"
"\n"
-"#define TRUNC_S(ut, st, ft, min, max, maxop, x) \\\n"
-" ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \\\n"
-" : (UNLIKELY((x) < (ft)(min) || (x) maxop (ft)(max))) ? TRAP(INT_OVERFLOW) \\\n"
-" : (ut)(st)(x))\n"
-"\n"
-"#define I32_TRUNC_S_F32(x) TRUNC_S(u32, s32, f32, INT32_MIN, INT32_MAX, >=, x)\n"
-"#define I64_TRUNC_S_F32(x) TRUNC_S(u64, s64, f32, INT64_MIN, INT64_MAX, >=, x)\n"
-"#define I32_TRUNC_S_F64(x) TRUNC_S(u32, s32, f64, INT32_MIN, INT32_MAX, >, x)\n"
-"#define I64_TRUNC_S_F64(x) TRUNC_S(u64, s64, f64, INT64_MIN, INT64_MAX, >=, x)\n"
-"\n"
-"#define TRUNC_U(ut, ft, max, maxop, x) \\\n"
-" ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \\\n"
-" : (UNLIKELY((x) <= (ft)-1 || (x) maxop (ft)(max))) ? TRAP(INT_OVERFLOW) \\\n"
-" : (ut)(x))\n"
-"\n"
-"#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, UINT32_MAX, >=, x)\n"
-"#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, UINT64_MAX, >=, x)\n"
-"#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, UINT32_MAX, >, x)\n"
-"#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, UINT64_MAX, >=, x)\n"
+"#define TRUNC_S(ut, st, ft, min, minop, max, x) \\\n"
+" ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \\\n"
+" : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \\\n"
+" : (ut)(st)(x))\n"
+"\n"
+"#define I32_TRUNC_S_F32(x) TRUNC_S(u32, s32, f32, (f32)INT32_MIN, >=, 2147483648.f, x)\n"
+"#define I64_TRUNC_S_F32(x) TRUNC_S(u64, s64, f32, (f32)INT64_MIN, >=, (f32)INT64_MAX, x)\n"
+"#define I32_TRUNC_S_F64(x) TRUNC_S(u32, s32, f64, -2147483649., >, 2147483648., x)\n"
+"#define I64_TRUNC_S_F64(x) TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x)\n"
+"\n"
+"#define TRUNC_U(ut, ft, max, x) \\\n"
+" ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \\\n"
+" : (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \\\n"
+" : (ut)(x))\n"
+"\n"
+"#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x)\n"
+"#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, (f32)UINT64_MAX, x)\n"
+"#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, 4294967296., x)\n"
+"#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x)\n"
"\n"
"#define DEFINE_REINTERPRET(name, t1, t2) \\\n"
" static inline t2 name(t1 x) { \\\n"
diff --git a/src/wasm2c.c.tmpl b/src/wasm2c.c.tmpl
index 8b1da692..c932b98c 100644
--- a/src/wasm2c.c.tmpl
+++ b/src/wasm2c.c.tmpl
@@ -118,25 +118,25 @@ DEFINE_STORE(i64_store32, u32, u64);
: (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \
: (x > y) ? x : y)
-#define TRUNC_S(ut, st, ft, min, max, maxop, x) \
- ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
- : (UNLIKELY((x) < (ft)(min) || (x) maxop (ft)(max))) ? TRAP(INT_OVERFLOW) \
- : (ut)(st)(x))
-
-#define I32_TRUNC_S_F32(x) TRUNC_S(u32, s32, f32, INT32_MIN, INT32_MAX, >=, x)
-#define I64_TRUNC_S_F32(x) TRUNC_S(u64, s64, f32, INT64_MIN, INT64_MAX, >=, x)
-#define I32_TRUNC_S_F64(x) TRUNC_S(u32, s32, f64, INT32_MIN, INT32_MAX, >, x)
-#define I64_TRUNC_S_F64(x) TRUNC_S(u64, s64, f64, INT64_MIN, INT64_MAX, >=, x)
-
-#define TRUNC_U(ut, ft, max, maxop, x) \
- ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
- : (UNLIKELY((x) <= (ft)-1 || (x) maxop (ft)(max))) ? TRAP(INT_OVERFLOW) \
- : (ut)(x))
-
-#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, UINT32_MAX, >=, x)
-#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, UINT64_MAX, >=, x)
-#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, UINT32_MAX, >, x)
-#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, UINT64_MAX, >=, x)
+#define TRUNC_S(ut, st, ft, min, minop, max, x) \
+ ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
+ : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
+ : (ut)(st)(x))
+
+#define I32_TRUNC_S_F32(x) TRUNC_S(u32, s32, f32, (f32)INT32_MIN, >=, 2147483648.f, x)
+#define I64_TRUNC_S_F32(x) TRUNC_S(u64, s64, f32, (f32)INT64_MIN, >=, (f32)INT64_MAX, x)
+#define I32_TRUNC_S_F64(x) TRUNC_S(u32, s32, f64, -2147483649., >, 2147483648., x)
+#define I64_TRUNC_S_F64(x) TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x)
+
+#define TRUNC_U(ut, ft, max, x) \
+ ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
+ : (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
+ : (ut)(x))
+
+#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x)
+#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, (f32)UINT64_MAX, x)
+#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, 4294967296., x)
+#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x)
#define DEFINE_REINTERPRET(name, t1, t2) \
static inline t2 name(t1 x) { \