1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2012 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Redistribution and use in source and binary forms, with or without
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// modification, are permitted provided that the following conditions are
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// met:
5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Redistributions of source code must retain the above copyright
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       notice, this list of conditions and the following disclaimer.
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Redistributions in binary form must reproduce the above
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       copyright notice, this list of conditions and the following
10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       disclaimer in the documentation and/or other materials provided
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       with the distribution.
12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Neither the name of Google Inc. nor the names of its
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       contributors may be used to endorse or promote products derived
14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       from this software without specific prior written permission.
15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Flags: --allow-natives-syntax --expose-gc
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Test shift operations that can be replaced by rotate operation.
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction SideEffect() {
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  with ({}) { }  // not inlinable
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction Twenty() {
37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  SideEffect();
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return 20;
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction Twelve() {
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  SideEffect();
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return 12;
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR(x, sa) {
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> sa) | (x << (32 - sa));
49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR1(x, sa) {
52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> sa) | (x << (32 - sa));
53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR2(x, sa) {
56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> (32 - sa)) | (x << (sa));
57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR3(x, sa) {
60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << (32 - sa)) | (x >>> sa);
61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR4(x, sa) {
64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << (sa)) | (x >>> (32 - sa));
65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1 << ((2 % 32)), ROR(1, 30));
68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1 << ((2 % 32)), ROR(1, 30));
69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR);
70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1 << ((2 % 32)), ROR(1, 30));
71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR1(0x0000FFFF, 4));
73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR1(0x0000FFFF, 4));
74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR1);
75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR1(0x0000FFFF, 4));
76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, 20));
78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, 20));
79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR1);
80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, 20));
81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, Twenty()));
83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, Twenty()));
84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR1);
85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR1(0x0000FFFF, Twenty()));
86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR1(0xFFFFFFFF, i));
89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR1(0xFFFFFFFF, i));
90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR1);
91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR1(0xFFFFFFFF, i));
92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR1(-1, i));
96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR1(-1, i));
97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR1);
98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR1(-1, i));
99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1, i));
103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1, i));
104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR1);
105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1, i));
106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
107b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
108b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
109b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1.4, i));
110b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1.4, i));
111b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR1);
112b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR1(1.4, i));
113b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
114b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
115b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
116b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
117b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR2(0x0000FFFF, 28));
118b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR2(0x0000FFFF, 28));
119b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR2);
120b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR2(0x0000FFFF, 28));
121b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
122b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, 12));
123b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, 12));
124b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR2);
125b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, 12));
126b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
127b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, Twelve()));
128b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, Twelve()));
129b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR2);
130b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR2(0x0000FFFF, Twelve()));
131b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
132b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
133b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR2(0xFFFFFFFF, i));
134b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR2(0xFFFFFFFF, i));
135b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR2);
136b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR2(0xFFFFFFFF, i));
137b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
138b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
139b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
140b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR2(-1, i));
141b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR2(-1, i));
142b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR2);
143b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR2(-1, i));
144b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
145b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
146b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
147b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR2(1, i));
148b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR2(1, i));
149b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR2);
150b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR2(1, i));
151b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
152b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
153b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR3(0x0000FFFF, 4));
154b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR3(0x0000FFFF, 4));
155b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR3);
156b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR3(0x0000FFFF, 4));
157b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
158b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, 20));
159b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, 20));
160b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR3);
161b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, 20));
162b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
163b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, Twenty()));
164b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, Twenty()));
165b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR3);
166b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR3(0x0000FFFF, Twenty()));
167b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
168b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
169b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR3(0xFFFFFFFF, i));
170b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR3(0xFFFFFFFF, i));
171b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR3);
172b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR3(0xFFFFFFFF, i));
173b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
174b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
175b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
176b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR3(-1, i));
177b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR3(-1, i));
178b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR3);
179b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR3(-1, i));
180b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
181b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
182b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
183b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR3(1, i));
184b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR3(1, i));
185b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR3);
186b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << (32 - (i % 32)), ROR3(1, i));
187b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
188b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
189b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR4(0x0000FFFF, 28));
190b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR4(0x0000FFFF, 28));
191b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR4);
192b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0xF0000FFF | 0, ROR4(0x0000FFFF, 28));
193b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
194b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, 12));
195b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, 12));
196b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR4);
197b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, 12));
198b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
199b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, Twelve()));
200b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, Twelve()));
201b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR4);
202b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0x0FFFF000 | 0, ROR4(0x0000FFFF, Twelve()));
203b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
204b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
205b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR4(0xFFFFFFFF, i));
206b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR4(0xFFFFFFFF, i));
207b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR4);
208b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(0xFFFFFFFF | 0, ROR4(0xFFFFFFFF, i));
209b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
210b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
211b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
212b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR4(-1, i));
213b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR4(-1, i));
214b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR4);
215b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(-1, ROR4(-1, i));
216b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
217b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
218b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i <= 100; i++) {
219b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR4(1, i));
220b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR4(1, i));
221b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(ROR4);
222b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1 << ((i % 32)), ROR4(1, i));
223b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
224b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
225b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//---------------------------------------------------------
226b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// add test cases for constant operand
227b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//---------------------------------------------------------
228b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// constant operand: 20
229b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR1_sa20(x) {
230b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> 20) | (x << 12);
231b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
232b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
233b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR2_sa20(x) {
234b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> 12) | (x << 20);
235b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
236b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
237b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR3_sa20(x, sa) {
238b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << 12) | (x >>> 20);
239b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
240b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
241b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR4_sa20(x) {
242b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << 20) | (x >>> 12);
243b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
244b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
245b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// constant operand: 40
246b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR1_sa40(x) {
247b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> 40) | (x << -8);
248b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
249b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
250b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR2_sa40(x) {
251b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x >>> -8) | (x << 40);
252b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
253b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
254b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR3_sa40(x, sa) {
255b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << -8) | (x >>> 40);
256b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
257b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
258b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction ROR4_sa40(x) {
259b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return (x << 40) | (x >>> -8);
260b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
261b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
262b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR1_sa20
263b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
264b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
265b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR1_sa20);
266b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
267b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
268b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR1_sa40
269b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
270b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
271b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR1_sa40);
272b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
273b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
274b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR2_sa20
275b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
276b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
277b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR2_sa20);
278b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
279b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
280b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR2_sa40
281b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
282b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
283b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR2_sa40);
284b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
285b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
286b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR3_sa20
287b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
288b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
289b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR3_sa20);
290b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
291b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
292b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR3_sa40
293b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
294b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
295b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR3_sa40);
296b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
297b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
298b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR4_sa20
299b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
300b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
301b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR4_sa20);
302b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
303b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
304b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ROR4_sa40
305b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
306b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
307b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(ROR4_sa40);
308b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
309