diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-30 13:41:06 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-30 13:41:06 -0800 |
commit | c707fc8a860649099ba475a61aa1f8c8203774f4 (patch) | |
tree | 6dfc597699ed9d312a402aca3b0d4687cae2a27f /src/parseTools.js | |
parent | 764e81bd041395d4e3bd78c9c53b0676e34ef377 (diff) |
handle 32-bit bitcasts int <-> float properly
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index d4ef27eb..cc59f150 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1815,7 +1815,22 @@ function processMathop(item) { assert(bitsLeft <= 32, 'Cannot truncate to more than 32 bits, since we use a native & op'); return '((' + ident1 + ') & ' + (Math.pow(2, bitsLeft)-1) + ')'; } - case 'bitcast': return ident1; + case 'bitcast': { + // Most bitcasts are no-ops for us. However, the exception is int to float and float to int + var inType = item.param1.type; + var outType = item.type; + if ((inType in Runtime.INT_TYPES && outType in Runtime.FLOAT_TYPES) || + (inType in Runtime.FLOAT_TYPES && outType in Runtime.INT_TYPES)) { + assert(USE_TYPED_ARRAYS == 2, 'Can only bitcast ints <-> floats with typed arrays mode 2'); + assert(inType == 'i32' || inType == 'float', 'Can only bitcast ints <-> floats with 32 bits, for now'); + if (inType in Runtime.INT_TYPES) { + return '(tempDoubleI32[0] = ' + ident1 + ',tempDoubleF32[0])'; + } else { + return '(tempDoubleF32[0] = ' + ident1 + ',tempDoubleI32[0])'; + } + } + return ident1; + } default: throw 'Unknown mathcmp op: ' + item.op; } } |