OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
Jakob Kummerow
2013/08/20 13:51:23
nit: we don't update copyright years anymore.
| |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | |
29 | |
28 function divp4(x) { | 30 function divp4(x) { |
29 return x / 4; | 31 return x / 4; |
30 } | 32 } |
31 | 33 |
32 for (var i = 0; i < 10000; i+=4) { | 34 divp4(8); |
33 assertEquals(i >> 2, divp4(i)); | 35 divp4(8); |
34 } | 36 %OptimizeFunctionOnNextCall(divp4); |
37 assertEquals(2, divp4(8)); | |
38 assertEquals(0.5, divp4(2)); | |
35 | 39 |
36 assertEquals(0.5, divp4(2)); | |
37 | 40 |
38 function divn4(x) { | 41 function divn4(x) { |
39 return x / (-4); | 42 return x / (-4); |
40 } | 43 } |
41 | 44 |
42 for (var i = 0; i < 10000; i+=4) { | 45 divn4(8); |
43 assertEquals(-(i >> 2), divn4(i)); | 46 divn4(8); |
44 } | 47 %OptimizeFunctionOnNextCall(divn4); |
45 | 48 assertEquals(-2, divn4(8)); |
49 // Check for (0 / -x) | |
46 assertEquals(-0, divn4(0)); | 50 assertEquals(-0, divn4(0)); |
47 | 51 |
48 | 52 |
53 // Check for (kMinInt / -1) | |
49 function divn1(x) { | 54 function divn1(x) { |
50 return x / (-1); | 55 return x / (-1); |
51 } | 56 } |
52 | 57 |
53 for (var i = 0; i < 10000; i++) { | 58 var two_31 = 1 << 31; |
54 assertEquals(-i, divn1(i)); | 59 divn1(2); |
60 divn1(2); | |
61 %OptimizeFunctionOnNextCall(divn1); | |
62 assertEquals(-2, divn1(2)); | |
63 assertEquals(two_31, divn1(-two_31)); | |
64 | |
65 | |
66 //Check for truncating to int32 case | |
67 function divp4t(x) { | |
68 return (x / 4) | 0; | |
55 } | 69 } |
56 | 70 |
57 var min_int = -(0x7FFFFFFF)-1; | 71 divp4t(8); |
58 assertEquals(-min_int, divn1(min_int)); | 72 divp4t(8); |
73 %OptimizeFunctionOnNextCall(divp4t); | |
74 assertEquals(-1, divp4t(-5)); | |
75 assertEquals(1, divp4t(5)); | |
76 assertOptimized(divp4t); | |
59 | 77 |
78 function divn4t(x) { | |
79 return (x / -4) | 0; | |
80 } | |
81 | |
82 divn4t(8); | |
83 divn4t(8); | |
84 %OptimizeFunctionOnNextCall(divn4t); | |
85 assertEquals(1, divn4t(-5)); | |
86 assertEquals(-1, divn4t(5)); | |
87 assertOptimized(divn4t); | |
OLD | NEW |