Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: test/mjsunit/div-mod.js

Issue 155047: ARM improvements to constant div, mod and mul.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Test fast div and mod.
29
30 function divmod(div_func, mod_func, x, y) {
31 var div_answer = (div_func)(x);
32 assertEquals(x / y, div_answer, x + "/" + y);
33 var mod_answer = (mod_func)(x);
34 assertEquals(x % y, mod_answer, x + "%" + y);
35 var minus_div_answer = (div_func)(-x);
36 assertEquals(-x / y, minus_div_answer, "-" + x + "/" + y);
37 var minus_mod_answer = (mod_func)(-x);
38 assertEquals(-x % y, minus_mod_answer, "-" + x + "%" + y);
39 }
40
41
42 function run_tests_for(divisor) {
43 print("(function(left) { return left / " + divisor + "; })");
44 var div_func = this.eval("(function(left) { return left / " + divisor + "; })" );
45 var mod_func = this.eval("(function(left) { return left % " + divisor + "; })" );
46 var exp;
47 // Strange number test.
48 divmod(div_func, mod_func, 0, divisor);
49 divmod(div_func, mod_func, 1 / 0, divisor);
50 // Floating point number test.
51 for (exp = -1024; exp <= 1024; exp += 4) {
52 divmod(div_func, mod_func, Math.pow(2, exp), divisor);
53 divmod(div_func, mod_func, 0.9999999 * Math.pow(2, exp), divisor);
54 divmod(div_func, mod_func, 1.0000001 * Math.pow(2, exp), divisor);
55 }
56 // Integer number test.
57 for (exp = 0; exp <= 32; exp++) {
58 divmod(div_func, mod_func, 1 << exp, divisor);
59 divmod(div_func, mod_func, (1 << exp) + 1, divisor);
60 divmod(div_func, mod_func, (1 << exp) - 1, divisor);
61 }
62 divmod(div_func, mod_func, Math.floor(0x1fffffff / 3), divisor);
63 divmod(div_func, mod_func, Math.floor(-0x20000000 / 3), divisor);
64 }
65
66
67 var divisors = [
68 0,
69 1,
70 2,
71 3,
72 4,
73 5,
74 6,
75 7,
76 8,
77 9,
78 10,
79 // These ones in the middle don't add much apart from slowness to the test.
80 0x1000000,
81 0x2000000,
82 0x4000000,
83 0x8000000,
84 0x10000000,
85 0x20000000,
86 0x40000000,
87 12,
88 60,
89 100,
90 1000 * 60 * 60 * 24];
91
92 for (var i = 0; i < divisors.length; i++) {
93 run_tests_for(divisors[i]);
94 }
95
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698