blob: af80b7f0564e38583b5e5c2689d6e1946632c48d [file] [log] [blame]
Andrei Popescu402d9372010-02-26 13:31:12 +00001// 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
30function Test() {
31 this.result = 0;
32 this.x = 0;
33 this.y = 0;
34 this.z = 0;
35}
36var a = 1;
37var b = 2;
38var c = 4;
39var d = 8;
40
41// Test operations expected to stay on the fast path. Enumerate all binary
42// trees with <= 4 leaves.
43Test.prototype.test0 = function () {
44 this.result = a | b;
45};
46
47Test.prototype.test1 = function() {
48 this.result = (a | b) | c;
49};
50
51Test.prototype.test2 = function() {
52 this.result = a | (b | c);
53};
54
55Test.prototype.test3 = function() {
56 this.result = ((a | b) | c) | d;
57};
58
59Test.prototype.test4 = function() {
60 this.result = (a | (b | c)) | d;
61};
62
63Test.prototype.test5 = function() {
64 this.result = (a | b) | (c | d);
65};
66
67Test.prototype.test6 = function() {
68 this.result = a | ((b | c) | d);
69};
70
71Test.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.
77Test.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
84Test.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
95var t = new Test();
96
97t.test0();
98assertEquals(3, t.result);
99
100t.test1();
101assertEquals(7, t.result);
102t.test2();
103assertEquals(7, t.result);
104
105t.test3();
106assertEquals(15, t.result);
107t.test4();
108assertEquals(15, t.result);
109t.test5();
110assertEquals(15, t.result);
111t.test6();
112assertEquals(15, t.result);
113t.test7();
114assertEquals(15, t.result);
115
116a = 1.1;
117t.x = 1;
118t.test8();
119assertEquals(4, t.x);
120assertEquals(3, t.y);
121assertEquals(5, t.z);
122
123t.x = 2;
124t.test9();
125assertEquals(14, t.x);
126assertEquals(6, t.y);
127assertEquals(15, t.z);