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 {
assertEquals(int expected, int actual)18   public static void assertEquals(int expected, int actual) {
19     if (expected != actual) {
20       throw new Error("Expected " + expected + ", got " + actual);
21     }
22   }
23 
assertEquals(long expected, long actual)24   public static void assertEquals(long expected, long actual) {
25     if (expected != actual) {
26       throw new Error("Expected " + expected + ", got " + actual);
27     }
28   }
29 
main(String[] args)30   public static void main(String[] args) {
31     assertEquals(0, $noinline$divInt(1));
32     assertEquals(1, $noinline$remInt(1));
33 
34     assertEquals(0, $noinline$divInt(-1));
35     assertEquals(-1, $noinline$remInt(-1));
36 
37     assertEquals(0, $noinline$divInt(0));
38     assertEquals(0, $noinline$remInt(0));
39 
40     assertEquals(1, $noinline$divInt(Integer.MIN_VALUE));
41     assertEquals(0, $noinline$remInt(Integer.MIN_VALUE));
42 
43     assertEquals(0, $noinline$divInt(Integer.MAX_VALUE));
44     assertEquals(Integer.MAX_VALUE, $noinline$remInt(Integer.MAX_VALUE));
45 
46     assertEquals(0, $noinline$divInt(Integer.MAX_VALUE - 1));
47     assertEquals(Integer.MAX_VALUE - 1, $noinline$remInt(Integer.MAX_VALUE - 1));
48 
49     assertEquals(0, $noinline$divInt(Integer.MIN_VALUE + 1));
50     assertEquals(Integer.MIN_VALUE + 1, $noinline$remInt(Integer.MIN_VALUE + 1));
51 
52     assertEquals(0L, $noinline$divLong(1L));
53     assertEquals(1L, $noinline$remLong(1L));
54 
55     assertEquals(0L, $noinline$divLong(-1L));
56     assertEquals(-1L, $noinline$remLong(-1L));
57 
58     assertEquals(0L, $noinline$divLong(0L));
59     assertEquals(0L, $noinline$remLong(0L));
60 
61     assertEquals(1L, $noinline$divLong(Long.MIN_VALUE));
62     assertEquals(0L, $noinline$remLong(Long.MIN_VALUE));
63 
64     assertEquals(0L, $noinline$divLong(Long.MAX_VALUE));
65     assertEquals(Long.MAX_VALUE, $noinline$remLong(Long.MAX_VALUE));
66 
67     assertEquals(0L, $noinline$divLong(Long.MAX_VALUE - 1));
68     assertEquals(Long.MAX_VALUE - 1, $noinline$remLong(Long.MAX_VALUE - 1));
69 
70     assertEquals(0L, $noinline$divLong(Integer.MIN_VALUE + 1));
71     assertEquals(Long.MIN_VALUE + 1, $noinline$remLong(Long.MIN_VALUE + 1));
72   }
73 
$noinline$divInt(int value)74   public static int $noinline$divInt(int value) {
75     if (doThrow) {
76       throw new Error("");
77     }
78     return value / Integer.MIN_VALUE;
79   }
80 
$noinline$remInt(int value)81   public static int $noinline$remInt(int value) {
82     if (doThrow) {
83       throw new Error("");
84     }
85     return value % Integer.MIN_VALUE;
86   }
87 
$noinline$divLong(long value)88   public static long $noinline$divLong(long value) {
89     if (doThrow) {
90       throw new Error("");
91     }
92     return value / Long.MIN_VALUE;
93   }
94 
$noinline$remLong(long value)95   public static long $noinline$remLong(long value) {
96     if (doThrow) {
97       throw new Error("");
98     }
99     return value % Long.MIN_VALUE;
100   }
101 
102   static boolean doThrow = false;
103 }
104