OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var stdlib = {}; | 5 var stdlib = {}; |
6 var foreign = {}; | 6 var foreign = {}; |
7 var heap = new ArrayBuffer(64 * 1024); | 7 var heap = new ArrayBuffer(64 * 1024); |
8 | 8 |
9 function Uint32Mod(divisor) { | 9 var mod = (function Module(stdlib, foreign, heap) { |
10 var name = "mod_"; | 10 "use asm"; |
11 name += divisor; | 11 function mod(dividend, divisor) { |
12 var m = eval("function Module(stdlib, foreign, heap) {\n" | 12 dividend = dividend >>> 0; |
13 + " \"use asm\";\n" | 13 divisor = divisor >>> 0; |
14 + " function " + name + "(dividend) {\n" | 14 return (dividend % divisor) >>> 0; |
15 + " return ((dividend >>> 0) % " + divisor + ") >>> 0;\n" | 15 } |
16 + " }\n" | 16 return { mod: mod }; |
17 + " return { f: " + name + "}\n" | 17 })(stdlib, foreign, heap).mod; |
18 + "}; Module"); | |
19 return m(stdlib, foreign, heap).f; | |
20 } | |
21 | 18 |
22 var divisors = [0, 1, 3, 4, 10, 42, 64, 100, 1024, 2147483647, 4294967295]; | 19 var divisors = [0, 1, 3, 4, 10, 42, 64, 100, 1024, 2147483647, 4294967295]; |
23 for (var i in divisors) { | 20 for (var i in divisors) { |
24 var divisor = divisors[i]; | 21 var divisor = divisors[i]; |
25 var mod = Uint32Mod(divisor); | |
26 for (var dividend = 0; dividend < 4294967296; dividend += 3999773) { | 22 for (var dividend = 0; dividend < 4294967296; dividend += 3999773) { |
27 assertEquals((dividend % divisor) >>> 0, mod(dividend)); | 23 assertEquals((dividend % divisor) >>> 0, mod(dividend, divisor)); |
28 } | 24 } |
29 } | 25 } |
OLD | NEW |