aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-01-02 21:26:22 -0800
committerAlon Zakai <azakai@mozilla.com>2011-01-02 21:26:22 -0800
commit044ce8ea7c61616d1836633a40db06e128c051b9 (patch)
tree8f2003c9a98d93a09f403e029ea3098de844649a
parent78aa032b233add4d31f323c650b78d21bc9482a4 (diff)
optimize mod operator, and primes benchmark
-rw-r--r--src/jsifier.js2
-rw-r--r--tests/runner.py29
2 files changed, 28 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index a753fd05..0738363e 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -758,7 +758,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
case 'sub': return handleOverflow(ident1 + ' - ' + ident2);
case 'sdiv': case 'udiv': return 'Math.floor(' + ident1 + ' / ' + ident2 + ')';
case 'mul': return handleOverflow(ident1 + ' * ' + ident2);
- case 'urem': case 'srem': return 'Math.floor(' + ident1 + ' % ' + ident2 + ')';
+ case 'urem': case 'srem': return ident1 + ' % ' + ident2;
case 'or': return ident1 + ' | ' + ident2; // TODO this forces into a 32-bit int - add overflow-style checks? also other bitops below us
case 'and': return ident1 + ' & ' + ident2;
case 'xor': return ident1 + ' ^ ' + ident2;
diff --git a/tests/runner.py b/tests/runner.py
index 0316574a..0a50f3c7 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1502,8 +1502,8 @@ else:
GUARD_MEMORY = SAFE_HEAP = CHECK_OVERFLOWS = CORRECT_OVERFLOWS = 0
LLVM_OPTS = 1
- TEST_REPS = 10
- TOTAL_TESTS = 2
+ TEST_REPS = 3
+ TOTAL_TESTS = 3
tests_done = 0
total_times = map(lambda x: 0., range(TEST_REPS))
@@ -1561,6 +1561,31 @@ else:
print 'Total stats:'
self.print_stats(total_times)
+ def test_primes(self):
+ src = '''
+ #include<stdio.h>
+ #include<math.h>
+ int main() {
+ int primes = 0, curri = 2;
+ while (primes < 30000) {
+ int ok = true;
+ for (int j = 2; j < sqrtf(curri); j++) {
+ if (curri % j == 0) {
+ ok = false;
+ break;
+ }
+ }
+ if (ok) {
+ primes++;
+ }
+ curri++;
+ }
+ printf("lastprime: %d.\\n", curri-1);
+ return 1;
+ }
+ '''
+ self.do_benchmark(src, [], 'lastprime: 348949.')
+
def test_fannkuch(self):
src = open(path_from_root(['tests', 'fannkuch.cpp']), 'r').read()
self.do_benchmark(src, ['9'], 'Pfannkuchen(9) = 30.')