author | iignatyev |
Thu, 26 Jul 2018 23:59:46 -0700 | |
changeset 51298 | 3e08503ad77e |
parent 50366 | 4d85990f9c4a |
permissions | -rw-r--r-- |
50366
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
1 |
/* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
4 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
8 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
13 |
* accompanied this code). |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
14 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
18 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
21 |
* questions. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
22 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
23 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
24 |
/* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
25 |
* @test |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
26 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
27 |
* @summary converted from VM Testbase runtime/jbe/subcommon/subcommon02. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
28 |
* VM Testbase keywords: [runtime] |
51298 | 29 |
* VM Testbase comments: 7190319 |
50366
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
30 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
31 |
* @library /vmTestbase |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
32 |
* /test/lib |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
33 |
* @run driver jdk.test.lib.FileInstaller . . |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
34 |
* @run main/othervm vm.compiler.jbe.subcommon.subcommon02.subcommon02 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
35 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
36 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
37 |
package vm.compiler.jbe.subcommon.subcommon02; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
38 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
39 |
/* -- Common subexpression elimination testing |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
40 |
Using global common subexpression in method fopt() to calculate x**n. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
41 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
42 |
import java.io.*; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
43 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
44 |
public class subcommon02 { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
45 |
int LEN = 5000; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
46 |
int WIDTH = 20; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
47 |
int ngrt10000 = 0; // number of elements > 10,000 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
48 |
int ngrtO10000 = 0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
49 |
int ngrt1000 = 0; // number of elements > 1,000 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
50 |
int ngrtO1000 = 0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
51 |
int ngrt100 = 0; // number of elements > 100 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
52 |
int ngrtO100 = 0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
53 |
int nsmet100 = 0; // number of elements <= 100 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
54 |
int nsmetO100 = 0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
55 |
double a[][] = new double[LEN][WIDTH]; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
56 |
double aopt[][] = new double[LEN][WIDTH]; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
57 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
58 |
public static void main(String args[]) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
59 |
subcommon02 sce = new subcommon02(); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
60 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
61 |
sce.f(); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
62 |
sce.fopt(); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
63 |
if (sce.eCheck()) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
64 |
System.out.println("Test subcommon02 Passed."); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
65 |
} else { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
66 |
throw new Error("Test subcommon02 Failed."); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
67 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
68 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
69 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
70 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
71 |
double nPower(int x, int pwr) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
72 |
return Math.pow(x, pwr); // x**pwr |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
73 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
74 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
75 |
// non-optimized version |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
76 |
void f() { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
77 |
for (int x = 0; x < LEN; x++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
78 |
for (int n = 0; n < WIDTH; n++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
79 |
if (nPower(x, n) > 10000) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
80 |
a[x][n] = nPower(x, n); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
81 |
ngrt10000++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
82 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
83 |
else if (nPower(x, n) > 1000) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
84 |
a[x][n] = nPower(x, n); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
85 |
ngrt1000++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
86 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
87 |
else if (nPower(x, n) > 100) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
88 |
a[x][n] = nPower(x, n); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
89 |
ngrt100++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
90 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
91 |
else { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
92 |
a[x][n] = nPower(x, n); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
93 |
nsmet100++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
94 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
95 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
96 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
97 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
98 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
99 |
// hand-optimized version |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
100 |
void fopt() { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
101 |
for (int x = 0; x < LEN; x++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
102 |
for (int n = 0; n < WIDTH; n++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
103 |
double tmp = nPower(x, n); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
104 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
105 |
aopt[x][n] = tmp; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
106 |
if (tmp > 10000) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
107 |
ngrtO10000++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
108 |
else if (tmp > 1000) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
109 |
ngrtO1000++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
110 |
else if (tmp > 100) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
111 |
ngrtO100++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
112 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
113 |
nsmetO100++; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
114 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
115 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
116 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
117 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
118 |
// Compare non-optimized and hand-optimized results |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
119 |
boolean eCheck() { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
120 |
boolean r = true; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
121 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
122 |
for (int i = 0; i < LEN; i++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
123 |
for (int j = 0; j < WIDTH; j++) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
124 |
// if (a[i][j] != aopt[i][j]) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
125 |
if (ulpDiff(a[i][j], aopt[i][j]) > 1) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
126 |
System.out.println("Bad result: a["+i+","+j+"]="+a[i][j]+"; aopt["+i+","+j+"]="+aopt[i][j]); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
127 |
r = false; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
128 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
129 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
130 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
131 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
132 |
if ((ngrt10000!=ngrtO10000) || (ngrt1000!=ngrtO1000) || (ngrt100!=ngrtO100) || (nsmetO100!=nsmetO100)) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
133 |
System.out.println("Bad result: number of elements found is not matching"); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
134 |
r = false; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
135 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
136 |
return r; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
137 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
138 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
139 |
/** |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
140 |
* Paired-down nextAfter routine |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
141 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
142 |
public static double nextAfter(double base, double direction) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
143 |
//first check for NaN values |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
144 |
if (Double.isNaN(base) || Double.isNaN(direction)) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
145 |
// return a NaN dervied from the input NaN(s) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
146 |
return base + direction; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
147 |
} else if (base == direction) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
148 |
return base; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
149 |
} else { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
150 |
long doppelganger; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
151 |
double result=0.0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
152 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
153 |
doppelganger = Double.doubleToLongBits(base + 0.0); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
154 |
if (direction > base) //next greater value |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
155 |
{ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
156 |
if (doppelganger >= 0 ) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
157 |
result = Double.longBitsToDouble(++doppelganger); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
158 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
159 |
result = Double.longBitsToDouble(--doppelganger); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
160 |
} else if (direction < base) { // calculate next lesser value |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
161 |
if (doppelganger > 0) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
162 |
result = Double.longBitsToDouble(--doppelganger); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
163 |
else if (doppelganger < 0) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
164 |
result = Double.longBitsToDouble(++doppelganger); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
165 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
166 |
/* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
167 |
* doppelganger==0L, result is -MIN_VALUE |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
168 |
* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
169 |
* The transition from zero (implicitly |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
170 |
* positive) to the smallest negative |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
171 |
* signed magnitude value must be done |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
172 |
* explicitly. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
173 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
174 |
result = -Double.MIN_VALUE; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
175 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
176 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
177 |
return result; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
178 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
179 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
180 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
181 |
/* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
182 |
* return ulp of a floating-point value |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
183 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
184 |
static double ulp(double d) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
185 |
d = Math.abs(d); // don't worry about negative numbers |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
186 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
187 |
if(Double.isNaN(d)) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
188 |
return Double.NaN; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
189 |
else if(Double.isInfinite(d)) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
190 |
return Double.POSITIVE_INFINITY; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
191 |
else { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
192 |
// can't represent (Double.MAX_VALUE + ulp) so special case it |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
193 |
if(d == Double.MAX_VALUE) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
194 |
return 1.9958403095347198E292; // 2^971 |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
195 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
196 |
return nextAfter(d, Double.POSITIVE_INFINITY) - d; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
197 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
198 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
199 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
200 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
201 |
/* |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
202 |
* return signed difference in ulps between two floating-point |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
203 |
* values. ulpDiff(NaN, NaN) is zero. |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
204 |
*/ |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
205 |
static double ulpDiff(double ref, double test) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
206 |
double ulp; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
207 |
// assume ref is "correct" value |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
208 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
209 |
// Infinity, NaN handling |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
210 |
if(Double.isInfinite(ref)) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
211 |
if(ref == test) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
212 |
return 0.0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
213 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
214 |
return Double.POSITIVE_INFINITY; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
215 |
} else if(Double.isNaN(ref)) { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
216 |
if(Double.isNaN(test)) |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
217 |
return 0.0; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
218 |
else |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
219 |
return Double.NaN; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
220 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
221 |
else { |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
222 |
ulp = ulp(ref); |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
223 |
// the expression below can overflow |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
224 |
return (test - ref) / ulp; |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
225 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
226 |
} |
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
227 |
|
4d85990f9c4a
8202812: [TESTBUG] Open source VM testbase compiler tests
iignatyev
parents:
diff
changeset
|
228 |
} |