aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-05-24 07:33:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-05-24 07:33:53 -0700
commit77cacaa2fd27bcc1265f2f7255b18c3461e0ddff (patch)
tree83ef0b674533d8e9171b4b6ac786d88b6627babb
parent608c3ce208f406b172f98272710df0032088a248 (diff)
handle shifts with more than 32 bits
-rw-r--r--src/parseTools.js11
-rw-r--r--tests/runner.py12
2 files changed, 20 insertions, 3 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 774293d0..bc83e4ea 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -931,10 +931,17 @@ function processMathop(item) { with(item) {
}
}
*/
+ if (bits > 32) return ident1 + '*Math.pow(2,' + ident2 + ')';
return ident1 + ' << ' + ident2;
}
- case 'ashr': return ident1 + ' >> ' + ident2;
- case 'lshr': return ident1 + ' >>> ' + ident2;
+ case 'ashr': {
+ if (bits > 32) return ident1 + '/Math.pow(2,' + ident2 + ')';
+ return ident1 + ' >> ' + ident2;
+ }
+ case 'lshr': {
+ if (bits > 32) return ident1 + '/Math.pow(2,' + ident2 + ')';
+ return ident1 + ' >>> ' + ident2;
+ }
// basic float ops
case 'fadd': return ident1 + ' + ' + ident2;
case 'fsub': return ident1 + ' - ' + ident2;
diff --git a/tests/runner.py b/tests/runner.py
index dcf535e7..c0814c52 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -375,11 +375,21 @@ if 'benchmark' not in sys.argv:
printf("*\\n");
printf("*%.1d,%.2d*\\n", 56, 9);
+ // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS
+ {
+ struct Fixed {
+ static int Mult(int a, int b) {
+ return ((long long)a * (long long)b) >> 16;
+ }
+ };
+ printf("fixed:%d\\n", Fixed::Mult(150000, 140000));
+ }
+
printf("*%ld*%p\\n", (long)21, &hash); // The %p should not enter an infinite loop!
return 0;
}
'''
- self.do_test(src, '*5,23,10,19,121,1,37,1,0*\n0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*\n*56,09*\n*21*')
+ self.do_test(src, '*5,23,10,19,121,1,37,1,0*\n0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*\n*56,09*\nfixed:320434\n*21*')
def test_sintvars(self):
global CORRECT_SIGNS; CORRECT_SIGNS = 1 # Relevant to this test