OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var stdlib = {}; |
| 6 var foreign = {}; |
| 7 var heap = new ArrayBuffer(64 * 1024); |
| 8 |
| 9 function Int32Mod(divisor) { |
| 10 var name = "mod_"; |
| 11 if (divisor < 0) { |
| 12 name += "minus_"; |
| 13 } |
| 14 name += Math.abs(divisor); |
| 15 var m = eval("function Module(stdlib, foreign, heap) {\n" |
| 16 + " \"use asm\";\n" |
| 17 + " function " + name + "(dividend) {\n" |
| 18 + " return ((dividend | 0) % " + divisor + ") | 0;\n" |
| 19 + " }\n" |
| 20 + " return { f: " + name + "}\n" |
| 21 + "}; Module"); |
| 22 return m(stdlib, foreign, heap).f; |
| 23 } |
| 24 |
| 25 var divisors = [-2147483648, -32 * 1024, -1000, -16, -7, -2, -1, |
| 26 1, 3, 4, 10, 64, 100, 1024, 2147483647]; |
| 27 for (var i in divisors) { |
| 28 var divisor = divisors[i]; |
| 29 var mod = Int32Mod(divisor); |
| 30 for (var dividend = -2147483648; dividend < 2147483648; dividend += 3999773) { |
| 31 assertEquals((dividend % divisor) | 0, mod(dividend)); |
| 32 } |
| 33 } |
OLD | NEW |