aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-13 18:36:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-13 18:36:38 -0700
commit323bd5206e8b49d48e47cdd69d4b47b38aa384b9 (patch)
tree7cd82b17b6f3699618f83ac31932bd35eaceddf7 /src
parent7aa745d5bf521ae4124af8fc3c224dddbde490ee (diff)
faster shortcuts for sign/unsign
Diffstat (limited to 'src')
-rw-r--r--src/parseTools.js22
-rw-r--r--src/preamble.js3
2 files changed, 16 insertions, 9 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 73d7e647..a0bcf44f 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1118,12 +1118,20 @@ function makeSignOp(value, type, op) {
}
if (!correctSigns() && !CHECK_SIGNS) return value;
if (type in Runtime.INT_TYPES) {
- // shortcuts for 32-bit case
- if (bits === 32 && !CHECK_SIGNS) {
- if (op === 're') {
- return '((' + value + ')|0)';
- } else {
- return '((' + value + ')>>>0)';
+ // shortcuts
+ if (!CHECK_SIGNS) {
+ if (bits === 32) {
+ if (op === 're') {
+ return '((' + value + ')|0)';
+ } else {
+ return '((' + value + ')>>>0)';
+ }
+ } else if (bits < 32) {
+ if (op === 'un') {
+ return '((' + value + ')&' + (Math.pow(2, bits)-1) + ')';
+ } else {
+ return '(tempInt=(' + value + '),(tempInt>=' + Math.pow(2, bits-1) + '?tempInt-' + Math.pow(2, bits) + ':tempInt))';
+ }
}
}
return full;
@@ -1178,7 +1186,7 @@ function processMathop(item) { with(item) {
var bitsLeft = ident2 ? ident2.substr(2, ident2.length-3) : null; // remove (i and ), to leave number. This value is important in float ops
function integerizeBignum(value) {
- return '(tempNumber=(' + value + '), tempNumber-tempNumber%1)';
+ return '(tempBigInt=(' + value + '), tempBigInt-tempBigInt%1)';
}
switch (op) {
diff --git a/src/preamble.js b/src/preamble.js
index c045bb2d..8c2a9dcb 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -288,8 +288,7 @@ var __ATEXIT__ = [];
var ABORT = false;
var undef = 0;
-var tempValue;
-var tempNumber;
+var tempValue, tempInt, tempBigInt;
function abort(text) {
print(text + ':\n' + (new Error).stack);