summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-05 10:07:32 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-05 10:07:32 -0800
commit2266390bc8055693b26438ddd3544a8cb20d0db0 (patch)
tree74fa5a8a4c451df81966d7a944ef61c2ea137313 /src/wasm-interpreter.h
parent8839251f5148bcaff3b9b784afdf8937d2ba032e (diff)
downloadbinaryen-2266390bc8055693b26438ddd3544a8cb20d0db0.tar.gz
binaryen-2266390bc8055693b26438ddd3544a8cb20d0db0.tar.bz2
binaryen-2266390bc8055693b26438ddd3544a8cb20d0db0.zip
fix float conversions
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 0843de8b4..b8fcf2509 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -359,20 +359,30 @@ public:
case ExtendSInt32: return Flow(Literal(int64_t(value.geti32())));
case ExtendUInt32: return Flow(Literal(uint64_t((uint32_t)value.geti32())));
case WrapInt64: return Flow(Literal(int32_t(value.geti64())));
- case TruncSFloat32: {
- float val = value.getf32();
+ case TruncSFloat32:
+ case TruncSFloat64: {
+ double val = curr->op == TruncSFloat32 ? value.getf32() : value.getf64();
if (isnan(val)) instance.externalInterface->trap();
- if (val > (double)INT_MAX || val < (double)INT_MIN) instance.externalInterface->trap();
- return Flow(Literal(int32_t(val)));
+ if (curr->type == i32) {
+ if (val > (double)INT_MAX || val < (double)INT_MIN) instance.externalInterface->trap();
+ return Flow(Literal(int32_t(val)));
+ } else {
+ if (val > (double)LLONG_MAX || val < (double)LLONG_MIN) instance.externalInterface->trap();
+ return Flow(Literal(int64_t(val)));
+ }
}
- case TruncUFloat32: {
- float val = value.getf32();
+ case TruncUFloat32:
+ case TruncUFloat64: {
+ double val = curr->op == TruncUFloat32 ? value.getf32() : value.getf64();
if (isnan(val)) instance.externalInterface->trap();
- if (val > (double)UINT_MAX || val <= (double)-1) instance.externalInterface->trap();
- return Flow(Literal(uint32_t(val)));
+ if (curr->type == i32) {
+ if (val > (double)UINT_MAX || val <= (double)-1) instance.externalInterface->trap();
+ return Flow(Literal(uint32_t(val)));
+ } else {
+ if (val > (double)ULLONG_MAX || val <= (double)-1) instance.externalInterface->trap();
+ return Flow(Literal(uint64_t(val)));
+ }
}
- case TruncSFloat64: return Flow(Literal(int32_t(value.getf64())));
- case TruncUFloat64: return Flow(Literal(int32_t((uint32_t)value.getf64())));
case ReinterpretFloat: return curr->type == i32 ? Flow(Literal(value.reinterpreti32())) : Flow(Literal(value.reinterpreti64()));
case ConvertUInt32: return Flow(Literal(double(uint32_t(value.geti32()))));
case ConvertSInt32: return Flow(Literal(double(int32_t(value.geti32()))));