| Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1 | // Copyright 2010 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 | // Flags: --fast-compiler |
| 29 | |
| 30 | function Test() { |
| 31 | this.result = 0; |
| 32 | this.x = 0; |
| 33 | this.y = 0; |
| 34 | this.z = 0; |
| 35 | } |
| 36 | var a = 1; |
| 37 | var b = 2; |
| 38 | var c = 4; |
| 39 | var d = 8; |
| 40 | |
| 41 | // Test operations expected to stay on the fast path. Enumerate all binary |
| 42 | // trees with <= 4 leaves. |
| 43 | Test.prototype.test0 = function () { |
| 44 | this.result = a | b; |
| 45 | }; |
| 46 | |
| 47 | Test.prototype.test1 = function() { |
| 48 | this.result = (a | b) | c; |
| 49 | }; |
| 50 | |
| 51 | Test.prototype.test2 = function() { |
| 52 | this.result = a | (b | c); |
| 53 | }; |
| 54 | |
| 55 | Test.prototype.test3 = function() { |
| 56 | this.result = ((a | b) | c) | d; |
| 57 | }; |
| 58 | |
| 59 | Test.prototype.test4 = function() { |
| 60 | this.result = (a | (b | c)) | d; |
| 61 | }; |
| 62 | |
| 63 | Test.prototype.test5 = function() { |
| 64 | this.result = (a | b) | (c | d); |
| 65 | }; |
| 66 | |
| 67 | Test.prototype.test6 = function() { |
| 68 | this.result = a | ((b | c) | d); |
| 69 | }; |
| 70 | |
| 71 | Test.prototype.test7 = function() { |
| 72 | this.result = a | (b | (c | d)); |
| 73 | }; |
| 74 | |
| 75 | // These tests should fail if we bailed out to the beginning of the full |
| 76 | // code. |
| 77 | Test.prototype.test8 = function () { |
| 78 | // If this.x = 1 and a = 1.1: |
| 79 | this.y = this.x | b; // Should be (1 | 2) == 3. |
| 80 | this.x = c; // Should be 4. |
| 81 | this.z = this.x | a; // Should be (4 | 1.1) == 5. |
| 82 | }; |
| 83 | |
| 84 | Test.prototype.test9 = function() { |
| 85 | // If this.x = 2 and a = 1.1: |
| 86 | this.z = // (14 | 1.1) == 15 |
| 87 | (this.x = // (6 | 8) == 14 |
| 88 | (this.y = // (2 | 4) == 6 |
| 89 | this.x // 2 |
| 90 | | c) // 4 |
| 91 | | d) // 8 |
| 92 | | a; // 1.1 |
| 93 | } |
| 94 | |
| 95 | var t = new Test(); |
| 96 | |
| 97 | t.test0(); |
| 98 | assertEquals(3, t.result); |
| 99 | |
| 100 | t.test1(); |
| 101 | assertEquals(7, t.result); |
| 102 | t.test2(); |
| 103 | assertEquals(7, t.result); |
| 104 | |
| 105 | t.test3(); |
| 106 | assertEquals(15, t.result); |
| 107 | t.test4(); |
| 108 | assertEquals(15, t.result); |
| 109 | t.test5(); |
| 110 | assertEquals(15, t.result); |
| 111 | t.test6(); |
| 112 | assertEquals(15, t.result); |
| 113 | t.test7(); |
| 114 | assertEquals(15, t.result); |
| 115 | |
| 116 | a = 1.1; |
| 117 | t.x = 1; |
| 118 | t.test8(); |
| 119 | assertEquals(4, t.x); |
| 120 | assertEquals(3, t.y); |
| 121 | assertEquals(5, t.z); |
| 122 | |
| 123 | t.x = 2; |
| 124 | t.test9(); |
| 125 | assertEquals(14, t.x); |
| 126 | assertEquals(6, t.y); |
| 127 | assertEquals(15, t.z); |