summaryrefslogtreecommitdiff
path: root/src/support/safe_integer.cpp
diff options
context:
space:
mode:
authorBrendan Dahl <brendan.dahl@gmail.com>2024-09-26 15:35:47 -0700
committerGitHub <noreply@github.com>2024-09-26 15:35:47 -0700
commitc3a71ff46d8f38e29896c321d89b6d0c3b90fbc1 (patch)
tree04c4751da10f8e548e0ff94945d2635939b34f58 /src/support/safe_integer.cpp
parent3856a2dc909b3c713497ef311fe4051078ee74b9 (diff)
downloadbinaryen-c3a71ff46d8f38e29896c321d89b6d0c3b90fbc1.tar.gz
binaryen-c3a71ff46d8f38e29896c321d89b6d0c3b90fbc1.tar.bz2
binaryen-c3a71ff46d8f38e29896c321d89b6d0c3b90fbc1.zip
[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
Diffstat (limited to 'src/support/safe_integer.cpp')
-rw-r--r--src/support/safe_integer.cpp10
1 files changed, 10 insertions, 0 deletions
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);