diff options
-rw-r--r-- | src/wasm-interpreter.h | 4 | ||||
-rw-r--r-- | src/wasm.h | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 381176390..3fa83b863 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -412,7 +412,7 @@ private: float ret; switch (curr->op) { case Neg: ret = -v; break; - case Abs: ret = std::abs(v); break; + case Abs: return Literal(value.reinterpreti32() & 0x7fffffff).castToF32(); break; // operate on bits directly, to avoid signalling bit being set on a float case Ceil: ret = std::ceil(v); break; case Floor: ret = std::floor(v); break; case Trunc: ret = std::trunc(v); break; @@ -431,7 +431,7 @@ private: double ret; switch (curr->op) { case Neg: ret = -v; break; - case Abs: ret = std::abs(v); break; + case Abs: return Literal(value.reinterpreti64() & 0x7fffffffffffffffUL).castToF64(); break; // operate on bits directly, to avoid signalling bit being set on a float case Ceil: ret = std::ceil(v); break; case Floor: ret = std::floor(v); break; case Trunc: ret = std::trunc(v); break; diff --git a/src/wasm.h b/src/wasm.h index 2d30e4730..51b54846a 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -162,6 +162,19 @@ public: explicit Literal(float init) : type(WasmType::f32), i32(bit_cast<int32_t>(init)) {} explicit Literal(double init) : type(WasmType::f64), i64(bit_cast<int64_t>(init)) {} + Literal castToF32() { + assert(type == WasmType::i32); + Literal ret(i32); + ret.type = f32; + return ret; + } + Literal castToF64() { + assert(type == WasmType::i64); + Literal ret(i64); + ret.type = f64; + return ret; + } + int32_t geti32() { assert(type == WasmType::i32); return i32; } int64_t geti64() { assert(type == WasmType::i64); return i64; } float getf32() { assert(type == WasmType::f32); return bit_cast<float>(i32); } |