summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorBrendan Dahl <brendan.dahl@gmail.com>2024-08-06 14:15:58 -0700
committerGitHub <noreply@github.com>2024-08-06 14:15:58 -0700
commit0c269482097ae9da62a690b0ace406e2d2109c48 (patch)
treed7fa2f2f5b9e7e703dce9805f9dbd1bb16f65cfb /src/wasm-interpreter.h
parentd5a5425c0c76cfc08711b81d6ec70c3a2879e405 (diff)
downloadbinaryen-0c269482097ae9da62a690b0ace406e2d2109c48.tar.gz
binaryen-0c269482097ae9da62a690b0ace406e2d2109c48.tar.bz2
binaryen-0c269482097ae9da62a690b0ace406e2d2109c48.zip
[FP16] Implement load and store instructions. (#6796)
Specified at https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 9bdf0e72c..3e62d5335 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -28,6 +28,7 @@
#include <sstream>
#include <variant>
+#include "fp16.h"
#include "ir/intrinsics.h"
#include "ir/module-utils.h"
#include "support/bits.h"
@@ -2540,8 +2541,22 @@ public:
}
break;
}
- case Type::f32:
- return Literal(load32u(addr, memory)).castToF32();
+ case Type::f32: {
+ switch (load->bytes) {
+ case 2: {
+ // Convert the float16 to float32 and store the binary
+ // representation.
+ return Literal(bit_cast<int32_t>(
+ fp16_ieee_to_fp32_value(load16u(addr, memory))))
+ .castToF32();
+ }
+ case 4:
+ return Literal(load32u(addr, memory)).castToF32();
+ default:
+ WASM_UNREACHABLE("invalid size");
+ }
+ break;
+ }
case Type::f64:
return Literal(load64u(addr, memory)).castToF64();
case Type::v128:
@@ -2590,9 +2605,23 @@ public:
break;
}
// write floats carefully, ensuring all bits reach memory
- case Type::f32:
- store32(addr, value.reinterpreti32(), memory);
+ case Type::f32: {
+ switch (store->bytes) {
+ case 2: {
+ float f32 = bit_cast<float>(value.reinterpreti32());
+ // Convert the float32 to float16 and store the binary
+ // representation.
+ store16(addr, fp16_ieee_from_fp32_value(f32), memory);
+ break;
+ }
+ case 4:
+ store32(addr, value.reinterpreti32(), memory);
+ break;
+ default:
+ WASM_UNREACHABLE("invalid store size");
+ }
break;
+ }
case Type::f64:
store64(addr, value.reinterpreti64(), memory);
break;