Debian Codegraph @

test/542-bitfield-rotates/src/Main.java

raw
1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 public class Main {
18
19 public static void assertIntEquals(int expected, int actual) {
20 if (expected != actual) {
21 throw new Error("Expected: " + expected + ", found: " + actual);
22 }
23 }
24
25 public static void assertLongEquals(long expected, long actual) {
26 if (expected != actual) {
27 throw new Error("Expected: " + expected + ", found: " + actual);
28 }
29 }
30
31 public static void main(String args[]) throws Exception {
32 test_Integer_right_v_csubv();
33 test_Long_right_v_csubv();
34
35 test_Integer_right_constant_v();
36 test_Long_right_constant_v();
37
38 test_Integer_left_csubv_v();
39 test_Long_left_csubv_v();
40
41 test_Integer_right_v_negv();
42 test_Long_right_v_negv();
43
44 test_Integer_left_negv_v();
45 test_Long_left_negv_v();
46
47 test_Integer_left_constant_v();
48 test_Long_left_constant_v();
49 }
50
51 public static int $noinline$rotate_int_right_reg_v_csubv(int value, int distance) {
52 return (value >>> distance) | (value << (32 - distance));
53 }
54
55 public static void test_Integer_right_v_csubv() throws Exception {
56 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, 0), 0x11);
57
58 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, 1), 0x80000008);
59 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, Integer.SIZE - 1), 0x22);
60 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, Integer.SIZE), 0x11);
61 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, Integer.SIZE + 1), 0x80000008);
62
63 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, -1), 0x22);
64 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, -(Integer.SIZE - 1)), 0x80000008);
65 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, -Integer.SIZE), 0x11);
66 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x11, -(Integer.SIZE + 1)), 0x22);
67
68 assertIntEquals($noinline$rotate_int_right_reg_v_csubv(0x80000000, 1), 0x40000000);
69 }
70
71 public static long $noinline$rotate_long_right_reg_v_csubv(long value, int distance) {
72 return (value >>> distance) | (value << (64 - distance));
73 }
74
75 public static void test_Long_right_v_csubv() throws Exception {
76 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, 0), 0x11);
77
78 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, 1), 0x8000000000000008L);
79 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, Long.SIZE - 1), 0x22);
80 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, Long.SIZE), 0x11);
81 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, Long.SIZE + 1), 0x8000000000000008L);
82
83 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, -1), 0x22);
84 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, -(Long.SIZE - 1)), 0x8000000000000008L);
85 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, -Long.SIZE), 0x11);
86 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x11, -(Long.SIZE + 1)), 0x22);
87
88 assertLongEquals($noinline$rotate_long_right_reg_v_csubv(0x8000000000000000L, 1), 0x4000000000000000L);
89 }
90
91 public static int $noinline$rotate_int_left_reg_csubv_v(int value, int distance) {
92 return (value >>> (32 - distance)) | (value << distance);
93 }
94
95 public static void test_Integer_left_csubv_v() throws Exception {
96 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, 0), 0x11);
97
98 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, 1), 0x22);
99 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, Integer.SIZE - 1), 0x80000008);
100 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, Integer.SIZE), 0x11);
101 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, Integer.SIZE + 1), 0x22);
102
103 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, -1), 0x80000008);
104 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, -(Integer.SIZE - 1)), 0x22);
105 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, -Integer.SIZE), 0x11);
106 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0x11, -(Integer.SIZE + 1)), 0x80000008);
107
108 assertIntEquals($noinline$rotate_int_left_reg_csubv_v(0xC0000000, 1), 0x80000001);
109 }
110
111 public static long $noinline$rotate_long_left_reg_csubv_v(long value, int distance) {
112 return (value >>> (64 - distance)) | (value << distance);
113 }
114
115 public static void test_Long_left_csubv_v() throws Exception {
116 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, 0), 0x11);
117
118 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, 1), 0x22);
119 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, Long.SIZE - 1), 0x8000000000000008L);
120 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, Long.SIZE), 0x11);
121 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, Long.SIZE + 1), 0x22);
122
123 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, -1), 0x8000000000000008L);
124 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, -(Long.SIZE - 1)), 0x22);
125 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, -Long.SIZE), 0x11);
126 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0x11, -(Long.SIZE + 1)), 0x8000000000000008L);
127
128 assertLongEquals($noinline$rotate_long_left_reg_csubv_v(0xC000000000000000L, 1), 0x8000000000000001L);
129 }
130
131 public static int $noinline$rotate_int_right_reg_v_negv(int value, int distance) {
132 return (value >>> distance) | (value << -distance);
133 }
134
135 public static void test_Integer_right_v_negv() throws Exception {
136 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, 0), 0x11);
137
138 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, 1), 0x80000008);
139 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, Integer.SIZE - 1), 0x22);
140 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, Integer.SIZE), 0x11);
141 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, Integer.SIZE + 1), 0x80000008);
142
143 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, -1), 0x22);
144 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, -(Integer.SIZE - 1)), 0x80000008);
145 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, -Integer.SIZE), 0x11);
146 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x11, -(Integer.SIZE + 1)), 0x22);
147
148 assertIntEquals($noinline$rotate_int_right_reg_v_negv(0x80000000, 1), 0x40000000);
149 }
150
151 public static long $noinline$rotate_long_right_reg_v_negv(long value, int distance) {
152 return (value >>> distance) | (value << -distance);
153 }
154
155 public static void test_Long_right_v_negv() throws Exception {
156 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, 0), 0x11);
157
158 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, 1), 0x8000000000000008L);
159 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, Long.SIZE - 1), 0x22);
160 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, Long.SIZE), 0x11);
161 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, Long.SIZE + 1), 0x8000000000000008L);
162
163 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, -1), 0x22);
164 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, -(Long.SIZE - 1)), 0x8000000000000008L);
165 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, -Long.SIZE), 0x11);
166 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x11, -(Long.SIZE + 1)), 0x22);
167
168 assertLongEquals($noinline$rotate_long_right_reg_v_negv(0x8000000000000000L, 1), 0x4000000000000000L);
169 }
170
171 public static int $noinline$rotate_int_left_reg_negv_v(int value, int distance) {
172 return (value >>> -distance) | (value << distance);
173 }
174
175 public static void test_Integer_left_negv_v() throws Exception {
176 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, 0), 0x11);
177
178 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, 1), 0x22);
179 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, Integer.SIZE - 1), 0x80000008);
180 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, Integer.SIZE), 0x11);
181 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, Integer.SIZE + 1), 0x22);
182
183 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, -1), 0x80000008);
184 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, -(Integer.SIZE - 1)), 0x22);
185 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, -Integer.SIZE), 0x11);
186 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0x11, -(Integer.SIZE + 1)), 0x80000008);
187
188 assertIntEquals($noinline$rotate_int_left_reg_negv_v(0xC0000000, 1), 0x80000001);
189 }
190
191 public static long $noinline$rotate_long_left_reg_negv_v(long value, int distance) {
192 return (value >>> -distance) | (value << distance);
193 }
194
195 public static void test_Long_left_negv_v() throws Exception {
196 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, 0), 0x11);
197
198 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, 1), 0x22);
199 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, Long.SIZE - 1), 0x8000000000000008L);
200 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, Long.SIZE), 0x11);
201 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, Long.SIZE + 1), 0x22);
202
203 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, -1), 0x8000000000000008L);
204 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, -(Long.SIZE - 1)), 0x22);
205 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, -Long.SIZE), 0x11);
206 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0x11, -(Long.SIZE + 1)), 0x8000000000000008L);
207
208 assertLongEquals($noinline$rotate_long_left_reg_negv_v(0xC000000000000000L, 1), 0x8000000000000001L);
209 }
210
211 public static int $noinline$rotate_int_right_constant_0(int value) {
212 return (value >>> 0) | (value << 0);
213 }
214
215 public static int $noinline$rotate_int_right_constant_1(int value) {
216 return (value >>> 1) | (value << -1);
217 }
218
219 public static int $noinline$rotate_int_right_constant_m1(int value) {
220 return (value >>> -1) | (value << 1);
221 }
222
223 public static int $noinline$rotate_int_right_constant_16(int value) {
224 return (value >>> 16) | (value << -16);
225 }
226
227 public static void test_Integer_right_constant_v() throws Exception {
228 assertIntEquals($noinline$rotate_int_right_constant_0(0x11), 0x11);
229 assertIntEquals($noinline$rotate_int_right_constant_1(0x11), 0x80000008);
230 assertIntEquals($noinline$rotate_int_right_constant_m1(0x11), 0x22);
231 assertIntEquals($noinline$rotate_int_right_constant_16(0x11), 0x110000);
232 }
233
234 public static long $noinline$rotate_long_right_constant_0(long value) {
235 return (value >>> 0) | (value << 0);
236 }
237
238 public static long $noinline$rotate_long_right_constant_1(long value) {
239 return (value >>> 1) | (value << -1);
240 }
241
242 public static long $noinline$rotate_long_right_constant_m1(long value) {
243 return (value >>> -1) | (value << 1);
244 }
245
246 public static long $noinline$rotate_long_right_constant_16(long value) {
247 return (value >>> 16) | (value << -16);
248 }
249
250 public static long $noinline$rotate_long_right_constant_32(long value) {
251 return (value >>> 32) | (value << -32);
252 }
253
254 public static long $noinline$rotate_long_right_constant_48(long value) {
255 return (value >>> 48) | (value << -48);
256 }
257
258 public static long $noinline$rotate_long_right_constant_64(long value) {
259 return (value >>> 64) | (value << -64);
260 }
261
262 public static void test_Long_right_constant_v() throws Exception {
263 assertLongEquals($noinline$rotate_long_right_constant_0(0x11), 0x11);
264 assertLongEquals($noinline$rotate_long_right_constant_1(0x11), 0x8000000000000008L);
265 assertLongEquals($noinline$rotate_long_right_constant_m1(0x11), 0x22);
266 assertLongEquals($noinline$rotate_long_right_constant_16(0x11), 0x11000000000000L);
267 assertLongEquals($noinline$rotate_long_right_constant_32(0x11), 0x1100000000L);
268 assertLongEquals($noinline$rotate_long_right_constant_48(0x11), 0x110000L);
269 }
270
271 public static int $noinline$rotate_int_left_constant_0(int value) {
272 return (value << 0) | (value >>> 0);
273 }
274
275 public static int $noinline$rotate_int_left_constant_1(int value) {
276 return (value << 1) | (value >>> -1);
277 }
278
279 public static int $noinline$rotate_int_left_constant_m1(int value) {
280 return (value << -1) | (value >>> 1);
281 }
282
283 public static int $noinline$rotate_int_left_constant_16(int value) {
284 return (value << 16) | (value >>> -16);
285 }
286
287 public static void test_Integer_left_constant_v() throws Exception {
288 assertIntEquals($noinline$rotate_int_left_constant_0(0x11), 0x11);
289 assertIntEquals($noinline$rotate_int_left_constant_1(0x11), 0x22);
290 assertIntEquals($noinline$rotate_int_left_constant_m1(0x11), 0x80000008);
291 assertIntEquals($noinline$rotate_int_left_constant_16(0x11), 0x110000);
292 }
293
294 public static long $noinline$rotate_long_left_constant_0(long value) {
295 return (value << 0) | (value >>> 0);
296 }
297
298 public static long $noinline$rotate_long_left_constant_1(long value) {
299 return (value << 1) | (value >>> -1);
300 }
301
302 public static long $noinline$rotate_long_left_constant_m1(long value) {
303 return (value << -1) | (value >>> 1);
304 }
305
306 public static long $noinline$rotate_long_left_constant_16(long value) {
307 return (value << 16) | (value >>> -16);
308 }
309
310 public static long $noinline$rotate_long_left_constant_32(long value) {
311 return (value << 32) | (value >>> -32);
312 }
313
314 public static long $noinline$rotate_long_left_constant_48(long value) {
315 return (value << 48) | (value >>> -48);
316 }
317
318 public static long $noinline$rotate_long_left_constant_64(long value) {
319 return (value << 64) | (value >>> -64);
320 }
321
322 public static void test_Long_left_constant_v() throws Exception {
323 assertLongEquals($noinline$rotate_long_left_constant_0(0x11), 0x11);
324 assertLongEquals($noinline$rotate_long_left_constant_1(0x11), 0x22);
325 assertLongEquals($noinline$rotate_long_left_constant_m1(0x11), 0x8000000000000008L);
326 assertLongEquals($noinline$rotate_long_left_constant_16(0x11), 0x110000L);
327 assertLongEquals($noinline$rotate_long_left_constant_32(0x11), 0x1100000000L);
328 assertLongEquals($noinline$rotate_long_left_constant_48(0x11), 0x11000000000000L);
329 }
330
331 }