jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1 | // Copyright 2012 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 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 28 | // Flags: --allow-natives-syntax |
| 29 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 30 | function divp4(x) { |
| 31 | return x / 4; |
| 32 | } |
| 33 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 34 | divp4(8); |
| 35 | divp4(8); |
| 36 | %OptimizeFunctionOnNextCall(divp4); |
| 37 | assertEquals(2, divp4(8)); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 38 | assertEquals(0.5, divp4(2)); |
| 39 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 40 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 41 | function divn4(x) { |
| 42 | return x / (-4); |
| 43 | } |
| 44 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 45 | divn4(8); |
| 46 | divn4(8); |
| 47 | %OptimizeFunctionOnNextCall(divn4); |
| 48 | assertEquals(-2, divn4(8)); |
| 49 | // Check for (0 / -x) |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 50 | assertEquals(-0, divn4(0)); |
| 51 | |
| 52 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 53 | // Check for (kMinInt / -1) |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 54 | function divn1(x) { |
| 55 | return x / (-1); |
| 56 | } |
| 57 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 58 | var two_31 = 1 << 31; |
| 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; |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 69 | } |
| 70 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 71 | divp4t(8); |
| 72 | divp4t(8); |
| 73 | %OptimizeFunctionOnNextCall(divp4t); |
| 74 | assertEquals(-1, divp4t(-5)); |
| 75 | assertEquals(1, divp4t(5)); |
| 76 | assertOptimized(divp4t); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 77 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 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); |