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