1 /* 2 * Copyright (C) 2016 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 TestRotate { 18 19 /// CHECK-START: int TestRotate.$inline$rotateLeftByte(byte, int) builder (after) 20 /// CHECK: <<ArgVal:b\d+>> ParameterValue 21 /// CHECK: <<ArgDist:i\d+>> ParameterValue 22 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 23 /// CHECK-DAG: Return [<<Result>>] 24 25 /// CHECK-START: int TestRotate.$inline$rotateLeftByte(byte, int) builder (after) 26 /// CHECK-NOT: InvokeStaticOrDirect 27 $inline$rotateLeftByte(byte value, int distance)28 private static int $inline$rotateLeftByte(byte value, int distance) { 29 return Integer.rotateLeft(value, distance); 30 } 31 $noinline$rotateLeftByte(byte value, int distance)32 private static int $noinline$rotateLeftByte(byte value, int distance) { 33 return Integer.rotateLeft(value, distance); 34 } 35 36 /// CHECK-START: int TestRotate.$inline$rotateLeftShort(short, int) builder (after) 37 /// CHECK: <<ArgVal:s\d+>> ParameterValue 38 /// CHECK: <<ArgDist:i\d+>> ParameterValue 39 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 40 /// CHECK-DAG: Return [<<Result>>] 41 42 /// CHECK-START: int TestRotate.$inline$rotateLeftShort(short, int) builder (after) 43 /// CHECK-NOT: InvokeStaticOrDirect 44 $inline$rotateLeftShort(short value, int distance)45 private static int $inline$rotateLeftShort(short value, int distance) { 46 return Integer.rotateLeft(value, distance); 47 } 48 $noinline$rotateLeftShort(short value, int distance)49 private static int $noinline$rotateLeftShort(short value, int distance) { 50 return Integer.rotateLeft(value, distance); 51 } 52 53 /// CHECK-START: int TestRotate.$inline$rotateLeftChar(char, int) builder (after) 54 /// CHECK: <<ArgVal:c\d+>> ParameterValue 55 /// CHECK: <<ArgDist:i\d+>> ParameterValue 56 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 57 /// CHECK-DAG: Return [<<Result>>] 58 59 /// CHECK-START: int TestRotate.$inline$rotateLeftChar(char, int) builder (after) 60 /// CHECK-NOT: InvokeStaticOrDirect 61 $inline$rotateLeftChar(char value, int distance)62 private static int $inline$rotateLeftChar(char value, int distance) { 63 return Integer.rotateLeft(value, distance); 64 } 65 $noinline$rotateLeftChar(char value, int distance)66 private static int $noinline$rotateLeftChar(char value, int distance) { 67 return Integer.rotateLeft(value, distance); 68 } 69 70 /// CHECK-START: int TestRotate.$inline$rotateLeftInt(int, int) builder (after) 71 /// CHECK: <<ArgVal:i\d+>> ParameterValue 72 /// CHECK: <<ArgDist:i\d+>> ParameterValue 73 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 74 /// CHECK-DAG: Return [<<Result>>] 75 76 /// CHECK-START: int TestRotate.$inline$rotateLeftInt(int, int) builder (after) 77 /// CHECK-NOT: InvokeStaticOrDirect 78 $inline$rotateLeftInt(int value, int distance)79 private static int $inline$rotateLeftInt(int value, int distance) { 80 return Integer.rotateLeft(value, distance); 81 } 82 83 /// CHECK-START-ARM64: int TestRotate.$noinline$rotateLeftInt(int, int) instruction_simplifier_arm64 (after) 84 /// CHECK: <<ArgVal:i\d+>> ParameterValue 85 /// CHECK: <<ArgDist:i\d+>> ParameterValue 86 /// CHECK-DAG: <<neg:i\d+>> Neg [<<ArgDist>>] 87 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<neg>>] 88 /// CHECK-DAG: Return [<<Result>>] 89 90 /// CHECK-START-ARM64: int TestRotate.$noinline$rotateLeftInt(int, int) disassembly (after) 91 /// CHECK: neg {{w\d+}}, {{w\d+}} 92 /// CHECK: ror {{w\d+}}, {{w\d+}}, {{w\d+}} 93 94 /// CHECK-START-RISCV64: int TestRotate.$noinline$rotateLeftInt(int, int) disassembly (after) 95 /// CHECK: rolw {{a\d+}}, {{a\d+}}, {{a\d+}} 96 $noinline$rotateLeftInt(int value, int distance)97 private static int $noinline$rotateLeftInt(int value, int distance) { 98 return Integer.rotateLeft(value, distance); 99 } 100 101 /// CHECK-START-ARM64: int TestRotate.$noinline$rotateLeftIntMulNegDistance(int, int) scheduler (before) 102 /// CHECK: <<ArgVal:i\d+>> ParameterValue 103 /// CHECK: <<ArgDist:i\d+>> ParameterValue 104 /// CHECK-DAG: <<neg:i\d+>> Neg [<<ArgDist>>] 105 /// CHECK-DAG: <<ror:i\d+>> Ror [<<ArgVal>>,<<neg>>] 106 /// CHECK-DAG: <<Result:i\d+>> Mul [<<neg>>,<<ror>>] 107 /// CHECK-DAG: Return [<<Result>>] 108 $noinline$rotateLeftIntMulNegDistance(int value, int distance)109 private static int $noinline$rotateLeftIntMulNegDistance(int value, int distance) { 110 return Integer.rotateLeft(value, distance) * -distance; 111 } 112 113 /// CHECK-START: int TestRotate.$noinline$rotateLeftIntConstant(int) builder (after) 114 /// CHECK: <<ArgVal:i\d+>> ParameterValue 115 /// CHECK: <<Constant:i\d+>> IntConstant 31 116 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<Constant>>] 117 /// CHECK-DAG: Return [<<Result>>] 118 119 /// CHECK-START-ARM64: int TestRotate.$noinline$rotateLeftIntConstant(int) disassembly (after) 120 /// CHECK: ror {{w\d+}}, {{w\d+}}, #1 121 122 /// CHECK-START-RISCV64: int TestRotate.$noinline$rotateLeftIntConstant(int) disassembly (after) 123 /// CHECK: roriw {{a\d+}}, {{a\d+}}, 1 124 $noinline$rotateLeftIntConstant(int value)125 private static int $noinline$rotateLeftIntConstant(int value) { 126 return Integer.rotateLeft(value, 31); 127 } 128 129 /// CHECK-START: long TestRotate.$inline$rotateLeftLong(long, int) builder (after) 130 /// CHECK: <<ArgVal:j\d+>> ParameterValue 131 /// CHECK: <<ArgDist:i\d+>> ParameterValue 132 /// CHECK-DAG: <<Result:j\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 133 /// CHECK-DAG: Return [<<Result>>] 134 135 /// CHECK-START: long TestRotate.$inline$rotateLeftLong(long, int) builder (after) 136 /// CHECK-NOT: InvokeStaticOrDirect 137 $inline$rotateLeftLong(long value, int distance)138 private static long $inline$rotateLeftLong(long value, int distance) { 139 return Long.rotateLeft(value, distance); 140 } 141 142 /// CHECK-START-ARM64: long TestRotate.$noinline$rotateLeftLong(long, int) instruction_simplifier_arm64 (after) 143 /// CHECK: <<ArgVal:j\d+>> ParameterValue 144 /// CHECK: <<ArgDist:i\d+>> ParameterValue 145 /// CHECK-DAG: <<neg:i\d+>> Neg [<<ArgDist>>] 146 /// CHECK-DAG: <<Result:j\d+>> Ror [<<ArgVal>>,<<neg>>] 147 /// CHECK-DAG: Return [<<Result>>] 148 149 /// CHECK-START-ARM64: long TestRotate.$noinline$rotateLeftLong(long, int) disassembly (after) 150 /// CHECK: neg {{w\d+}}, {{w\d+}} 151 /// CHECK: ror {{x\d+}}, {{x\d+}}, {{x\d+}} 152 153 /// CHECK-START-RISCV64: long TestRotate.$noinline$rotateLeftLong(long, int) disassembly (after) 154 /// CHECK: rol {{a\d+}}, {{a\d+}}, {{a\d+}} 155 $noinline$rotateLeftLong(long value, int distance)156 private static long $noinline$rotateLeftLong(long value, int distance) { 157 return Long.rotateLeft(value, distance); 158 } 159 160 /// CHECK-START: long TestRotate.$noinline$rotateLeftLongConstant(long) builder (after) 161 /// CHECK: <<ArgVal:j\d+>> ParameterValue 162 /// CHECK: <<Constant:i\d+>> IntConstant 63 163 /// CHECK-DAG: <<Result:j\d+>> Rol [<<ArgVal>>,<<Constant>>] 164 /// CHECK-DAG: Return [<<Result>>] 165 166 /// CHECK-START-ARM64: long TestRotate.$noinline$rotateLeftLongConstant(long) disassembly (after) 167 /// CHECK: ror {{x\d+}}, {{x\d+}}, #1 168 169 /// CHECK-START-RISCV64: long TestRotate.$noinline$rotateLeftLongConstant(long) disassembly (after) 170 /// CHECK: rori {{a\d+}}, {{a\d+}}, 1 171 $noinline$rotateLeftLongConstant(long value)172 private static long $noinline$rotateLeftLongConstant(long value) { 173 return Long.rotateLeft(value, 63); 174 } 175 176 /// CHECK-START: int TestRotate.rotateRightByte(byte, int) builder (after) 177 /// CHECK: <<ArgVal:b\d+>> ParameterValue 178 /// CHECK: <<ArgDist:i\d+>> ParameterValue 179 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 180 /// CHECK-DAG: Return [<<Result>>] 181 182 /// CHECK-START: int TestRotate.rotateRightByte(byte, int) builder (after) 183 /// CHECK-NOT: InvokeStaticOrDirect 184 rotateRightByte(byte value, int distance)185 private static int rotateRightByte(byte value, int distance) { 186 return Integer.rotateRight(value, distance); 187 } 188 189 /// CHECK-START: int TestRotate.rotateRightShort(short, int) builder (after) 190 /// CHECK: <<ArgVal:s\d+>> ParameterValue 191 /// CHECK: <<ArgDist:i\d+>> ParameterValue 192 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 193 /// CHECK-DAG: Return [<<Result>>] 194 195 /// CHECK-START: int TestRotate.rotateRightShort(short, int) builder (after) 196 /// CHECK-NOT: InvokeStaticOrDirect 197 rotateRightShort(short value, int distance)198 private static int rotateRightShort(short value, int distance) { 199 return Integer.rotateRight(value, distance); 200 } 201 202 /// CHECK-START: int TestRotate.rotateRightChar(char, int) builder (after) 203 /// CHECK: <<ArgVal:c\d+>> ParameterValue 204 /// CHECK: <<ArgDist:i\d+>> ParameterValue 205 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 206 /// CHECK-DAG: Return [<<Result>>] 207 208 /// CHECK-START: int TestRotate.rotateRightChar(char, int) builder (after) 209 /// CHECK-NOT: InvokeStaticOrDirect 210 rotateRightChar(char value, int distance)211 private static int rotateRightChar(char value, int distance) { 212 return Integer.rotateRight(value, distance); 213 } 214 215 /// CHECK-START: int TestRotate.rotateRightInt(int, int) builder (after) 216 /// CHECK: <<ArgVal:i\d+>> ParameterValue 217 /// CHECK: <<ArgDist:i\d+>> ParameterValue 218 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 219 /// CHECK-DAG: Return [<<Result>>] 220 221 /// CHECK-START: int TestRotate.rotateRightInt(int, int) builder (after) 222 /// CHECK-NOT: InvokeStaticOrDirect 223 rotateRightInt(int value, int distance)224 private static int rotateRightInt(int value, int distance) { 225 return Integer.rotateRight(value, distance); 226 } 227 228 /// CHECK-START: long TestRotate.rotateRightLong(long, int) builder (after) 229 /// CHECK: <<ArgVal:j\d+>> ParameterValue 230 /// CHECK: <<ArgDist:i\d+>> ParameterValue 231 /// CHECK-DAG: <<Result:j\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 232 /// CHECK-DAG: Return [<<Result>>] 233 234 /// CHECK-START: long TestRotate.rotateRightLong(long, int) builder (after) 235 /// CHECK-NOT: InvokeStaticOrDirect 236 rotateRightLong(long value, int distance)237 private static long rotateRightLong(long value, int distance) { 238 return Long.rotateRight(value, distance); 239 } 240 241 242 /// CHECK-START: int TestRotate.$inline$rotateLeftIntWithByteDistance(int, byte) builder (after) 243 /// CHECK: <<ArgVal:i\d+>> ParameterValue 244 /// CHECK: <<ArgDist:b\d+>> ParameterValue 245 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 246 /// CHECK-DAG: Return [<<Result>>] 247 248 /// CHECK-START: int TestRotate.$inline$rotateLeftIntWithByteDistance(int, byte) builder (after) 249 /// CHECK-NOT: InvokeStaticOrDirect 250 $inline$rotateLeftIntWithByteDistance(int value, byte distance)251 private static int $inline$rotateLeftIntWithByteDistance(int value, byte distance) { 252 return Integer.rotateLeft(value, distance); 253 } 254 $noinline$rotateLeftIntWithByteDistance(int value, byte distance)255 private static int $noinline$rotateLeftIntWithByteDistance(int value, byte distance) { 256 return Integer.rotateLeft(value, distance); 257 } 258 259 /// CHECK-START: int TestRotate.rotateRightIntWithByteDistance(int, byte) builder (after) 260 /// CHECK: <<ArgVal:i\d+>> ParameterValue 261 /// CHECK: <<ArgDist:b\d+>> ParameterValue 262 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 263 /// CHECK-DAG: Return [<<Result>>] 264 265 /// CHECK-START: int TestRotate.rotateRightIntWithByteDistance(int, byte) builder (after) 266 /// CHECK-NOT: InvokeStaticOrDirect 267 rotateRightIntWithByteDistance(int value, byte distance)268 private static int rotateRightIntWithByteDistance(int value, byte distance) { 269 return Integer.rotateRight(value, distance); 270 } 271 272 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) builder (after) 273 /// CHECK: <<ArgVal:z\d+>> ParameterValue 274 /// CHECK: <<ArgDist:i\d+>> ParameterValue 275 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 276 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 277 /// CHECK-DAG: <<Val:i\d+>> Phi [<<One>>,<<Zero>>] 278 /// CHECK-DAG: <<Result:i\d+>> Rol [<<Val>>,<<ArgDist>>] 279 /// CHECK-DAG: Return [<<Result>>] 280 281 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) builder (after) 282 /// CHECK-NOT: InvokeStaticOrDirect 283 284 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) select_generator (after) 285 /// CHECK: <<ArgVal:z\d+>> ParameterValue 286 /// CHECK: <<ArgDist:i\d+>> ParameterValue 287 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 288 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 289 /// CHECK-DAG: <<SelVal:i\d+>> Select [<<Zero>>,<<One>>,<<ArgVal>>] 290 /// CHECK-DAG: <<Result:i\d+>> Rol [<<SelVal>>,<<ArgDist>>] 291 /// CHECK-DAG: Return [<<Result>>] 292 293 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) select_generator (after) 294 /// CHECK-NOT: Phi 295 296 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) instruction_simplifier$before_codegen (after) 297 /// CHECK: <<ArgVal:z\d+>> ParameterValue 298 /// CHECK: <<ArgDist:i\d+>> ParameterValue 299 /// CHECK-DAG: <<Result:i\d+>> Rol [<<ArgVal>>,<<ArgDist>>] 300 /// CHECK-DAG: Return [<<Result>>] 301 302 /// CHECK-START: int TestRotate.$inline$rotateLeftBoolean(boolean, int) instruction_simplifier$before_codegen (after) 303 /// CHECK-NOT: Select 304 $inline$rotateLeftBoolean(boolean value, int distance)305 private static int $inline$rotateLeftBoolean(boolean value, int distance) { 306 // Note: D8 would replace the ternary expression `value ? 1 : 0` with `value` 307 // but explicit `if` is preserved. 308 int src; 309 if (value) { 310 src = 1; 311 } else { 312 src = 0; 313 } 314 return Integer.rotateLeft(src, distance); 315 } 316 $noinline$rotateLeftBoolean(boolean value, int distance)317 private static int $noinline$rotateLeftBoolean(boolean value, int distance) { 318 // Note: D8 would replace the ternary expression `value ? 1 : 0` with `value` 319 // but explicit `if` is preserved. 320 int src; 321 if (value) { 322 src = 1; 323 } else { 324 src = 0; 325 } 326 return Integer.rotateLeft(src, distance); 327 } 328 testRotateLeftBoolean()329 public static void testRotateLeftBoolean() { 330 for (int i = 0; i < 40; i++) { // overshoot a bit 331 int j = i & 31; 332 expectEqualsInt(0, $inline$rotateLeftBoolean(false, i)); 333 expectEqualsInt(1 << j, $inline$rotateLeftBoolean(true, i)); 334 335 expectEqualsInt(0, $noinline$rotateLeftBoolean(false, i)); 336 expectEqualsInt(1 << j, $noinline$rotateLeftBoolean(true, i)); 337 } 338 } 339 testRotateLeftByte()340 public static void testRotateLeftByte() { 341 expectEqualsInt(0x00000001, $inline$rotateLeftByte((byte)0x01, 0)); 342 expectEqualsInt(0x00000002, $inline$rotateLeftByte((byte)0x01, 1)); 343 expectEqualsInt(0x80000000, $inline$rotateLeftByte((byte)0x01, 31)); 344 expectEqualsInt(0x00000001, $inline$rotateLeftByte((byte)0x01, 32)); // overshoot 345 expectEqualsInt(0xFFFFFF03, $inline$rotateLeftByte((byte)0x81, 1)); 346 expectEqualsInt(0xFFFFFE07, $inline$rotateLeftByte((byte)0x81, 2)); 347 expectEqualsInt(0x00000120, $inline$rotateLeftByte((byte)0x12, 4)); 348 expectEqualsInt(0xFFFF9AFF, $inline$rotateLeftByte((byte)0x9A, 8)); 349 350 expectEqualsInt(0x00000001, $noinline$rotateLeftByte((byte)0x01, 0)); 351 expectEqualsInt(0x00000002, $noinline$rotateLeftByte((byte)0x01, 1)); 352 expectEqualsInt(0x80000000, $noinline$rotateLeftByte((byte)0x01, 31)); 353 expectEqualsInt(0x00000001, $noinline$rotateLeftByte((byte)0x01, 32)); // overshoot 354 expectEqualsInt(0xFFFFFF03, $noinline$rotateLeftByte((byte)0x81, 1)); 355 expectEqualsInt(0xFFFFFE07, $noinline$rotateLeftByte((byte)0x81, 2)); 356 expectEqualsInt(0x00000120, $noinline$rotateLeftByte((byte)0x12, 4)); 357 expectEqualsInt(0xFFFF9AFF, $noinline$rotateLeftByte((byte)0x9A, 8)); 358 359 for (int i = 0; i < 40; i++) { // overshoot a bit 360 int j = i & 31; 361 expectEqualsInt(0x00000000, $inline$rotateLeftByte((byte)0x0000, i)); 362 expectEqualsInt(0xFFFFFFFF, $inline$rotateLeftByte((byte)0xFFFF, i)); 363 expectEqualsInt((1 << j), $inline$rotateLeftByte((byte)0x0001, i)); 364 expectEqualsInt((0x12 << j) | (0x12 >>> -j), $inline$rotateLeftByte((byte)0x12, i)); 365 366 expectEqualsInt(0x00000000, $noinline$rotateLeftByte((byte)0x0000, i)); 367 expectEqualsInt(0xFFFFFFFF, $noinline$rotateLeftByte((byte)0xFFFF, i)); 368 expectEqualsInt((1 << j), $noinline$rotateLeftByte((byte)0x0001, i)); 369 expectEqualsInt((0x12 << j) | (0x12 >>> -j), $noinline$rotateLeftByte((byte)0x12, i)); 370 } 371 } 372 testRotateLeftShort()373 public static void testRotateLeftShort() { 374 expectEqualsInt(0x00000001, $inline$rotateLeftShort((short)0x0001, 0)); 375 expectEqualsInt(0x00000002, $inline$rotateLeftShort((short)0x0001, 1)); 376 expectEqualsInt(0x80000000, $inline$rotateLeftShort((short)0x0001, 31)); 377 expectEqualsInt(0x00000001, $inline$rotateLeftShort((short)0x0001, 32)); // overshoot 378 expectEqualsInt(0xFFFF0003, $inline$rotateLeftShort((short)0x8001, 1)); 379 expectEqualsInt(0xFFFE0007, $inline$rotateLeftShort((short)0x8001, 2)); 380 expectEqualsInt(0x00012340, $inline$rotateLeftShort((short)0x1234, 4)); 381 expectEqualsInt(0xFF9ABCFF, $inline$rotateLeftShort((short)0x9ABC, 8)); 382 383 expectEqualsInt(0x00000001, $noinline$rotateLeftShort((short)0x0001, 0)); 384 expectEqualsInt(0x00000002, $noinline$rotateLeftShort((short)0x0001, 1)); 385 expectEqualsInt(0x80000000, $noinline$rotateLeftShort((short)0x0001, 31)); 386 expectEqualsInt(0x00000001, $noinline$rotateLeftShort((short)0x0001, 32)); // overshoot 387 expectEqualsInt(0xFFFF0003, $noinline$rotateLeftShort((short)0x8001, 1)); 388 expectEqualsInt(0xFFFE0007, $noinline$rotateLeftShort((short)0x8001, 2)); 389 expectEqualsInt(0x00012340, $noinline$rotateLeftShort((short)0x1234, 4)); 390 expectEqualsInt(0xFF9ABCFF, $noinline$rotateLeftShort((short)0x9ABC, 8)); 391 392 for (int i = 0; i < 40; i++) { // overshoot a bit 393 int j = i & 31; 394 expectEqualsInt(0x00000000, $inline$rotateLeftShort((short)0x0000, i)); 395 expectEqualsInt(0xFFFFFFFF, $inline$rotateLeftShort((short)0xFFFF, i)); 396 expectEqualsInt((1 << j), $inline$rotateLeftShort((short)0x0001, i)); 397 expectEqualsInt((0x1234 << j) | (0x1234 >>> -j), $inline$rotateLeftShort((short)0x1234, i)); 398 399 expectEqualsInt(0x00000000, $noinline$rotateLeftShort((short)0x0000, i)); 400 expectEqualsInt(0xFFFFFFFF, $noinline$rotateLeftShort((short)0xFFFF, i)); 401 expectEqualsInt((1 << j), $noinline$rotateLeftShort((short)0x0001, i)); 402 expectEqualsInt((0x1234 << j) | (0x1234 >>> -j), $noinline$rotateLeftShort((short)0x1234, i)); 403 } 404 } 405 testRotateLeftChar()406 public static void testRotateLeftChar() { 407 expectEqualsInt(0x00000001, $inline$rotateLeftChar((char)0x0001, 0)); 408 expectEqualsInt(0x00000002, $inline$rotateLeftChar((char)0x0001, 1)); 409 expectEqualsInt(0x80000000, $inline$rotateLeftChar((char)0x0001, 31)); 410 expectEqualsInt(0x00000001, $inline$rotateLeftChar((char)0x0001, 32)); // overshoot 411 expectEqualsInt(0x00010002, $inline$rotateLeftChar((char)0x8001, 1)); 412 expectEqualsInt(0x00020004, $inline$rotateLeftChar((char)0x8001, 2)); 413 expectEqualsInt(0x00012340, $inline$rotateLeftChar((char)0x1234, 4)); 414 expectEqualsInt(0x009ABC00, $inline$rotateLeftChar((char)0x9ABC, 8)); 415 expectEqualsInt(0x00FF0000, $inline$rotateLeftChar((char)0xFF00, 8)); 416 417 expectEqualsInt(0x00000001, $noinline$rotateLeftChar((char)0x0001, 0)); 418 expectEqualsInt(0x00000002, $noinline$rotateLeftChar((char)0x0001, 1)); 419 expectEqualsInt(0x80000000, $noinline$rotateLeftChar((char)0x0001, 31)); 420 expectEqualsInt(0x00000001, $noinline$rotateLeftChar((char)0x0001, 32)); // overshoot 421 expectEqualsInt(0x00010002, $noinline$rotateLeftChar((char)0x8001, 1)); 422 expectEqualsInt(0x00020004, $noinline$rotateLeftChar((char)0x8001, 2)); 423 expectEqualsInt(0x00012340, $noinline$rotateLeftChar((char)0x1234, 4)); 424 expectEqualsInt(0x009ABC00, $noinline$rotateLeftChar((char)0x9ABC, 8)); 425 expectEqualsInt(0x00FF0000, $noinline$rotateLeftChar((char)0xFF00, 8)); 426 427 for (int i = 0; i < 40; i++) { // overshoot a bit 428 int j = i & 31; 429 expectEqualsInt(0x00000000, $inline$rotateLeftChar((char)0x0000, i)); 430 expectEqualsInt((1 << j), $inline$rotateLeftChar((char)0x0001, i)); 431 expectEqualsInt((0x1234 << j) | (0x1234 >>> -j), $inline$rotateLeftChar((char)0x1234, i)); 432 433 expectEqualsInt(0x00000000, $noinline$rotateLeftChar((char)0x0000, i)); 434 expectEqualsInt((1 << j), $noinline$rotateLeftChar((char)0x0001, i)); 435 expectEqualsInt((0x1234 << j) | (0x1234 >>> -j), $noinline$rotateLeftChar((char)0x1234, i)); 436 } 437 } 438 testRotateLeftInt()439 public static void testRotateLeftInt() { 440 expectEqualsInt(0x00000001, $inline$rotateLeftInt(0x00000001, 0)); 441 expectEqualsInt(0x00000002, $inline$rotateLeftInt(0x00000001, 1)); 442 expectEqualsInt(0x80000000, $inline$rotateLeftInt(0x00000001, 31)); 443 expectEqualsInt(0x00000001, $inline$rotateLeftInt(0x00000001, 32)); // overshoot 444 expectEqualsInt(0x00000003, $inline$rotateLeftInt(0x80000001, 1)); 445 expectEqualsInt(0x00000006, $inline$rotateLeftInt(0x80000001, 2)); 446 expectEqualsInt(0x23456781, $inline$rotateLeftInt(0x12345678, 4)); 447 expectEqualsInt(0xBCDEF09A, $inline$rotateLeftInt(0x9ABCDEF0, 8)); 448 449 expectEqualsInt(0x00000001, $noinline$rotateLeftInt(0x00000001, 0)); 450 expectEqualsInt(0x00000002, $noinline$rotateLeftInt(0x00000001, 1)); 451 expectEqualsInt(0x80000000, $noinline$rotateLeftInt(0x00000001, 31)); 452 expectEqualsInt(0x00000001, $noinline$rotateLeftInt(0x00000001, 32)); // overshoot 453 expectEqualsInt(0x00000003, $noinline$rotateLeftInt(0x80000001, 1)); 454 expectEqualsInt(0x00000006, $noinline$rotateLeftInt(0x80000001, 2)); 455 expectEqualsInt(0x23456781, $noinline$rotateLeftInt(0x12345678, 4)); 456 expectEqualsInt(0xBCDEF09A, $noinline$rotateLeftInt(0x9ABCDEF0, 8)); 457 expectEqualsInt(0x80000000, $noinline$rotateLeftIntConstant(0x00000001)); 458 expectEqualsInt(Integer.MIN_VALUE, $noinline$rotateLeftIntMulNegDistance(1, -2)); 459 460 for (int i = 0; i < 40; i++) { // overshoot a bit 461 int j = i & 31; 462 expectEqualsInt(0x00000000, $inline$rotateLeftInt(0x00000000, i)); 463 expectEqualsInt(0xFFFFFFFF, $inline$rotateLeftInt(0xFFFFFFFF, i)); 464 expectEqualsInt(1 << j, $inline$rotateLeftInt(0x00000001, i)); 465 expectEqualsInt((0x12345678 << j) | (0x12345678 >>> -j), 466 $inline$rotateLeftInt(0x12345678, i)); 467 468 expectEqualsInt(0x00000000, $noinline$rotateLeftInt(0x00000000, i)); 469 expectEqualsInt(0xFFFFFFFF, $noinline$rotateLeftInt(0xFFFFFFFF, i)); 470 expectEqualsInt(1 << j, $noinline$rotateLeftInt(0x00000001, i)); 471 expectEqualsInt((0x12345678 << j) | (0x12345678 >>> -j), 472 $noinline$rotateLeftInt(0x12345678, i)); 473 } 474 } 475 testRotateLeftLong()476 public static void testRotateLeftLong() { 477 expectEqualsLong(0x0000000000000001L, $inline$rotateLeftLong(0x0000000000000001L, 0)); 478 expectEqualsLong(0x0000000000000002L, $inline$rotateLeftLong(0x0000000000000001L, 1)); 479 expectEqualsLong(0x8000000000000000L, $inline$rotateLeftLong(0x0000000000000001L, 63)); 480 expectEqualsLong(0x8000000000000000L, $noinline$rotateLeftLongConstant(0x0000000000000001L)); 481 expectEqualsLong(0x0000000000000001L, 482 $inline$rotateLeftLong(0x0000000000000001L, 64)); // overshoot 483 expectEqualsLong(0x0000000000000003L, $inline$rotateLeftLong(0x8000000000000001L, 1)); 484 expectEqualsLong(0x0000000000000006L, $inline$rotateLeftLong(0x8000000000000001L, 2)); 485 expectEqualsLong(0x23456789ABCDEF01L, $inline$rotateLeftLong(0x123456789ABCDEF0L, 4)); 486 expectEqualsLong(0x3456789ABCDEF012L, $inline$rotateLeftLong(0x123456789ABCDEF0L, 8)); 487 488 expectEqualsLong(0x0000000000000001L, $noinline$rotateLeftLong(0x0000000000000001L, 0)); 489 expectEqualsLong(0x0000000000000002L, $noinline$rotateLeftLong(0x0000000000000001L, 1)); 490 expectEqualsLong(0x8000000000000000L, $noinline$rotateLeftLong(0x0000000000000001L, 63)); 491 expectEqualsLong(0x0000000000000001L, 492 $noinline$rotateLeftLong(0x0000000000000001L, 64)); // overshoot 493 expectEqualsLong(0x0000000000000003L, $noinline$rotateLeftLong(0x8000000000000001L, 1)); 494 expectEqualsLong(0x0000000000000006L, $noinline$rotateLeftLong(0x8000000000000001L, 2)); 495 expectEqualsLong(0x23456789ABCDEF01L, $noinline$rotateLeftLong(0x123456789ABCDEF0L, 4)); 496 expectEqualsLong(0x3456789ABCDEF012L, $noinline$rotateLeftLong(0x123456789ABCDEF0L, 8)); 497 for (int i = 0; i < 70; i++) { // overshoot a bit 498 int j = i & 63; 499 expectEqualsLong(0x0000000000000000L, $inline$rotateLeftLong(0x0000000000000000L, i)); 500 expectEqualsLong(0xFFFFFFFFFFFFFFFFL, $inline$rotateLeftLong(0xFFFFFFFFFFFFFFFFL, i)); 501 expectEqualsLong(1L << j, $inline$rotateLeftLong(0x0000000000000001, i)); 502 expectEqualsLong((0x123456789ABCDEF0L << j) | (0x123456789ABCDEF0L >>> -j), 503 $inline$rotateLeftLong(0x123456789ABCDEF0L, i)); 504 505 expectEqualsLong(0x0000000000000000L, $noinline$rotateLeftLong(0x0000000000000000L, i)); 506 expectEqualsLong(0xFFFFFFFFFFFFFFFFL, $noinline$rotateLeftLong(0xFFFFFFFFFFFFFFFFL, i)); 507 expectEqualsLong(1L << j, $noinline$rotateLeftLong(0x0000000000000001, i)); 508 expectEqualsLong((0x123456789ABCDEF0L << j) | (0x123456789ABCDEF0L >>> -j), 509 $noinline$rotateLeftLong(0x123456789ABCDEF0L, i)); 510 } 511 } 512 513 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) builder (after) 514 /// CHECK: <<ArgVal:z\d+>> ParameterValue 515 /// CHECK: <<ArgDist:i\d+>> ParameterValue 516 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 517 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 518 /// CHECK-DAG: <<Val:i\d+>> Phi [<<One>>,<<Zero>>] 519 /// CHECK-DAG: <<Result:i\d+>> Ror [<<Val>>,<<ArgDist>>] 520 /// CHECK-DAG: Return [<<Result>>] 521 522 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) builder (after) 523 /// CHECK-NOT: InvokeStaticOrDirect 524 525 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) select_generator (after) 526 /// CHECK: <<ArgVal:z\d+>> ParameterValue 527 /// CHECK: <<ArgDist:i\d+>> ParameterValue 528 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 529 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 530 /// CHECK-DAG: <<SelVal:i\d+>> Select [<<Zero>>,<<One>>,<<ArgVal>>] 531 /// CHECK-DAG: <<Result:i\d+>> Ror [<<SelVal>>,<<ArgDist>>] 532 /// CHECK-DAG: Return [<<Result>>] 533 534 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) select_generator (after) 535 /// CHECK-NOT: Phi 536 537 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) instruction_simplifier$before_codegen (after) 538 /// CHECK: <<ArgVal:z\d+>> ParameterValue 539 /// CHECK: <<ArgDist:i\d+>> ParameterValue 540 /// CHECK-DAG: <<Result:i\d+>> Ror [<<ArgVal>>,<<ArgDist>>] 541 /// CHECK-DAG: Return [<<Result>>] 542 543 /// CHECK-START: int TestRotate.rotateRightBoolean(boolean, int) instruction_simplifier$before_codegen (after) 544 /// CHECK-NOT: Select 545 rotateRightBoolean(boolean value, int distance)546 private static int rotateRightBoolean(boolean value, int distance) { 547 // Note: D8 would replace the ternary expression `value ? 1 : 0` with `value` 548 // but explicit `if` is preserved. 549 int src; 550 if (value) { 551 src = 1; 552 } else { 553 src = 0; 554 } 555 return Integer.rotateRight(src, distance); 556 } 557 testRotateRightBoolean()558 public static void testRotateRightBoolean() { 559 for (int i = 0; i < 40; i++) { // overshoot a bit 560 int j = (-i) & 31; 561 expectEqualsInt(0, rotateRightBoolean(false, i)); 562 expectEqualsInt(1 << j, rotateRightBoolean(true, i)); 563 } 564 } 565 testRotateRightByte()566 public static void testRotateRightByte() { 567 expectEqualsInt(0xFFFFFF80, rotateRightByte((byte)0x80, 0)); 568 expectEqualsInt(0x7FFFFFC0, rotateRightByte((byte)0x80, 1)); 569 expectEqualsInt(0xFFFFFF01, rotateRightByte((byte)0x80, 31)); 570 expectEqualsInt(0xFFFFFF80, rotateRightByte((byte)0x80, 32)); // overshoot 571 expectEqualsInt(0xFFFFFFC0, rotateRightByte((byte)0x81, 1)); 572 expectEqualsInt(0x7FFFFFE0, rotateRightByte((byte)0x81, 2)); 573 expectEqualsInt(0x20000001, rotateRightByte((byte)0x12, 4)); 574 expectEqualsInt(0x9AFFFFFF, rotateRightByte((byte)0x9A, 8)); 575 for (int i = 0; i < 40; i++) { // overshoot a bit 576 int j = i & 31; 577 expectEqualsInt(0x00000000, rotateRightByte((byte)0x00, i)); 578 expectEqualsInt(0xFFFFFFFF, rotateRightByte((byte)0xFF, i)); 579 expectEqualsInt(1 << (32 - j), rotateRightByte((byte)0x01, i)); 580 expectEqualsInt((0x12 >>> j) | (0x12 << -j), rotateRightByte((byte)0x12, i)); 581 } 582 } 583 testRotateRightShort()584 public static void testRotateRightShort() { 585 expectEqualsInt(0xFFFF8000, rotateRightShort((short)0x8000, 0)); 586 expectEqualsInt(0x7FFFC000, rotateRightShort((short)0x8000, 1)); 587 expectEqualsInt(0xFFFF0001, rotateRightShort((short)0x8000, 31)); 588 expectEqualsInt(0xFFFF8000, rotateRightShort((short)0x8000, 32)); // overshoot 589 expectEqualsInt(0xFFFFC000, rotateRightShort((short)0x8001, 1)); 590 expectEqualsInt(0x7FFFE000, rotateRightShort((short)0x8001, 2)); 591 expectEqualsInt(0x40000123, rotateRightShort((short)0x1234, 4)); 592 expectEqualsInt(0xBCFFFF9A, rotateRightShort((short)0x9ABC, 8)); 593 for (int i = 0; i < 40; i++) { // overshoot a bit 594 int j = i & 31; 595 expectEqualsInt(0x00000000, rotateRightShort((short)0x0000, i)); 596 expectEqualsInt(0xFFFFFFFF, rotateRightShort((short)0xFFFF, i)); 597 expectEqualsInt(1 << (32 - j), rotateRightShort((short)0x0001, i)); 598 expectEqualsInt((0x1234 >>> j) | (0x1234 << -j), rotateRightShort((short)0x1234, i)); 599 } 600 } 601 testRotateRightChar()602 public static void testRotateRightChar() { 603 expectEqualsInt(0x00008000, rotateRightChar((char)0x8000, 0)); 604 expectEqualsInt(0x00004000, rotateRightChar((char)0x8000, 1)); 605 expectEqualsInt(0x00010000, rotateRightChar((char)0x8000, 31)); 606 expectEqualsInt(0x00008000, rotateRightChar((char)0x8000, 32)); // overshoot 607 expectEqualsInt(0x80004000, rotateRightChar((char)0x8001, 1)); 608 expectEqualsInt(0x40002000, rotateRightChar((char)0x8001, 2)); 609 expectEqualsInt(0x40000123, rotateRightChar((char)0x1234, 4)); 610 expectEqualsInt(0xBC00009A, rotateRightChar((char)0x9ABC, 8)); 611 for (int i = 0; i < 40; i++) { // overshoot a bit 612 int j = i & 31; 613 expectEqualsInt(0x00000000, rotateRightChar((char)0x0000, i)); 614 expectEqualsInt(1 << (32 - j), rotateRightChar((char)0x0001, i)); 615 expectEqualsInt((0x1234 >>> j) | (0x1234 << -j), rotateRightChar((char)0x1234, i)); 616 } 617 } 618 testRotateRightInt()619 public static void testRotateRightInt() { 620 expectEqualsInt(0x80000000, rotateRightInt(0x80000000, 0)); 621 expectEqualsInt(0x40000000, rotateRightInt(0x80000000, 1)); 622 expectEqualsInt(0x00000001, rotateRightInt(0x80000000, 31)); 623 expectEqualsInt(0x80000000, rotateRightInt(0x80000000, 32)); // overshoot 624 expectEqualsInt(0xC0000000, rotateRightInt(0x80000001, 1)); 625 expectEqualsInt(0x60000000, rotateRightInt(0x80000001, 2)); 626 expectEqualsInt(0x81234567, rotateRightInt(0x12345678, 4)); 627 expectEqualsInt(0xF09ABCDE, rotateRightInt(0x9ABCDEF0, 8)); 628 for (int i = 0; i < 40; i++) { // overshoot a bit 629 int j = i & 31; 630 expectEqualsInt(0x00000000, rotateRightInt(0x00000000, i)); 631 expectEqualsInt(0xFFFFFFFF, rotateRightInt(0xFFFFFFFF, i)); 632 expectEqualsInt(0x80000000 >>> j, rotateRightInt(0x80000000, i)); 633 expectEqualsInt((0x12345678 >>> j) | (0x12345678 << -j), rotateRightInt(0x12345678, i)); 634 } 635 } 636 testRotateRightLong()637 public static void testRotateRightLong() { 638 expectEqualsLong(0x8000000000000000L, rotateRightLong(0x8000000000000000L, 0)); 639 expectEqualsLong(0x4000000000000000L, rotateRightLong(0x8000000000000000L, 1)); 640 expectEqualsLong(0x0000000000000001L, rotateRightLong(0x8000000000000000L, 63)); 641 expectEqualsLong(0x8000000000000000L, rotateRightLong(0x8000000000000000L, 64)); // overshoot 642 expectEqualsLong(0xC000000000000000L, rotateRightLong(0x8000000000000001L, 1)); 643 expectEqualsLong(0x6000000000000000L, rotateRightLong(0x8000000000000001L, 2)); 644 expectEqualsLong(0x0123456789ABCDEFL, rotateRightLong(0x123456789ABCDEF0L, 4)); 645 expectEqualsLong(0xF0123456789ABCDEL, rotateRightLong(0x123456789ABCDEF0L, 8)); 646 for (int i = 0; i < 70; i++) { // overshoot a bit 647 int j = i & 63; 648 expectEqualsLong(0x0000000000000000L, rotateRightLong(0x0000000000000000L, i)); 649 expectEqualsLong(0xFFFFFFFFFFFFFFFFL, rotateRightLong(0xFFFFFFFFFFFFFFFFL, i)); 650 expectEqualsLong(0x8000000000000000L >>> j, rotateRightLong(0x8000000000000000L, i)); 651 expectEqualsLong((0x123456789ABCDEF0L >>> j) | (0x123456789ABCDEF0L << -j), 652 rotateRightLong(0x123456789ABCDEF0L, i)); 653 } 654 } 655 656 testRotateLeftIntWithByteDistance()657 public static void testRotateLeftIntWithByteDistance() { 658 expectEqualsInt(0x00000001, $inline$rotateLeftIntWithByteDistance(0x00000001, (byte)0)); 659 expectEqualsInt(0x00000002, $inline$rotateLeftIntWithByteDistance(0x00000001, (byte)1)); 660 expectEqualsInt(0x80000000, $inline$rotateLeftIntWithByteDistance(0x00000001, (byte)31)); 661 expectEqualsInt(0x00000001, 662 $inline$rotateLeftIntWithByteDistance(0x00000001, (byte)32)); // overshoot 663 expectEqualsInt(0x00000003, $inline$rotateLeftIntWithByteDistance(0x80000001, (byte)1)); 664 expectEqualsInt(0x00000006, $inline$rotateLeftIntWithByteDistance(0x80000001, (byte)2)); 665 expectEqualsInt(0x23456781, $inline$rotateLeftIntWithByteDistance(0x12345678, (byte)4)); 666 expectEqualsInt(0xBCDEF09A, $inline$rotateLeftIntWithByteDistance(0x9ABCDEF0, (byte)8)); 667 668 expectEqualsInt(0x00000001, $noinline$rotateLeftIntWithByteDistance(0x00000001, (byte)0)); 669 expectEqualsInt(0x00000002, $noinline$rotateLeftIntWithByteDistance(0x00000001, (byte)1)); 670 expectEqualsInt(0x80000000, $noinline$rotateLeftIntWithByteDistance(0x00000001, (byte)31)); 671 expectEqualsInt(0x00000001, 672 $noinline$rotateLeftIntWithByteDistance(0x00000001, (byte)32)); // overshoot 673 expectEqualsInt(0x00000003, $noinline$rotateLeftIntWithByteDistance(0x80000001, (byte)1)); 674 expectEqualsInt(0x00000006, $noinline$rotateLeftIntWithByteDistance(0x80000001, (byte)2)); 675 expectEqualsInt(0x23456781, $noinline$rotateLeftIntWithByteDistance(0x12345678, (byte)4)); 676 expectEqualsInt(0xBCDEF09A, $noinline$rotateLeftIntWithByteDistance(0x9ABCDEF0, (byte)8)); 677 678 for (byte i = 0; i < 40; i++) { // overshoot a bit 679 byte j = (byte)(i & 31); 680 expectEqualsInt(0x00000000, $inline$rotateLeftIntWithByteDistance(0x00000000, i)); 681 expectEqualsInt(0xFFFFFFFF, $inline$rotateLeftIntWithByteDistance(0xFFFFFFFF, i)); 682 expectEqualsInt(1 << j, $inline$rotateLeftIntWithByteDistance(0x00000001, i)); 683 expectEqualsInt((0x12345678 << j) | (0x12345678 >>> -j), 684 $inline$rotateLeftIntWithByteDistance(0x12345678, i)); 685 686 expectEqualsInt(0x00000000, $noinline$rotateLeftIntWithByteDistance(0x00000000, i)); 687 expectEqualsInt(0xFFFFFFFF, $noinline$rotateLeftIntWithByteDistance(0xFFFFFFFF, i)); 688 expectEqualsInt(1 << j, $noinline$rotateLeftIntWithByteDistance(0x00000001, i)); 689 expectEqualsInt((0x12345678 << j) | (0x12345678 >>> -j), 690 $noinline$rotateLeftIntWithByteDistance(0x12345678, i)); 691 } 692 } 693 testRotateRightIntWithByteDistance()694 public static void testRotateRightIntWithByteDistance() { 695 expectEqualsInt(0x80000000, rotateRightIntWithByteDistance(0x80000000, (byte)0)); 696 expectEqualsInt(0x40000000, rotateRightIntWithByteDistance(0x80000000, (byte)1)); 697 expectEqualsInt(0x00000001, rotateRightIntWithByteDistance(0x80000000, (byte)31)); 698 expectEqualsInt(0x80000000, 699 rotateRightIntWithByteDistance(0x80000000, (byte)32)); // overshoot 700 expectEqualsInt(0xC0000000, rotateRightIntWithByteDistance(0x80000001, (byte)1)); 701 expectEqualsInt(0x60000000, rotateRightIntWithByteDistance(0x80000001, (byte)2)); 702 expectEqualsInt(0x81234567, rotateRightIntWithByteDistance(0x12345678, (byte)4)); 703 expectEqualsInt(0xF09ABCDE, rotateRightIntWithByteDistance(0x9ABCDEF0, (byte)8)); 704 for (byte i = 0; i < 40; i++) { // overshoot a bit 705 byte j = (byte)(i & 31); 706 expectEqualsInt(0x00000000, rotateRightIntWithByteDistance(0x00000000, i)); 707 expectEqualsInt(0xFFFFFFFF, rotateRightIntWithByteDistance(0xFFFFFFFF, i)); 708 expectEqualsInt(0x80000000 >>> j, rotateRightIntWithByteDistance(0x80000000, i)); 709 expectEqualsInt((0x12345678 >>> j) | (0x12345678 << -j), 710 rotateRightIntWithByteDistance(0x12345678, i)); 711 } 712 } 713 714 main()715 public static void main() { 716 testRotateLeftBoolean(); 717 testRotateLeftByte(); 718 testRotateLeftShort(); 719 testRotateLeftChar(); 720 testRotateLeftInt(); 721 testRotateLeftLong(); 722 723 testRotateRightBoolean(); 724 testRotateRightByte(); 725 testRotateRightShort(); 726 testRotateRightChar(); 727 testRotateRightInt(); 728 testRotateRightLong(); 729 730 // Also exercise distance values with types other than int. 731 testRotateLeftIntWithByteDistance(); 732 testRotateRightIntWithByteDistance(); 733 734 System.out.println("TestRotate passed"); 735 } 736 737 expectEqualsInt(int expected, int result)738 private static void expectEqualsInt(int expected, int result) { 739 if (expected != result) { 740 throw new Error("Expected: " + expected + ", found: " + result); 741 } 742 } 743 expectEqualsLong(long expected, long result)744 private static void expectEqualsLong(long expected, long result) { 745 if (expected != result) { 746 throw new Error("Expected: " + expected + ", found: " + result); 747 } 748 } 749 } 750