Mercurial > hg > truffle
annotate test/compiler/intrinsics/mathexact/Verify.java @ 20121:5f533a5c2aaf
Merge.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 01 Apr 2015 17:36:51 +0200 |
parents | 52b4284cb496 |
children |
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(); |
18041
52b4284cb496
Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14909
diff
changeset
|
163 public static int[] values = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE }; |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
164 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
165 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
166 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
167 int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
168 Verify.verifyBinary(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
169 Verify.verifyBinary(rnd1, rnd2 + 1, 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 - 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
172 Verify.verifyBinary(rnd1, rnd2 - 1, method); |
18041
52b4284cb496
Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14909
diff
changeset
|
173 Verify.verifyBinary(0, values[0], method); |
52b4284cb496
Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14909
diff
changeset
|
174 Verify.verifyBinary(values[0], 0, method); |
52b4284cb496
Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14909
diff
changeset
|
175 Verify.verifyBinary(0, values[1], method); |
52b4284cb496
Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14909
diff
changeset
|
176 Verify.verifyBinary(values[1], 0, method); |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
177 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
178 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
179 } |
12323 | 180 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
181 public static class NonConstantLongTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
182 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
|
183 public static java.util.Random rnd = new java.util.Random(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
184 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
185 public static void verify(BinaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
186 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
187 long rnd1 = rnd.nextLong(), rnd2 = rnd.nextLong(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
188 Verify.verifyBinary(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
189 Verify.verifyBinary(rnd1, rnd2 + 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
190 Verify.verifyBinary(rnd1 + 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
191 Verify.verifyBinary(rnd1 - 1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
192 Verify.verifyBinary(rnd1, rnd2 - 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
193 Verify.verifyBinary(rnd1 + Long.MAX_VALUE - rnd2, rnd2 + 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
194 Verify.verifyBinary(values[0], values[2], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
195 Verify.verifyBinary(values[1], values[2], method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
196 Verify.verifyBinary(values[3], 74L, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
197 } |
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 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
200 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
201 public static class LoopDependentTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
202 public static java.util.Random rnd = new java.util.Random(); |
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 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
205 int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
206 runTest(rnd1, rnd2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
207 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
208 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
209 private static void runTest(int rnd1, int rnd2, BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
210 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
211 Verify.verifyBinary(rnd1 + i, rnd2 + i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
212 Verify.verifyBinary(rnd1 + i, rnd2 + (i & 0xff), method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
213 Verify.verifyBinary(rnd1 - i, rnd2 - (i & 0xff), method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
214 Verify.verifyBinary(rnd1 + i + 1, rnd2 + i + 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
215 Verify.verifyBinary(rnd1 + i * 2, rnd2 + i, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
216 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
217 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
218 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
219 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
220 public static class ConstantTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
221 public static void verify(BinaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
222 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
223 Verify.verifyBinary(5, 7, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
224 Verify.verifyBinary(Integer.MAX_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
225 Verify.verifyBinary(Integer.MIN_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
226 Verify.verifyBinary(Integer.MAX_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
227 Verify.verifyBinary(Integer.MIN_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
228 Verify.verifyBinary(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
229 Verify.verifyBinary(Integer.MAX_VALUE / 2, (Integer.MAX_VALUE / 2) + 3, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
230 Verify.verifyBinary(Integer.MAX_VALUE, Integer.MIN_VALUE, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
231 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
232 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
233 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
234 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
235 public static class ConstantLongTest { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
236 public static void verify(BinaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
237 for (int i = 0; i < 50000; ++i) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
238 Verify.verifyBinary(5, 7, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
239 Verify.verifyBinary(Long.MAX_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
240 Verify.verifyBinary(Long.MIN_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
241 Verify.verifyBinary(Long.MAX_VALUE, -1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
242 Verify.verifyBinary(Long.MIN_VALUE, 1, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
243 Verify.verifyBinary(Long.MAX_VALUE / 2, Long.MAX_VALUE / 2, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
244 Verify.verifyBinary(Long.MAX_VALUE / 2, (Long.MAX_VALUE / 2) + 3, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
245 Verify.verifyBinary(Long.MAX_VALUE, Long.MIN_VALUE, method); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
246 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
247 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
248 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
249 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
250 public static interface BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
251 int safeMethod(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
252 int checkMethod(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
253 int unchecked(int a, int b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
254 String name(); |
12323 | 255 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
256 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
257 public static interface UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
258 int safeMethod(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
259 int checkMethod(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
260 int unchecked(int value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
261 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
262 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
263 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
264 public static interface BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
265 long safeMethod(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
266 long checkMethod(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
267 long unchecked(long a, long b); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
268 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
269 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
270 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
271 public static interface UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
272 long safeMethod(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
273 long checkMethod(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
274 long unchecked(long value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
275 String name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
276 } |
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 public static class UnaryToBinary implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
279 private final UnaryMethod method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
280 public UnaryToBinary(UnaryMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
281 this.method = method; |
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 safeMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
286 return method.safeMethod(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 checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
291 return method.checkMethod(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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
295 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
296 return method.unchecked(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
297 |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
301 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
302 return method.name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
303 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
304 } |
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 public static class UnaryToBinaryLong implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
307 private final UnaryLongMethod method; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
308 public UnaryToBinaryLong(UnaryLongMethod method) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
309 this.method = method; |
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 safeMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
314 return method.safeMethod(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 checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
319 return method.checkMethod(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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
323 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
324 return method.unchecked(a); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
325 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
326 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
327 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
328 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
329 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
330 return method.name(); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
331 } |
12323 | 332 } |
333 | |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
334 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
335 public static class AddExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
336 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
337 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
338 int r = x + y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
339 // 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
|
340 if (((x ^ r) & (y ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
341 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
342 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
343 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
344 |
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 int checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
349 return Math.addExact(a, b); |
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 String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
354 return "addExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
355 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
356 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
357 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
358 public int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
359 return a + b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
360 } |
12323 | 361 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
362 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
363 public static class AddExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
364 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
365 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
366 long r = x + y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
367 // 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
|
368 if (((x ^ r) & (y ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
369 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
370 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
371 return r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
372 |
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 long checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
377 return Math.addExact(a, b); |
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 String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
382 return "addExactLong"; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
386 public long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
387 return a + b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
388 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
389 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
390 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
391 public static class MulExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
392 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
393 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
394 long r = (long)x * (long)y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
395 if ((int)r != r) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
396 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
397 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
398 return (int)r; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
399 |
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 checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
404 return Math.multiplyExact(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 int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
409 return a * b; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
410 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
411 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
412 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
413 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
414 return "multiplyExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
415 } |
12323 | 416 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
417 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
418 public static class MulExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
419 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
420 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
421 long r = x * y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
422 long ax = Math.abs(x); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
423 long ay = Math.abs(y); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
424 if (((ax | ay) >>> 31 != 0)) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
425 // Some bits greater than 2^31 that might cause overflow |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
426 // Check the result using the divide operator |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
427 // and check for the special case of Long.MIN_VALUE * -1 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
428 if (((y != 0) && (r / y != x)) || |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
429 (x == Long.MIN_VALUE && y == -1)) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
430 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
431 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
432 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
433 return r; |
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 checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
438 return Math.multiplyExact(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 long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
443 return a * b; |
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 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
446 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
447 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
448 return "multiplyExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
449 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
450 } |
12323 | 451 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
452 public static class NegExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
453 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
454 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
455 if (a == Long.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
456 throw new ArithmeticException("long overflow"); |
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 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
459 return -a; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
460 |
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 checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
465 return Math.negateExact(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 long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
470 return -value; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
474 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
475 return "negateExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
476 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
477 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
478 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
479 public static class NegExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
480 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
481 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
482 if (a == Integer.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
483 throw new ArithmeticException("integer overflow"); |
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 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
486 return -a; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
487 |
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 checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
492 return Math.negateExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
493 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
494 |
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 int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
497 return -value; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
498 } |
12323 | 499 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
500 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
501 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
502 return "negateExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
503 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
504 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
505 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
506 public static class SubExactI implements BinaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
507 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
508 public int safeMethod(int x, int y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
509 int r = x - y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
510 // HD 2-12 Overflow iff the arguments have different signs and |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
511 // the sign of the result is different than the sign of x |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
512 if (((x ^ y) & (x ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
513 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
514 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
515 return r; |
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 checkMethod(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
520 return Math.subtractExact(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 int unchecked(int a, int b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
525 return a - b; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
529 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
530 return "subtractExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
531 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
532 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
533 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
534 public static class SubExactL implements BinaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
535 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
536 public long safeMethod(long x, long y) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
537 long r = x - y; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
538 // HD 2-12 Overflow iff the arguments have different signs and |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
539 // the sign of the result is different than the sign of x |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
540 if (((x ^ y) & (x ^ r)) < 0) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
541 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
542 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
543 return r; |
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 checkMethod(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
548 return Math.subtractExact(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 long unchecked(long a, long b) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
553 return a - b; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
557 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
558 return "subtractExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
559 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
560 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
561 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
562 static class IncExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
563 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
564 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
565 if (a == Long.MAX_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
566 throw new ArithmeticException("long overflow"); |
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 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
569 return a + 1L; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
570 |
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 checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
575 return Math.incrementExact(value); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
576 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
577 |
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 long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
580 return value + 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
581 } |
12323 | 582 |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
583 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
584 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
585 return "incrementExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
586 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
587 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
588 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
589 static class IncExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
590 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
591 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
592 if (a == Integer.MAX_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
593 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
594 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
595 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
596 return a + 1; |
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 checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
601 return Math.incrementExact(value); |
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 int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
606 return value + 1; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
607 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
608 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
609 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
610 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
611 return "incrementExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
612 } |
12323 | 613 } |
12972
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
614 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
615 static class DecExactL implements UnaryLongMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
616 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
617 public long safeMethod(long a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
618 if (a == Long.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
619 throw new ArithmeticException("long overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
620 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
621 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
622 return a - 1L; |
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 checkMethod(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
627 return Math.decrementExact(value); |
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 long unchecked(long value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
632 return value - 1; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
636 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
637 return "decExactLong"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
638 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
639 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
640 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
641 static class DecExactI implements UnaryMethod { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
642 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
643 public int safeMethod(int a) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
644 if (a == Integer.MIN_VALUE) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
645 throw new ArithmeticException("integer overflow"); |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
646 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
647 |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
648 return a - 1; |
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 checkMethod(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
653 return Math.decrementExact(value); |
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 int unchecked(int value) { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
658 return value - 1; |
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 @Override |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
662 public String name() { |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
663 return "decrementExact"; |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
664 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
665 } |
59e8ad757e19
8026844: Various Math functions needs intrinsification
rbackman
parents:
12323
diff
changeset
|
666 |
12323 | 667 } |