js/src/jit-test/tests/sunspider/check-bitops-nsieve-bits.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 // The Great Computer Language Shootout
michael@0 2 // http://shootout.alioth.debian.org
michael@0 3 //
michael@0 4 // Contributed by Ian Osgood
michael@0 5
michael@0 6 var result = [];
michael@0 7
michael@0 8 function pad(n,width) {
michael@0 9 var s = n.toString();
michael@0 10 while (s.length < width) s = ' ' + s;
michael@0 11 return s;
michael@0 12 }
michael@0 13
michael@0 14 function primes(isPrime, n) {
michael@0 15 var i, count = 0, m = 10000<<n, size = m+31>>5;
michael@0 16
michael@0 17 for (i=0; i<size; i++) isPrime[i] = 0xffffffff;
michael@0 18
michael@0 19 for (i=2; i<m; i++)
michael@0 20 if (isPrime[i>>5] & 1<<(i&31)) {
michael@0 21 for (var j=i+i; j<m; j+=i)
michael@0 22 result.push(isPrime[j>>5] &= ~(1<<(j&31)));
michael@0 23 count++;
michael@0 24 }
michael@0 25 }
michael@0 26
michael@0 27 function sieve() {
michael@0 28 for (var i = 4; i <= 4; i++) {
michael@0 29 var isPrime = new Array((10000<<i)+31>>5);
michael@0 30 primes(isPrime, i);
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 sieve();
michael@0 35
michael@0 36 var ret = 0;
michael@0 37 for (var i = 0; i < result.length; ++i)
michael@0 38 ret += result[i];
michael@0 39
michael@0 40 assertEq(ret, -211235557404919)

mercurial