Mercurial > hg > truffle
annotate test/compiler/intrinsics/mathexact/Verify.java @ 13971:3e5b9a4d5986
added Array.getLength substitution
author | twisti |
---|---|
date | Tue, 18 Feb 2014 13:21:11 -0800 |
parents | 59e8ad757e19 |
children | cd5d10655495 |
rev | line source |
---|---|
12323 | 1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 public class Verify { | |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
25 public static String throwWord(boolean threw) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
26 return (threw ? "threw" : "didn't throw"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
27 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
28 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
29 public static void verifyResult(UnaryMethod method, int result1, int result2, boolean exception1, boolean exception2, int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
30 if (exception1 != exception2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
31 throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version" + throwWord(exception2) + " for: " + value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
32 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
33 if (result1 != result2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
34 throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
35 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
36 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
37 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
38 public static void verifyResult(UnaryLongMethod method, long result1, long result2, boolean exception1, boolean exception2, long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
39 if (exception1 != exception2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
40 throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version" + throwWord(exception2) + " for: " + value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
41 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
42 if (result1 != result2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
43 throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
44 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
45 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
46 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
47 private static void verifyResult(BinaryMethod method, int result1, int result2, boolean exception1, boolean exception2, int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
48 if (exception1 != exception2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
49 throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
50 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
51 if (result1 != result2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
52 throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
53 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
54 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
55 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
56 private static void verifyResult(BinaryLongMethod method, long result1, long result2, boolean exception1, boolean exception2, long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
57 if (exception1 != exception2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
58 throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
59 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
60 if (result1 != result2) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
61 throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
62 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
63 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
64 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
65 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
66 public static void verifyUnary(int a, UnaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
67 boolean exception1 = false, exception2 = false; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
68 int result1 = 0, result2 = 0; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
69 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
70 result1 = method.checkMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
71 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
72 exception1 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
73 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
74 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
75 result2 = method.safeMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
76 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
77 exception2 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
78 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
79 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
80 verifyResult(method, result1, result2, exception1, exception2, a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
81 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
82 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
83 public static void verifyUnary(long a, UnaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
84 boolean exception1 = false, exception2 = false; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
85 long result1 = 0, result2 = 0; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
86 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
87 result1 = method.checkMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
88 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
89 exception1 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
90 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
91 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
92 result2 = method.safeMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
93 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
94 exception2 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
95 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
96 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
97 verifyResult(method, result1, result2, exception1, exception2, a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
98 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
99 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
100 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
101 public static void verifyBinary(int a, int b, BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
102 boolean exception1 = false, exception2 = false; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
103 int result1 = 0, result2 = 0; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
104 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
105 result1 = method.checkMethod(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
106 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
107 exception1 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
108 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
109 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
110 result2 = method.safeMethod(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
111 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
112 exception2 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
113 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
114 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
115 verifyResult(method, result1, result2, exception1, exception2, a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
116 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
117 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
118 public static void verifyBinary(long a, long b, BinaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
119 boolean exception1 = false, exception2 = false; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
120 long result1 = 0, result2 = 0; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
121 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
122 result1 = method.checkMethod(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
123 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
124 exception1 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
125 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
126 try { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
127 result2 = method.safeMethod(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
128 } catch (ArithmeticException e) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
129 exception2 = true; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
130 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
131 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
132 verifyResult(method, result1, result2, exception1, exception2, a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
133 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
134 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
135 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
136 public static class LoadTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
137 public static java.util.Random rnd = new java.util.Random(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
138 public static int[] values = new int[256]; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
139 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
140 public static void init() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
141 for (int i = 0; i < values.length; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
142 values[i] = rnd.nextInt(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
143 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
144 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
145 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
146 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
147 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
148 Verify.verifyBinary(values[i & 255], values[i & 255] - i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
149 Verify.verifyBinary(values[i & 255] + i, values[i & 255] - i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
150 Verify.verifyBinary(values[i & 255], values[i & 255], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
151 if ((i & 1) == 1 && i > 5) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
152 Verify.verifyBinary(values[i & 255] + i, values[i & 255] - i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
153 } else { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
154 Verify.verifyBinary(values[i & 255] - i, values[i & 255] + i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
155 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
156 Verify.verifyBinary(values[i & 255], values[(i + 1) & 255], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
157 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
158 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
159 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
160 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
161 public static class NonConstantTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
162 public static java.util.Random rnd = new java.util.Random(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
163 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
164 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
165 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
166 int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
167 Verify.verifyBinary(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
168 Verify.verifyBinary(rnd1, rnd2 + 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
169 Verify.verifyBinary(rnd1 + 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
170 Verify.verifyBinary(rnd1 - 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
171 Verify.verifyBinary(rnd1, rnd2 - 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
172 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
173 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
174 } |
12323 | 175 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
176 public static class NonConstantLongTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
177 public static long[] values = { Long.MIN_VALUE, Long.MAX_VALUE, 0, Long.MAX_VALUE - 1831 }; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
178 public static java.util.Random rnd = new java.util.Random(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
179 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
180 public static void verify(BinaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
181 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
182 long rnd1 = rnd.nextLong(), rnd2 = rnd.nextLong(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
183 Verify.verifyBinary(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
184 Verify.verifyBinary(rnd1, rnd2 + 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
185 Verify.verifyBinary(rnd1 + 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
186 Verify.verifyBinary(rnd1 - 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
187 Verify.verifyBinary(rnd1, rnd2 - 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
188 Verify.verifyBinary(rnd1 + Long.MAX_VALUE - rnd2, rnd2 + 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
189 Verify.verifyBinary(values[0], values[2], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
190 Verify.verifyBinary(values[1], values[2], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
191 Verify.verifyBinary(values[3], 74L, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
192 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
193 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
194 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
195 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
196 public static class LoopDependentTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
197 public static java.util.Random rnd = new java.util.Random(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
198 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
199 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
200 int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
201 runTest(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
202 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
203 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
204 private static void runTest(int rnd1, int rnd2, BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
205 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
206 Verify.verifyBinary(rnd1 + i, rnd2 + i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
207 Verify.verifyBinary(rnd1 + i, rnd2 + (i & 0xff), method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
208 Verify.verifyBinary(rnd1 - i, rnd2 - (i & 0xff), method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
209 Verify.verifyBinary(rnd1 + i + 1, rnd2 + i + 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
210 Verify.verifyBinary(rnd1 + i * 2, rnd2 + i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
211 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
212 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
213 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
214 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
215 public static class ConstantTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
216 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
217 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
218 Verify.verifyBinary(5, 7, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
219 Verify.verifyBinary(Integer.MAX_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
220 Verify.verifyBinary(Integer.MIN_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
221 Verify.verifyBinary(Integer.MAX_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
222 Verify.verifyBinary(Integer.MIN_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
223 Verify.verifyBinary(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
224 Verify.verifyBinary(Integer.MAX_VALUE / 2, (Integer.MAX_VALUE / 2) + 3, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
225 Verify.verifyBinary(Integer.MAX_VALUE, Integer.MIN_VALUE, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
226 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
227 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
228 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
229 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
230 public static class ConstantLongTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
231 public static void verify(BinaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
232 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
233 Verify.verifyBinary(5, 7, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
234 Verify.verifyBinary(Long.MAX_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
235 Verify.verifyBinary(Long.MIN_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
236 Verify.verifyBinary(Long.MAX_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
237 Verify.verifyBinary(Long.MIN_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
238 Verify.verifyBinary(Long.MAX_VALUE / 2, Long.MAX_VALUE / 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
239 Verify.verifyBinary(Long.MAX_VALUE / 2, (Long.MAX_VALUE / 2) + 3, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
240 Verify.verifyBinary(Long.MAX_VALUE, Long.MIN_VALUE, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
241 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
242 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
243 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
244 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
245 public static interface BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
246 int safeMethod(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
247 int checkMethod(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
248 int unchecked(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
249 String name(); |
12323 | 250 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
251 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
252 public static interface UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
253 int safeMethod(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
254 int checkMethod(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
255 int unchecked(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
256 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
257 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
258 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
259 public static interface BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
260 long safeMethod(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
261 long checkMethod(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
262 long unchecked(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
263 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
264 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
265 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
266 public static interface UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
267 long safeMethod(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
268 long checkMethod(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
269 long unchecked(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
270 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
271 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
272 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
273 public static class UnaryToBinary implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
274 private final UnaryMethod method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
275 public UnaryToBinary(UnaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
276 this.method = method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
277 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
278 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
279 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
280 public int safeMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
281 return method.safeMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
282 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
283 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
284 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
285 public int checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
286 return method.checkMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
287 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
288 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
289 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
290 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
291 return method.unchecked(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
292 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
293 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
294 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
295 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
296 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
297 return method.name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
298 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
299 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
300 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
301 public static class UnaryToBinaryLong implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
302 private final UnaryLongMethod method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
303 public UnaryToBinaryLong(UnaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
304 this.method = method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
305 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
306 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
307 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
308 public long safeMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
309 return method.safeMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
310 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
311 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
312 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
313 public long checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
314 return method.checkMethod(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
315 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
316 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
317 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
318 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
319 return method.unchecked(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
320 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
321 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
322 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
323 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
324 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
325 return method.name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
326 } |
12323 | 327 } |
328 | |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
329 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
330 public static class AddExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
331 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
332 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
333 int r = x + y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
334 // HD 2-12 Overflow iff both arguments have the opposite sign of the result |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
335 if (((x ^ r) & (y ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
336 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
337 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
338 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
339 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
340 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
341 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
342 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
343 public int checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
344 return Math.addExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
345 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
346 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
347 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
348 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
349 return "addExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
350 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
351 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
352 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
353 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
354 return a + b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
355 } |
12323 | 356 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
357 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
358 public static class AddExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
359 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
360 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
361 long r = x + y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
362 // HD 2-12 Overflow iff both arguments have the opposite sign of the result |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
363 if (((x ^ r) & (y ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
364 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
365 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
366 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
367 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
368 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
369 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
370 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
371 public long checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
372 return Math.addExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
373 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
374 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
375 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
376 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
377 return "addExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
378 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
379 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
380 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
381 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
382 return a + b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
383 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
384 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
385 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
386 public static class MulExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
387 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
388 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
389 long r = (long)x * (long)y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
390 if ((int)r != r) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
391 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
392 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
393 return (int)r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
394 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
395 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
396 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
397 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
398 public int checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
399 return Math.multiplyExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
400 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
401 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
402 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
403 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
404 return a * b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
405 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
406 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
407 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
408 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
409 return "multiplyExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
410 } |
12323 | 411 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
412 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
413 public static class MulExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
414 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
415 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
416 long r = x * y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
417 long ax = Math.abs(x); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
418 long ay = Math.abs(y); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
419 if (((ax | ay) >>> 31 != 0)) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
420 // Some bits greater than 2^31 that might cause overflow |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
421 // Check the result using the divide operator |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
422 // and check for the special case of Long.MIN_VALUE * -1 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
423 if (((y != 0) && (r / y != x)) || |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
424 (x == Long.MIN_VALUE && y == -1)) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
425 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
426 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
427 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
428 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
429 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
430 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
431 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
432 public long checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
433 return Math.multiplyExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
434 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
435 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
436 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
437 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
438 return a * b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
439 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
440 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
441 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
442 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
443 return "multiplyExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
444 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
445 } |
12323 | 446 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
447 public static class NegExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
448 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
449 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
450 if (a == Long.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
451 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
452 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
453 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
454 return -a; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
455 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
456 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
457 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
458 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
459 public long checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
460 return Math.negateExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
461 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
462 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
463 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
464 public long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
465 return -value; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
466 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
467 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
468 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
469 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
470 return "negateExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
471 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
472 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
473 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
474 public static class NegExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
475 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
476 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
477 if (a == Integer.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
478 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
479 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
480 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
481 return -a; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
482 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
483 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
484 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
485 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
486 public int checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
487 return Math.negateExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
488 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
489 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
490 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
491 public int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
492 return -value; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
493 } |
12323 | 494 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
495 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
496 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
497 return "negateExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
498 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
499 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
500 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
501 public static class SubExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
502 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
503 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
504 int r = x - y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
505 // HD 2-12 Overflow iff the arguments have different signs and |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
506 // the sign of the result is different than the sign of x |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
507 if (((x ^ y) & (x ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
508 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
509 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
510 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
511 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
512 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
513 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
514 public int checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
515 return Math.subtractExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
516 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
517 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
518 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
519 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
520 return a - b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
521 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
522 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
523 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
524 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
525 return "subtractExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
526 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
527 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
528 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
529 public static class SubExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
530 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
531 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
532 long r = x - y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
533 // HD 2-12 Overflow iff the arguments have different signs and |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
534 // the sign of the result is different than the sign of x |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
535 if (((x ^ y) & (x ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
536 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
537 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
538 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
539 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
540 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
541 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
542 public long checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
543 return Math.subtractExact(a, b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
544 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
545 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
546 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
547 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
548 return a - b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
549 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
550 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
551 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
552 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
553 return "subtractExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
554 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
555 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
556 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
557 static class IncExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
558 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
559 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
560 if (a == Long.MAX_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
561 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
562 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
563 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
564 return a + 1L; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
565 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
566 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
567 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
568 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
569 public long checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
570 return Math.incrementExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
571 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
572 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
573 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
574 public long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
575 return value + 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
576 } |
12323 | 577 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
578 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
579 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
580 return "incrementExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
581 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
582 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
583 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
584 static class IncExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
585 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
586 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
587 if (a == Integer.MAX_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
588 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
589 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
590 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
591 return a + 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
592 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
593 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
594 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
595 public int checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
596 return Math.incrementExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
597 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
598 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
599 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
600 public int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
601 return value + 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
602 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
603 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
604 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
605 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
606 return "incrementExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
607 } |
12323 | 608 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
609 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
610 static class DecExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
611 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
612 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
613 if (a == Long.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
614 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
615 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
616 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
617 return a - 1L; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
618 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
619 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
620 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
621 public long checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
622 return Math.decrementExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
623 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
624 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
625 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
626 public long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
627 return value - 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
628 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
629 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
630 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
631 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
632 return "decExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
633 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
634 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
635 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
636 static class DecExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
637 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
638 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
639 if (a == Integer.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
640 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
641 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
642 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
643 return a - 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
644 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
645 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
646 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
647 public int checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
648 return Math.decrementExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
649 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
650 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
651 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
652 public int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
653 return value - 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
654 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
655 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
656 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
657 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
658 return "decrementExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
659 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
660 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
661 |
12323 | 662 } |