diff options
author | Alex Crichton <alex@alexcrichton.com> | 2018-05-16 18:40:45 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-05-16 16:40:45 -0700 |
commit | 3c5a2de669542caebd7ef001db6678b70375f0b5 (patch) | |
tree | bbe25d21142627cc04041d7ecbea9d4d15f3a680 /src/emscripten-optimizer | |
parent | d4aa0d30234ac9e553d743bd881a767d96554a4a (diff) | |
download | binaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.tar.gz binaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.tar.bz2 binaryen-3c5a2de669542caebd7ef001db6678b70375f0b5.zip |
wasm2asm: Implement float<->int conversions (#1550)
This commit lifts the same conversion strategy that `emcc` takes to convert
between floats point numbers and integers, and it should implement all the
various matrices of i32/u32/i64/u64 to f32/f64
Some refactoring was performed in the i64->i32 pass to allow for temporary
variables to get allocated which have types other than i32, but otherwise this
contains a pretty direct translation of `emcc`'s operations to `wasm2asm`.
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r-- | src/emscripten-optimizer/simple_ast.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h index 62bf975f0..64aab7708 100644 --- a/src/emscripten-optimizer/simple_ast.h +++ b/src/emscripten-optimizer/simple_ast.h @@ -836,6 +836,19 @@ struct JSPrinter { } static char* numToString(double d, bool finalize=true) { + if (std::isnan(d)) { + if (std::signbit(d)) { + return (char*) "-NaN"; + } else { + return (char*) "NaN"; + } + } else if (!std::isfinite(d)) { + if (std::signbit(d)) { + return (char*) "-Infinity"; + } else { + return (char*) "Infinity"; + } + } bool neg = d < 0; if (neg) d = -d; // try to emit the fewest necessary characters @@ -1046,6 +1059,8 @@ struct JSPrinter { ensure(1); // we temporarily append a 0 char *curr = buffer + last; // ensure might invalidate buffer[used] = 0; + if (strstr(curr, "Infinity")) return; + if (strstr(curr, "NaN")) return; if (strchr(curr, '.')) return; // already a decimal point, all good char *e = strchr(curr, 'e'); if (!e) { |