summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-08-08 20:47:39 -0700
committerGitHub <noreply@github.com>2016-08-08 20:47:39 -0700
commit8e8c311aaeecf9b5433e4a651585914465731f0c (patch)
tree179c9ae9f9363de4ef4aa213ee6efd52c0543663
parent49b99e6675424ff0866a670ed83f2393330198dd (diff)
downloadbinaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.tar.gz
binaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.tar.bz2
binaryen-8e8c311aaeecf9b5433e4a651585914465731f0c.zip
in DemoteFloat64, if the truncated value is exactly at the limit, return it (#665)
and update spec tests
-rw-r--r--src/wasm-interpreter.h6
m---------test/spec0
2 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index adaee0b6f..fcf03c591 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -288,6 +288,12 @@ public:
double val = value.getFloat();
if (std::isnan(val)) return Literal(float(val));
if (std::isinf(val)) return Literal(float(val));
+ // when close to the limit, but still truncatable to a valid value, do that
+ // see https://github.com/WebAssembly/sexpr-wasm-prototype/blob/2d375e8d502327e814d62a08f22da9d9b6b675dc/src/wasm-interpreter.c#L247
+ uint64_t bits = value.reinterpreti64();
+ if (bits > 0x47efffffe0000000ULL && bits < 0x47effffff0000000ULL) return Literal(std::numeric_limits<float>::max());
+ if (bits > 0xc7efffffe0000000ULL && bits < 0xc7effffff0000000ULL) return Literal(-std::numeric_limits<float>::max());
+ // when we must convert to infinity, do that
if (val < -std::numeric_limits<float>::max()) return Literal(-std::numeric_limits<float>::infinity());
if (val > std::numeric_limits<float>::max()) return Literal(std::numeric_limits<float>::infinity());
return value.truncateToF32();
diff --git a/test/spec b/test/spec
-Subproject 88274ef4376b5a679a2cd0a1d630bf7e71f96cf
+Subproject d4b150ce7268f903757ebdf1c7c001c99607da7