From c3a71ff46d8f38e29896c321d89b6d0c3b90fbc1 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 26 Sep 2024 15:35:47 -0700 Subject: [FP16] Implement conversion operations. (#6974) Note: FP16 is a little different from F32/F64 since it can't represent the full 2^16 integer range. 65504 is the max whole integer. This leads to some slightly strange behavior when converting integers greater than 65504 since they become infinity. Specified at https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md --- src/support/safe_integer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/support/safe_integer.cpp') diff --git a/src/support/safe_integer.cpp b/src/support/safe_integer.cpp index 3a50b50ea..86ba2547a 100644 --- a/src/support/safe_integer.cpp +++ b/src/support/safe_integer.cpp @@ -98,6 +98,11 @@ int64_t wasm::toSInteger64(double x) { * 1 11111111 111...11 => 0xffffffff => -nan(0x7fffff) */ +bool wasm::isInRangeI16TruncS(int32_t i) { + uint32_t u = i; + return (u < 0x47000000U) || (u >= 0x80000000U && u <= 0xc7000000U); +} + bool wasm::isInRangeI32TruncS(int32_t i) { uint32_t u = i; return (u < 0x4f000000U) || (u >= 0x80000000U && u <= 0xcf000000U); @@ -108,6 +113,11 @@ bool wasm::isInRangeI64TruncS(int32_t i) { return (u < 0x5f000000U) || (u >= 0x80000000U && u <= 0xdf000000U); } +bool wasm::isInRangeI16TruncU(int32_t i) { + uint32_t u = i; + return (u < 0x47800000) || (u >= 0x80000000U && u < 0xbf800000U); +} + bool wasm::isInRangeI32TruncU(int32_t i) { uint32_t u = i; return (u < 0x4f800000U) || (u >= 0x80000000U && u < 0xbf800000U); -- cgit v1.2.3