diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-24 16:03:47 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-24 16:03:47 -0800 |
commit | 05ee11999ac1e4428f9ddefbed2abde62203eda2 (patch) | |
tree | 5eebc6c87f1b0ac2e7e21245bed4e2638ac255ff /src/runtime.js | |
parent | 594b8a6a569b1fd84b1cb16ecc291d7a82341394 (diff) |
fix i64 mode 1 bitshifts, and improve printing of i64 mode 1s
Diffstat (limited to 'src/runtime.js')
-rw-r--r-- | src/runtime.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime.js b/src/runtime.js index 6439d0ed..495e72dd 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -73,6 +73,15 @@ var RuntimeGenerator = { quantum = '(quantum ? quantum : {{{ QUANTUM_SIZE }}})'; } return target + ' = ' + Runtime.forceAlign(target, quantum); + }, + + // Given two 32-bit unsigned parts of an emulated 64-bit number, combine them into a JS number (double). + // Rounding is inevitable if the number is large. This is a particular problem for small negative numbers + // (-1 will be rounded!), so handle negatives separately and carefully + makeBigInt: function(low, high, unsigned) { + return '((' + unsigned + ' || (' + makeSignOp(high, 'i32', 're', 1, 1) + ' >= 0))' + + ' ? (' + makeSignOp(low, 'i32', 'un', 1, 1) + '+(' + makeSignOp(high, 'i32', 'un', 1, 1) + '*4294967296))' + + ' : (' + makeSignOp(low, 'i32', 're', 1, 1) + '+(1+' + makeSignOp(high, 'i32', 're', 1, 1) + ')*4294967296))'; } }; @@ -260,6 +269,7 @@ var Runtime = { Runtime.stackAlloc = unInline('stackAlloc', ['size']); Runtime.staticAlloc = unInline('staticAlloc', ['size']); Runtime.alignMemory = unInline('alignMemory', ['size', 'quantum']); +Runtime.makeBigInt = unInline('makeBigInt', ['low', 'high', 'unsigned']); function getRuntime() { var ret = 'var Runtime = {\n'; |