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 Main { 18 19 public static boolean doThrow = false; 20 21 /// CHECK-START: void Main.$opt$noinline$testReplaceInputWithItself(int) intrinsics_recognition (after) 22 /// CHECK-DAG: <<ArgX:i\d+>> ParameterValue 23 /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod 24 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 25 /// CHECK-DAG: <<Cmp:i\d+>> InvokeStaticOrDirect [<<ArgX>>,<<Zero>>,<<Method>>] intrinsic:IntegerCompare 26 /// CHECK-DAG: GreaterThanOrEqual [<<Cmp>>,<<Zero>>] 27 28 /// CHECK-START: void Main.$opt$noinline$testReplaceInputWithItself(int) instruction_simplifier (after) 29 /// CHECK-DAG: <<ArgX:i\d+>> ParameterValue 30 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 31 /// CHECK-DAG: GreaterThanOrEqual [<<ArgX>>,<<Zero>>] 32 33 public static void $opt$noinline$testReplaceInputWithItself(int x) { 34 if (doThrow) { throw new Error(); } 35 36 // The instruction simplifier first replaces Integer.compare(x, 0) with Compare HIR 37 // and then merges the Compare into the GreaterThanOrEqual. This is a regression 38 // test that to check that it is allowed to replace the second input of the 39 // GreaterThanOrEqual, i.e. <<Zero>>, with the very same instruction. 40 if (Integer.compare(x, 0) < 0) { 41 System.out.println("OOOPS"); 42 } 43 } 44 45 /// CHECK-START: int Main.compareBooleans(boolean, boolean) intrinsics_recognition (after) 46 /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod 47 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 48 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 49 /// CHECK-DAG: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] 50 /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] 51 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<PhiX>>,<<PhiY>>,<<Method>>] intrinsic:IntegerCompare 52 /// CHECK-DAG: Return [<<Result>>] 53 54 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier (after) 55 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 56 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 57 /// CHECK-DAG: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] 58 /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] 59 /// CHECK-DAG: <<Result:i\d+>> Compare [<<PhiX>>,<<PhiY>>] 60 /// CHECK-DAG: Return [<<Result>>] 61 62 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier (after) 63 /// CHECK-NOT: InvokeStaticOrDirect 64 65 /// CHECK-START: int Main.compareBooleans(boolean, boolean) select_generator (after) 66 /// CHECK: <<ArgX:z\d+>> ParameterValue 67 /// CHECK: <<ArgY:z\d+>> ParameterValue 68 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 69 /// CHECK-DAG: <<One:i\d+>> IntConstant 1 70 /// CHECK-DAG: <<SelX:i\d+>> Select [<<Zero>>,<<One>>,<<ArgX>>] 71 /// CHECK-DAG: <<SelY:i\d+>> Select [<<Zero>>,<<One>>,<<ArgY>>] 72 /// CHECK-DAG: <<Result:i\d+>> Compare [<<SelX>>,<<SelY>>] 73 /// CHECK-DAG: Return [<<Result>>] 74 75 /// CHECK-START: int Main.compareBooleans(boolean, boolean) select_generator (after) 76 /// CHECK-NOT: Phi 77 78 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier_after_bce (after) 79 /// CHECK: <<ArgX:z\d+>> ParameterValue 80 /// CHECK: <<ArgY:z\d+>> ParameterValue 81 /// CHECK-DAG: <<Result:i\d+>> Compare [<<ArgX>>,<<ArgY>>] 82 /// CHECK-DAG: Return [<<Result>>] 83 84 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier_after_bce (after) 85 /// CHECK-NOT: Select 86 87 private static int compareBooleans(boolean x, boolean y) { 88 return Integer.compare((x ? 1 : 0), (y ? 1 : 0)); 89 } 90 91 /// CHECK-START: int Main.compareBytes(byte, byte) intrinsics_recognition (after) 92 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 93 /// CHECK-DAG: Return [<<Result>>] 94 95 /// CHECK-START: int Main.compareBytes(byte, byte) instruction_simplifier (after) 96 /// CHECK-DAG: <<Result:i\d+>> Compare 97 /// CHECK-DAG: Return [<<Result>>] 98 99 /// CHECK-START: int Main.compareBytes(byte, byte) instruction_simplifier (after) 100 /// CHECK-NOT: InvokeStaticOrDirect 101 102 private static int compareBytes(byte x, byte y) { 103 return Integer.compare(x, y); 104 } 105 106 /// CHECK-START: int Main.compareShorts(short, short) intrinsics_recognition (after) 107 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 108 /// CHECK-DAG: Return [<<Result>>] 109 110 /// CHECK-START: int Main.compareShorts(short, short) instruction_simplifier (after) 111 /// CHECK-DAG: <<Result:i\d+>> Compare 112 /// CHECK-DAG: Return [<<Result>>] 113 114 /// CHECK-START: int Main.compareShorts(short, short) instruction_simplifier (after) 115 /// CHECK-NOT: InvokeStaticOrDirect 116 117 private static int compareShorts(short x, short y) { 118 return Integer.compare(x, y); 119 } 120 121 /// CHECK-START: int Main.compareChars(char, char) intrinsics_recognition (after) 122 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 123 /// CHECK-DAG: Return [<<Result>>] 124 125 /// CHECK-START: int Main.compareChars(char, char) instruction_simplifier (after) 126 /// CHECK-DAG: <<Result:i\d+>> Compare 127 /// CHECK-DAG: Return [<<Result>>] 128 129 /// CHECK-START: int Main.compareChars(char, char) instruction_simplifier (after) 130 /// CHECK-NOT: InvokeStaticOrDirect 131 132 private static int compareChars(char x, char y) { 133 return Integer.compare(x, y); 134 } 135 136 /// CHECK-START: int Main.compareInts(int, int) intrinsics_recognition (after) 137 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 138 /// CHECK-DAG: Return [<<Result>>] 139 140 /// CHECK-START: int Main.compareInts(int, int) instruction_simplifier (after) 141 /// CHECK-DAG: <<Result:i\d+>> Compare 142 /// CHECK-DAG: Return [<<Result>>] 143 144 /// CHECK-START: int Main.compareInts(int, int) instruction_simplifier (after) 145 /// CHECK-NOT: InvokeStaticOrDirect 146 147 private static int compareInts(int x, int y) { 148 return Integer.compare(x, y); 149 } 150 151 /// CHECK-START: int Main.compareLongs(long, long) intrinsics_recognition (after) 152 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:LongCompare 153 /// CHECK-DAG: Return [<<Result>>] 154 155 /// CHECK-START: int Main.compareLongs(long, long) instruction_simplifier (after) 156 /// CHECK-DAG: <<Result:i\d+>> Compare 157 /// CHECK-DAG: Return [<<Result>>] 158 159 /// CHECK-START: int Main.compareLongs(long, long) instruction_simplifier (after) 160 /// CHECK-NOT: InvokeStaticOrDirect 161 162 private static int compareLongs(long x, long y) { 163 return Long.compare(x, y); 164 } 165 166 167 /// CHECK-START: int Main.compareByteShort(byte, short) intrinsics_recognition (after) 168 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 169 /// CHECK-DAG: Return [<<Result>>] 170 171 /// CHECK-START: int Main.compareByteShort(byte, short) instruction_simplifier (after) 172 /// CHECK-DAG: <<Result:i\d+>> Compare 173 /// CHECK-DAG: Return [<<Result>>] 174 175 /// CHECK-START: int Main.compareByteShort(byte, short) instruction_simplifier (after) 176 /// CHECK-NOT: InvokeStaticOrDirect 177 178 public static int compareByteShort(byte x, short y) { 179 return Integer.compare(x, y); 180 } 181 182 /// CHECK-START: int Main.compareByteChar(byte, char) intrinsics_recognition (after) 183 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 184 /// CHECK-DAG: Return [<<Result>>] 185 186 /// CHECK-START: int Main.compareByteChar(byte, char) instruction_simplifier (after) 187 /// CHECK-DAG: <<Result:i\d+>> Compare 188 /// CHECK-DAG: Return [<<Result>>] 189 190 /// CHECK-START: int Main.compareByteChar(byte, char) instruction_simplifier (after) 191 /// CHECK-NOT: InvokeStaticOrDirect 192 193 public static int compareByteChar(byte x, char y) { 194 return Integer.compare(x, y); 195 } 196 197 /// CHECK-START: int Main.compareByteInt(byte, int) intrinsics_recognition (after) 198 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 199 /// CHECK-DAG: Return [<<Result>>] 200 201 /// CHECK-START: int Main.compareByteInt(byte, int) instruction_simplifier (after) 202 /// CHECK-DAG: <<Result:i\d+>> Compare 203 /// CHECK-DAG: Return [<<Result>>] 204 205 /// CHECK-START: int Main.compareByteInt(byte, int) instruction_simplifier (after) 206 /// CHECK-NOT: InvokeStaticOrDirect 207 208 public static int compareByteInt(byte x, int y) { 209 return Integer.compare(x, y); 210 } 211 212 213 /// CHECK-START: int Main.compareShortByte(short, byte) intrinsics_recognition (after) 214 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 215 /// CHECK-DAG: Return [<<Result>>] 216 217 /// CHECK-START: int Main.compareShortByte(short, byte) instruction_simplifier (after) 218 /// CHECK-DAG: <<Result:i\d+>> Compare 219 /// CHECK-DAG: Return [<<Result>>] 220 221 /// CHECK-START: int Main.compareShortByte(short, byte) instruction_simplifier (after) 222 /// CHECK-NOT: InvokeStaticOrDirect 223 224 public static int compareShortByte(short x, byte y) { 225 return Integer.compare(x, y); 226 } 227 228 /// CHECK-START: int Main.compareShortChar(short, char) intrinsics_recognition (after) 229 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 230 /// CHECK-DAG: Return [<<Result>>] 231 232 /// CHECK-START: int Main.compareShortChar(short, char) instruction_simplifier (after) 233 /// CHECK-DAG: <<Result:i\d+>> Compare 234 /// CHECK-DAG: Return [<<Result>>] 235 236 /// CHECK-START: int Main.compareShortChar(short, char) instruction_simplifier (after) 237 /// CHECK-NOT: InvokeStaticOrDirect 238 239 public static int compareShortChar(short x, char y) { 240 return Integer.compare(x, y); 241 } 242 243 /// CHECK-START: int Main.compareShortInt(short, int) intrinsics_recognition (after) 244 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 245 /// CHECK-DAG: Return [<<Result>>] 246 247 /// CHECK-START: int Main.compareShortInt(short, int) instruction_simplifier (after) 248 /// CHECK-DAG: <<Result:i\d+>> Compare 249 /// CHECK-DAG: Return [<<Result>>] 250 251 /// CHECK-START: int Main.compareShortInt(short, int) instruction_simplifier (after) 252 /// CHECK-NOT: InvokeStaticOrDirect 253 254 public static int compareShortInt(short x, int y) { 255 return Integer.compare(x, y); 256 } 257 258 259 /// CHECK-START: int Main.compareCharByte(char, byte) intrinsics_recognition (after) 260 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 261 /// CHECK-DAG: Return [<<Result>>] 262 263 /// CHECK-START: int Main.compareCharByte(char, byte) instruction_simplifier (after) 264 /// CHECK-DAG: <<Result:i\d+>> Compare 265 /// CHECK-DAG: Return [<<Result>>] 266 267 /// CHECK-START: int Main.compareCharByte(char, byte) instruction_simplifier (after) 268 /// CHECK-NOT: InvokeStaticOrDirect 269 270 public static int compareCharByte(char x, byte y) { 271 return Integer.compare(x, y); 272 } 273 274 /// CHECK-START: int Main.compareCharShort(char, short) intrinsics_recognition (after) 275 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 276 /// CHECK-DAG: Return [<<Result>>] 277 278 /// CHECK-START: int Main.compareCharShort(char, short) instruction_simplifier (after) 279 /// CHECK-DAG: <<Result:i\d+>> Compare 280 /// CHECK-DAG: Return [<<Result>>] 281 282 /// CHECK-START: int Main.compareCharShort(char, short) instruction_simplifier (after) 283 /// CHECK-NOT: InvokeStaticOrDirect 284 285 public static int compareCharShort(char x, short y) { 286 return Integer.compare(x, y); 287 } 288 289 /// CHECK-START: int Main.compareCharInt(char, int) intrinsics_recognition (after) 290 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 291 /// CHECK-DAG: Return [<<Result>>] 292 293 /// CHECK-START: int Main.compareCharInt(char, int) instruction_simplifier (after) 294 /// CHECK-DAG: <<Result:i\d+>> Compare 295 /// CHECK-DAG: Return [<<Result>>] 296 297 /// CHECK-START: int Main.compareCharInt(char, int) instruction_simplifier (after) 298 /// CHECK-NOT: InvokeStaticOrDirect 299 300 public static int compareCharInt(char x, int y) { 301 return Integer.compare(x, y); 302 } 303 304 305 /// CHECK-START: int Main.compareIntByte(int, byte) intrinsics_recognition (after) 306 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 307 /// CHECK-DAG: Return [<<Result>>] 308 309 /// CHECK-START: int Main.compareIntByte(int, byte) instruction_simplifier (after) 310 /// CHECK-DAG: <<Result:i\d+>> Compare 311 /// CHECK-DAG: Return [<<Result>>] 312 313 /// CHECK-START: int Main.compareIntByte(int, byte) instruction_simplifier (after) 314 /// CHECK-NOT: InvokeStaticOrDirect 315 316 public static int compareIntByte(int x, byte y) { 317 return Integer.compare(x, y); 318 } 319 320 /// CHECK-START: int Main.compareIntShort(int, short) intrinsics_recognition (after) 321 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 322 /// CHECK-DAG: Return [<<Result>>] 323 324 /// CHECK-START: int Main.compareIntShort(int, short) instruction_simplifier (after) 325 /// CHECK-DAG: <<Result:i\d+>> Compare 326 /// CHECK-DAG: Return [<<Result>>] 327 328 /// CHECK-START: int Main.compareIntShort(int, short) instruction_simplifier (after) 329 /// CHECK-NOT: InvokeStaticOrDirect 330 331 public static int compareIntShort(int x, short y) { 332 return Integer.compare(x, y); 333 } 334 335 /// CHECK-START: int Main.compareIntChar(int, char) intrinsics_recognition (after) 336 /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare 337 /// CHECK-DAG: Return [<<Result>>] 338 339 /// CHECK-START: int Main.compareIntChar(int, char) instruction_simplifier (after) 340 /// CHECK-DAG: <<Result:i\d+>> Compare 341 /// CHECK-DAG: Return [<<Result>>] 342 343 /// CHECK-START: int Main.compareIntChar(int, char) instruction_simplifier (after) 344 /// CHECK-NOT: InvokeStaticOrDirect 345 346 public static int compareIntChar(int x, char y) { 347 return Integer.compare(x, y); 348 } 349 350 351 public static void testCompareBooleans() { 352 expectEquals(-1, compareBooleans(false, true)); 353 354 expectEquals(0, compareBooleans(false, false)); 355 expectEquals(0, compareBooleans(true, true)); 356 357 expectEquals(1, compareBooleans(true, false)); 358 } 359 360 public static void testCompareBytes() { 361 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1))); 362 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)-1)); 363 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)0)); 364 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)1)); 365 expectEquals(-1, compareBytes(Byte.MIN_VALUE, Byte.MAX_VALUE)); 366 expectEquals(-1, compareBytes((byte)-1, (byte)0)); 367 expectEquals(-1, compareBytes((byte)-1, (byte)1)); 368 expectEquals(-1, compareBytes((byte)0, (byte)1)); 369 370 expectEquals(0, compareBytes(Byte.MIN_VALUE, Byte.MIN_VALUE)); 371 expectEquals(0, compareBytes((byte)-1, (byte)-1)); 372 expectEquals(0, compareBytes((byte)0, (byte)0)); 373 expectEquals(0, compareBytes((byte)1, (byte)1)); 374 expectEquals(0, compareBytes(Byte.MAX_VALUE, Byte.MAX_VALUE)); 375 376 expectEquals(1, compareBytes((byte)0, (byte)-1)); 377 expectEquals(1, compareBytes((byte)1, (byte)-1)); 378 expectEquals(1, compareBytes((byte)1, (byte)0)); 379 expectEquals(1, compareBytes(Byte.MAX_VALUE, Byte.MIN_VALUE)); 380 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)-1)); 381 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)0)); 382 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)1)); 383 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1))); 384 385 for (byte i = -11; i <= 11; i++) { 386 for (byte j = -11; j <= 11; j++) { 387 int expected = 0; 388 if (i < j) expected = -1; 389 else if (i > j) expected = 1; 390 expectEquals(expected, compareBytes(i, j)); 391 } 392 } 393 } 394 395 public static void testCompareShorts() { 396 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)(Short.MIN_VALUE + 1))); 397 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)-1)); 398 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)0)); 399 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)1)); 400 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)Short.MAX_VALUE)); 401 expectEquals(-1, compareShorts((short)-1, (short)0)); 402 expectEquals(-1, compareShorts((short)-1, (short)1)); 403 expectEquals(-1, compareShorts((short)0, (short)1)); 404 405 expectEquals(0, compareShorts(Short.MIN_VALUE, Short.MIN_VALUE)); 406 expectEquals(0, compareShorts((short)-1, (short)-1)); 407 expectEquals(0, compareShorts((short)0, (short)0)); 408 expectEquals(0, compareShorts((short)1, (short)1)); 409 expectEquals(0, compareShorts(Short.MAX_VALUE, Short.MAX_VALUE)); 410 411 expectEquals(1, compareShorts((short)0, (short)-1)); 412 expectEquals(1, compareShorts((short)1, (short)-1)); 413 expectEquals(1, compareShorts((short)1, (short)0)); 414 expectEquals(1, compareShorts(Short.MAX_VALUE, Short.MIN_VALUE)); 415 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)-1)); 416 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)0)); 417 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)1)); 418 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)(Short.MAX_VALUE - 1))); 419 420 for (short i = -11; i <= 11; i++) { 421 for (short j = -11; j <= 11; j++) { 422 int expected = 0; 423 if (i < j) expected = -1; 424 else if (i > j) expected = 1; 425 expectEquals(expected, compareShorts(i, j)); 426 } 427 } 428 } 429 430 public static void testCompareChars() { 431 expectEquals(-1, compareChars((char)0, Character.MAX_VALUE)); 432 expectEquals(-1, compareChars((char)0, (char)1)); 433 434 expectEquals(0, compareChars((char)0, (char)0)); 435 expectEquals(0, compareChars((char)1, (char)1)); 436 expectEquals(0, compareChars(Character.MAX_VALUE, Character.MAX_VALUE)); 437 438 expectEquals(1, compareChars((char)1, (char)0)); 439 expectEquals(1, compareChars(Character.MAX_VALUE, (char)0)); 440 expectEquals(1, compareChars(Character.MAX_VALUE, (char)1)); 441 expectEquals(1, compareChars(Character.MAX_VALUE, (char)(Character.MAX_VALUE - 1))); 442 443 for (char i = 0; i <= 11; i++) { 444 for (char j = 0; j <= 11; j++) { 445 int expected = 0; 446 if (i < j) expected = -1; 447 else if (i > j) expected = 1; 448 expectEquals(expected, compareChars(i, j)); 449 } 450 } 451 } 452 453 public static void testCompareInts() { 454 expectEquals(-1, compareInts(Integer.MIN_VALUE, Integer.MIN_VALUE + 1)); 455 expectEquals(-1, compareInts(Integer.MIN_VALUE, -1)); 456 expectEquals(-1, compareInts(Integer.MIN_VALUE, 0)); 457 expectEquals(-1, compareInts(Integer.MIN_VALUE, 1)); 458 expectEquals(-1, compareInts(Integer.MIN_VALUE, Integer.MAX_VALUE)); 459 expectEquals(-1, compareInts(-1, 0)); 460 expectEquals(-1, compareInts(-1, 1)); 461 expectEquals(-1, compareInts(0, 1)); 462 463 expectEquals(0, compareInts(Integer.MIN_VALUE, Integer.MIN_VALUE)); 464 expectEquals(0, compareInts(-1, -1)); 465 expectEquals(0, compareInts(0, 0)); 466 expectEquals(0, compareInts(1, 1)); 467 expectEquals(0, compareInts(Integer.MAX_VALUE, Integer.MAX_VALUE)); 468 469 expectEquals(1, compareInts(0, -1)); 470 expectEquals(1, compareInts(1, -1)); 471 expectEquals(1, compareInts(1, 0)); 472 expectEquals(1, compareInts(Integer.MAX_VALUE, Integer.MIN_VALUE)); 473 expectEquals(1, compareInts(Integer.MAX_VALUE, -1)); 474 expectEquals(1, compareInts(Integer.MAX_VALUE, 0)); 475 expectEquals(1, compareInts(Integer.MAX_VALUE, 1)); 476 expectEquals(1, compareInts(Integer.MAX_VALUE, Integer.MAX_VALUE - 1)); 477 478 for (int i = -11; i <= 11; i++) { 479 for (int j = -11; j <= 11; j++) { 480 int expected = 0; 481 if (i < j) expected = -1; 482 else if (i > j) expected = 1; 483 expectEquals(expected, compareInts(i, j)); 484 } 485 } 486 } 487 488 public static void testCompareLongs() { 489 expectEquals(-1, compareLongs(Long.MIN_VALUE, Long.MIN_VALUE + 1L)); 490 expectEquals(-1, compareLongs(Long.MIN_VALUE, -1L)); 491 expectEquals(-1, compareLongs(Long.MIN_VALUE, 0L)); 492 expectEquals(-1, compareLongs(Long.MIN_VALUE, 1L)); 493 expectEquals(-1, compareLongs(Long.MIN_VALUE, Long.MAX_VALUE)); 494 expectEquals(-1, compareLongs(-1L, 0L)); 495 expectEquals(-1, compareLongs(-1L, 1L)); 496 expectEquals(-1, compareLongs(0L, 1L)); 497 498 expectEquals(0, compareLongs(Long.MIN_VALUE, Long.MIN_VALUE)); 499 expectEquals(0, compareLongs(-1L, -1L)); 500 expectEquals(0, compareLongs(0L, 0L)); 501 expectEquals(0, compareLongs(1L, 1L)); 502 expectEquals(0, compareLongs(Long.MAX_VALUE, Long.MAX_VALUE)); 503 504 expectEquals(1, compareLongs(0L, -1L)); 505 expectEquals(1, compareLongs(1L, -1L)); 506 expectEquals(1, compareLongs(1L, 0L)); 507 expectEquals(1, compareLongs(Long.MAX_VALUE, Long.MIN_VALUE)); 508 expectEquals(1, compareLongs(Long.MAX_VALUE, -1L)); 509 expectEquals(1, compareLongs(Long.MAX_VALUE, 0L)); 510 expectEquals(1, compareLongs(Long.MAX_VALUE, 1L)); 511 expectEquals(1, compareLongs(Long.MAX_VALUE, Long.MAX_VALUE - 1L)); 512 513 expectEquals(-1, compareLongs(0x111111117FFFFFFFL, 0x11111111FFFFFFFFL)); 514 expectEquals(0, compareLongs(0x111111117FFFFFFFL, 0x111111117FFFFFFFL)); 515 expectEquals(1, compareLongs(0x11111111FFFFFFFFL, 0x111111117FFFFFFFL)); 516 517 for (long i = -11L; i <= 11L; i++) { 518 for (long j = -11L; j <= 11L; j++) { 519 int expected = 0; 520 if (i < j) expected = -1; 521 else if (i > j) expected = 1; 522 expectEquals(expected, compareLongs(i, j)); 523 } 524 } 525 526 for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 11L; i++) { 527 expectEquals(-1, compareLongs(i, 0)); 528 } 529 530 for (long i = Long.MAX_VALUE; i >= Long.MAX_VALUE - 11L; i--) { 531 expectEquals(1, compareLongs(i, 0)); 532 } 533 } 534 535 536 public static void testCompareByteShort() { 537 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)-1)); 538 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)0)); 539 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)1)); 540 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, Short.MAX_VALUE)); 541 expectEquals(-1, compareByteShort((byte)-1, (short)0)); 542 expectEquals(-1, compareByteShort((byte)-1, (short)1)); 543 expectEquals(-1, compareByteShort((byte)0, (short)1)); 544 expectEquals(-1, compareByteShort(Byte.MAX_VALUE, (short)(Short.MAX_VALUE - 1))); 545 expectEquals(-1, compareByteShort(Byte.MAX_VALUE, Short.MAX_VALUE)); 546 547 expectEquals(0, compareByteShort((byte)-1, (short)-1)); 548 expectEquals(0, compareByteShort((byte)0, (short)0)); 549 expectEquals(0, compareByteShort((byte)1, (short)1)); 550 551 expectEquals(1, compareByteShort(Byte.MIN_VALUE, Short.MIN_VALUE)); 552 expectEquals(1, compareByteShort(Byte.MIN_VALUE, (short)(Short.MIN_VALUE + 1))); 553 expectEquals(1, compareByteShort((byte)0, (short)-1)); 554 expectEquals(1, compareByteShort((byte)1, (short)-1)); 555 expectEquals(1, compareByteShort((byte)1, (short)0)); 556 expectEquals(1, compareByteShort(Byte.MAX_VALUE, Short.MIN_VALUE)); 557 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)-1)); 558 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)0)); 559 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)1)); 560 561 for (byte i = -11; i <= 11; i++) { 562 for (short j = -11; j <= 11; j++) { 563 int expected = 0; 564 if (i < j) expected = -1; 565 else if (i > j) expected = 1; 566 expectEquals(expected, compareByteShort(i, j)); 567 } 568 } 569 } 570 571 public static void testCompareByteChar() { 572 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, (char)0)); 573 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, (char)1)); 574 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, Character.MAX_VALUE)); 575 expectEquals(-1, compareByteChar((byte)-1, (char)0)); 576 expectEquals(-1, compareByteChar((byte)-1, (char)1)); 577 expectEquals(-1, compareByteChar((byte)0, (char)1)); 578 expectEquals(-1, compareByteChar(Byte.MAX_VALUE, (char)(Character.MAX_VALUE - 1))); 579 expectEquals(-1, compareByteChar(Byte.MAX_VALUE, Character.MAX_VALUE)); 580 581 expectEquals(0, compareByteChar((byte)0, (char)0)); 582 expectEquals(0, compareByteChar((byte)1, (char)1)); 583 584 expectEquals(1, compareByteChar((byte)1, (char)0)); 585 expectEquals(1, compareByteChar(Byte.MAX_VALUE, (char)0)); 586 expectEquals(1, compareByteChar(Byte.MAX_VALUE, (char)1)); 587 588 for (byte i = -11; i <= 11; i++) { 589 for (char j = 0; j <= 11; j++) { 590 int expected = 0; 591 if (i < j) expected = -1; 592 else if (i > j) expected = 1; 593 expectEquals(expected, compareByteChar(i, j)); 594 } 595 } 596 } 597 598 public static void testCompareByteInt() { 599 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, -1)); 600 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, 0)); 601 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, 1)); 602 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, Integer.MAX_VALUE)); 603 expectEquals(-1, compareByteInt((byte)-1, 0)); 604 expectEquals(-1, compareByteInt((byte)-1, 1)); 605 expectEquals(-1, compareByteInt((byte)0, 1)); 606 expectEquals(-1, compareByteInt(Byte.MAX_VALUE, Integer.MAX_VALUE - 1)); 607 expectEquals(-1, compareByteInt(Byte.MAX_VALUE, Integer.MAX_VALUE)); 608 609 expectEquals(0, compareByteInt((byte)-1, -1)); 610 expectEquals(0, compareByteInt((byte)0, 0)); 611 expectEquals(0, compareByteInt((byte)1, 1)); 612 613 expectEquals(1, compareByteInt(Byte.MIN_VALUE, Integer.MIN_VALUE)); 614 expectEquals(1, compareByteInt(Byte.MIN_VALUE, Integer.MIN_VALUE + 1)); 615 expectEquals(1, compareByteInt((byte)0, -1)); 616 expectEquals(1, compareByteInt((byte)1, -1)); 617 expectEquals(1, compareByteInt((byte)1, 0)); 618 expectEquals(1, compareByteInt(Byte.MAX_VALUE, Integer.MIN_VALUE)); 619 expectEquals(1, compareByteInt(Byte.MAX_VALUE, -1)); 620 expectEquals(1, compareByteInt(Byte.MAX_VALUE, 0)); 621 expectEquals(1, compareByteInt(Byte.MAX_VALUE, 1)); 622 623 for (byte i = -11; i <= 11; i++) { 624 for (int j = -11; j <= 11; j++) { 625 int expected = 0; 626 if (i < j) expected = -1; 627 else if (i > j) expected = 1; 628 expectEquals(expected, compareByteInt(i, j)); 629 } 630 } 631 } 632 633 634 public static void testCompareShortByte() { 635 expectEquals(-1, compareShortByte(Short.MIN_VALUE, Byte.MIN_VALUE)); 636 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1))); 637 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)-1)); 638 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)0)); 639 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)1)); 640 expectEquals(-1, compareShortByte(Short.MIN_VALUE, Byte.MAX_VALUE)); 641 expectEquals(-1, compareShortByte((short)-1, (byte)0)); 642 expectEquals(-1, compareShortByte((short)-1, (byte)1)); 643 expectEquals(-1, compareShortByte((short)0, (byte)1)); 644 645 expectEquals(0, compareShortByte((short)-1, (byte)-1)); 646 expectEquals(0, compareShortByte((short)0, (byte)0)); 647 expectEquals(0, compareShortByte((short)1, (byte)1)); 648 649 expectEquals(1, compareShortByte((short)0, (byte)-1)); 650 expectEquals(1, compareShortByte((short)1, (byte)-1)); 651 expectEquals(1, compareShortByte((short)1, (byte)0)); 652 expectEquals(1, compareShortByte(Short.MAX_VALUE, Byte.MIN_VALUE)); 653 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)-1)); 654 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)0)); 655 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)1)); 656 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1))); 657 expectEquals(1, compareShortByte(Short.MAX_VALUE, Byte.MAX_VALUE)); 658 659 for (short i = -11; i <= 11; i++) { 660 for (byte j = -11; j <= 11; j++) { 661 int expected = 0; 662 if (i < j) expected = -1; 663 else if (i > j) expected = 1; 664 expectEquals(expected, compareShortByte(i, j)); 665 } 666 } 667 } 668 669 public static void testCompareShortChar() { 670 expectEquals(-1, compareShortChar(Short.MIN_VALUE, (char)0)); 671 expectEquals(-1, compareShortChar(Short.MIN_VALUE, (char)1)); 672 expectEquals(-1, compareShortChar(Short.MIN_VALUE, Character.MAX_VALUE)); 673 expectEquals(-1, compareShortChar((short)-1, (char)0)); 674 expectEquals(-1, compareShortChar((short)-1, (char)1)); 675 expectEquals(-1, compareShortChar((short)0, (char)1)); 676 expectEquals(-1, compareShortChar(Short.MAX_VALUE, (char)(Character.MAX_VALUE - 1))); 677 expectEquals(-1, compareShortChar(Short.MAX_VALUE, Character.MAX_VALUE)); 678 679 expectEquals(0, compareShortChar((short)0, (char)0)); 680 expectEquals(0, compareShortChar((short)1, (char)1)); 681 682 expectEquals(1, compareShortChar((short)1, (char)0)); 683 expectEquals(1, compareShortChar(Short.MAX_VALUE, (char)0)); 684 expectEquals(1, compareShortChar(Short.MAX_VALUE, (char)1)); 685 686 for (short i = -11; i <= 11; i++) { 687 for (char j = 0; j <= 11; j++) { 688 int expected = 0; 689 if (i < j) expected = -1; 690 else if (i > j) expected = 1; 691 expectEquals(expected, compareShortChar(i, j)); 692 } 693 } 694 } 695 696 public static void testCompareShortInt() { 697 expectEquals(-1, compareShortInt(Short.MIN_VALUE, -1)); 698 expectEquals(-1, compareShortInt(Short.MIN_VALUE, 0)); 699 expectEquals(-1, compareShortInt(Short.MIN_VALUE, 1)); 700 expectEquals(-1, compareShortInt(Short.MIN_VALUE, Integer.MAX_VALUE)); 701 expectEquals(-1, compareShortInt((short)-1, 0)); 702 expectEquals(-1, compareShortInt((short)-1, 1)); 703 expectEquals(-1, compareShortInt((short)0, 1)); 704 expectEquals(-1, compareShortInt(Short.MAX_VALUE, Integer.MAX_VALUE - 1)); 705 expectEquals(-1, compareShortInt(Short.MAX_VALUE, Integer.MAX_VALUE)); 706 707 expectEquals(0, compareShortInt((short)-1, -1)); 708 expectEquals(0, compareShortInt((short)0, 0)); 709 expectEquals(0, compareShortInt((short)1, 1)); 710 711 expectEquals(1, compareShortInt(Short.MIN_VALUE, Integer.MIN_VALUE)); 712 expectEquals(1, compareShortInt(Short.MIN_VALUE, Integer.MIN_VALUE + 1)); 713 expectEquals(1, compareShortInt((short)0, -1)); 714 expectEquals(1, compareShortInt((short)1, -1)); 715 expectEquals(1, compareShortInt((short)1, 0)); 716 expectEquals(1, compareShortInt(Short.MAX_VALUE, Integer.MIN_VALUE)); 717 expectEquals(1, compareShortInt(Short.MAX_VALUE, -1)); 718 expectEquals(1, compareShortInt(Short.MAX_VALUE, 0)); 719 expectEquals(1, compareShortInt(Short.MAX_VALUE, 1)); 720 721 for (short i = -11; i <= 11; i++) { 722 for (int j = -11; j <= 11; j++) { 723 int expected = 0; 724 if (i < j) expected = -1; 725 else if (i > j) expected = 1; 726 expectEquals(expected, compareShortInt(i, j)); 727 } 728 } 729 } 730 731 732 public static void testCompareCharByte() { 733 expectEquals(-1, compareCharByte((char)0, (byte)1)); 734 expectEquals(-1, compareCharByte((char)0, Byte.MAX_VALUE)); 735 736 expectEquals(0, compareCharByte((char)0, (byte)0)); 737 expectEquals(0, compareCharByte((char)1, (byte)1)); 738 739 expectEquals(1, compareCharByte((char)0, Byte.MIN_VALUE)); 740 expectEquals(1, compareCharByte((char)0, (byte)(Byte.MIN_VALUE + 1))); 741 expectEquals(1, compareCharByte((char)0, (byte)-1)); 742 expectEquals(1, compareCharByte((char)1, (byte)-1)); 743 expectEquals(1, compareCharByte((char)1, (byte)0)); 744 expectEquals(1, compareCharByte(Character.MAX_VALUE, Byte.MIN_VALUE)); 745 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)-1)); 746 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)0)); 747 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)1)); 748 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1))); 749 expectEquals(1, compareCharByte(Character.MAX_VALUE, Byte.MAX_VALUE)); 750 751 for (char i = 0; i <= 11; i++) { 752 for (byte j = -11; j <= 11; j++) { 753 int expected = 0; 754 if (i < j) expected = -1; 755 else if (i > j) expected = 1; 756 expectEquals(expected, compareCharByte(i, j)); 757 } 758 } 759 } 760 761 public static void testCompareCharShort() { 762 expectEquals(-1, compareCharShort((char)0, (short)1)); 763 expectEquals(-1, compareCharShort((char)0, Short.MAX_VALUE)); 764 765 expectEquals(0, compareCharShort((char)0, (short)0)); 766 expectEquals(0, compareCharShort((char)1, (short)1)); 767 768 expectEquals(1, compareCharShort((char)0, Short.MIN_VALUE)); 769 expectEquals(1, compareCharShort((char)0, (short)(Short.MIN_VALUE + 1))); 770 expectEquals(1, compareCharShort((char)0, (short)-1)); 771 expectEquals(1, compareCharShort((char)1, (short)-1)); 772 expectEquals(1, compareCharShort((char)1, (short)0)); 773 expectEquals(1, compareCharShort(Character.MAX_VALUE, Short.MIN_VALUE)); 774 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)-1)); 775 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)0)); 776 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)1)); 777 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)(Short.MAX_VALUE - 1))); 778 expectEquals(1, compareCharShort(Character.MAX_VALUE, Short.MAX_VALUE)); 779 780 for (char i = 0; i <= 11; i++) { 781 for (short j = -11; j <= 11; j++) { 782 int expected = 0; 783 if (i < j) expected = -1; 784 else if (i > j) expected = 1; 785 expectEquals(expected, compareCharShort(i, j)); 786 } 787 } 788 } 789 790 public static void testCompareCharInt() { 791 expectEquals(-1, compareCharInt((char)0, 1)); 792 expectEquals(-1, compareCharInt((char)0, Integer.MAX_VALUE)); 793 expectEquals(-1, compareCharInt(Character.MAX_VALUE, Integer.MAX_VALUE - 1)); 794 expectEquals(-1, compareCharInt(Character.MAX_VALUE, Integer.MAX_VALUE)); 795 796 expectEquals(0, compareCharInt((char)0, 0)); 797 expectEquals(0, compareCharInt((char)1, 1)); 798 799 expectEquals(1, compareCharInt((char)0, Integer.MIN_VALUE)); 800 expectEquals(1, compareCharInt((char)0, Integer.MIN_VALUE + 1)); 801 expectEquals(1, compareCharInt((char)0, -1)); 802 expectEquals(1, compareCharInt((char)1, -1)); 803 expectEquals(1, compareCharInt((char)1, 0)); 804 expectEquals(1, compareCharInt(Character.MAX_VALUE, Integer.MIN_VALUE)); 805 expectEquals(1, compareCharInt(Character.MAX_VALUE, -1)); 806 expectEquals(1, compareCharInt(Character.MAX_VALUE, 0)); 807 expectEquals(1, compareCharInt(Character.MAX_VALUE, 1)); 808 809 for (char i = 0; i <= 11; i++) { 810 for (int j = -11; j <= 11; j++) { 811 int expected = 0; 812 if (i < j) expected = -1; 813 else if (i > j) expected = 1; 814 expectEquals(expected, compareCharInt(i, j)); 815 } 816 } 817 } 818 819 820 public static void testCompareIntByte() { 821 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, Byte.MIN_VALUE)); 822 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1))); 823 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)-1)); 824 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)0)); 825 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)1)); 826 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, Byte.MAX_VALUE)); 827 expectEquals(-1, compareIntByte(-1, (byte)0)); 828 expectEquals(-1, compareIntByte(-1, (byte)1)); 829 expectEquals(-1, compareIntByte(0, (byte)1)); 830 831 expectEquals(0, compareIntByte(-1, (byte)-1)); 832 expectEquals(0, compareIntByte(0, (byte)0)); 833 expectEquals(0, compareIntByte(1, (byte)1)); 834 835 expectEquals(1, compareIntByte(0, (byte)-1)); 836 expectEquals(1, compareIntByte(1, (byte)-1)); 837 expectEquals(1, compareIntByte(1, (byte)0)); 838 expectEquals(1, compareIntByte(Integer.MAX_VALUE, Byte.MIN_VALUE)); 839 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)-1)); 840 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)0)); 841 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)1)); 842 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1))); 843 expectEquals(1, compareIntByte(Integer.MAX_VALUE, Byte.MAX_VALUE)); 844 845 for (int i = -11; i <= 11; i++) { 846 for (byte j = -11; j <= 11; j++) { 847 int expected = 0; 848 if (i < j) expected = -1; 849 else if (i > j) expected = 1; 850 expectEquals(expected, compareIntByte(i, j)); 851 } 852 } 853 } 854 855 public static void testCompareIntShort() { 856 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, Short.MIN_VALUE)); 857 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)(Short.MIN_VALUE + 1))); 858 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)-1)); 859 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)0)); 860 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)1)); 861 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, Short.MAX_VALUE)); 862 expectEquals(-1, compareIntShort(-1, (short)0)); 863 expectEquals(-1, compareIntShort(-1, (short)1)); 864 expectEquals(-1, compareIntShort(0, (short)1)); 865 866 expectEquals(0, compareIntShort(-1, (short)-1)); 867 expectEquals(0, compareIntShort(0, (short)0)); 868 expectEquals(0, compareIntShort(1, (short)1)); 869 870 expectEquals(1, compareIntShort(0, (short)-1)); 871 expectEquals(1, compareIntShort(1, (short)-1)); 872 expectEquals(1, compareIntShort(1, (short)0)); 873 expectEquals(1, compareIntShort(Integer.MAX_VALUE, Short.MIN_VALUE)); 874 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)-1)); 875 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)0)); 876 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)1)); 877 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)(Short.MAX_VALUE - 1))); 878 expectEquals(1, compareIntShort(Integer.MAX_VALUE, Short.MAX_VALUE)); 879 880 for (int i = -11; i <= 11; i++) { 881 for (short j = -11; j <= 11; j++) { 882 int expected = 0; 883 if (i < j) expected = -1; 884 else if (i > j) expected = 1; 885 expectEquals(expected, compareIntShort(i, j)); 886 } 887 } 888 } 889 890 public static void testCompareIntChar() { 891 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, (char)0)); 892 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, (char)1)); 893 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, Character.MAX_VALUE)); 894 expectEquals(-1, compareIntChar(-1, (char)0)); 895 expectEquals(-1, compareIntChar(-1, (char)1)); 896 expectEquals(-1, compareIntChar(0, (char)1)); 897 898 expectEquals(0, compareIntChar(0, (char)0)); 899 expectEquals(0, compareIntChar(1, (char)1)); 900 901 expectEquals(1, compareIntChar(1, (char)0)); 902 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)0)); 903 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)1)); 904 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)(Character.MAX_VALUE - 1))); 905 expectEquals(1, compareIntChar(Integer.MAX_VALUE, Character.MAX_VALUE)); 906 907 for (int i = -11; i <= 11; i++) { 908 for (char j = 0; j <= 11; j++) { 909 int expected = 0; 910 if (i < j) expected = -1; 911 else if (i > j) expected = 1; 912 expectEquals(expected, compareIntChar(i, j)); 913 } 914 } 915 } 916 917 918 public static void main(String args[]) { 919 $opt$noinline$testReplaceInputWithItself(42); 920 921 testCompareBooleans(); 922 testCompareBytes(); 923 testCompareShorts(); 924 testCompareChars(); 925 testCompareInts(); 926 testCompareLongs(); 927 928 testCompareByteShort(); 929 testCompareByteChar(); 930 testCompareByteInt(); 931 932 testCompareShortByte(); 933 testCompareShortChar(); 934 testCompareShortInt(); 935 936 testCompareCharByte(); 937 testCompareCharShort(); 938 testCompareCharInt(); 939 940 testCompareIntByte(); 941 testCompareIntShort(); 942 testCompareIntChar(); 943 944 System.out.println("passed"); 945 } 946 947 private static void expectEquals(int expected, int result) { 948 if (expected != result) { 949 throw new Error("Expected: " + expected + ", found: " + result); 950 } 951 } 952 } 953