Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/FloatingPoint/FPCompare/TestFPBinop/TestFPBinop.java
40951 views
1
/*
2
* Copyright (c) 2008, 2021, 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
/*
25
* @test
26
*
27
* @summary converted from VM Testbase jit/FloatingPoint/FPCompare/TestFPBinop.
28
* VM Testbase keywords: [jit, quick]
29
*
30
* @library /vmTestbase
31
* /test/lib
32
* @run main/othervm jit.FloatingPoint.FPCompare.TestFPBinop.TestFPBinop
33
*/
34
35
package jit.FloatingPoint.FPCompare.TestFPBinop;
36
37
import nsk.share.TestFailure;
38
import nsk.share.GoldChecker;
39
40
/** Test of Floating Point Binary Ops.
41
** This is intended to be run on a known-correct system and the
42
** answer compared with the golden answer with diff or equivalent.
43
*/
44
public class TestFPBinop {
45
public static final GoldChecker goldChecker = new GoldChecker( "TestFPBinop" );
46
47
static float floatValues [] = {
48
Float.MIN_VALUE, Float.MAX_VALUE,
49
-Float.MIN_VALUE, -Float.MAX_VALUE,
50
-1.0f, 1.0f, -0.0f, 0.0f,
51
Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY,
52
Float.NaN
53
};
54
static double doubleValues [] = {
55
Double.MIN_VALUE, Double.MAX_VALUE,
56
-Double.MIN_VALUE, -Double.MAX_VALUE,
57
-1.0, 1.0, -0.0, 0.0,
58
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
59
Double.NaN
60
};
61
62
static int nValues = floatValues.length;
63
64
static float fOne, fZero;
65
static double dOne, dZero;
66
67
/* This is intended to thrwart an optimizing compiler
68
* from simplifying some of the expressions by using algebraic
69
* identities. */
70
static {
71
fOne = Integer.valueOf(1).floatValue();
72
fZero = Integer.valueOf(0).floatValue();
73
dOne = Integer.valueOf(1).doubleValue();
74
dZero = Integer.valueOf(0).doubleValue();
75
}
76
77
static final boolean DEBUG = false;
78
79
static String operandType = "";
80
81
// static values
82
static float xs, ys;
83
static double xS, yS;
84
85
/** Test of Floating Point Binary operators.
86
** The following orthogonal variables need to be tested.
87
** <ul>
88
** <li> Data type: float or double
89
** <li> Operator: +, -, *, /
90
** <li> Data values: +-normal, +-zero, NaN, +-infinity, +- min, +-max
91
** <li> Operand: variable, parameter, static, field, array element,
92
** function reference, expression, explicit constant.
93
** </ul>
94
*/
95
public static void main (String [] args) {
96
testFloats();
97
testDoubles();
98
TestFPBinop.goldChecker.check();
99
}
100
101
static void testFloats() {
102
for (int i = 0; i < floatValues.length; i++) {
103
float iVal = floatValues[i];
104
for (int j = 0; j < floatValues.length; j++) {
105
float jVal = floatValues[j];
106
testFloat(iVal, jVal);
107
}
108
}
109
}
110
static void testDoubles() {
111
for (int i = 0; i < doubleValues.length; i++) {
112
double iVal = doubleValues[i];
113
for (int j = 0; j < doubleValues.length; j++) {
114
double jVal = doubleValues[j];
115
testDouble(iVal, jVal);
116
}
117
}
118
}
119
120
static void testFloat (float x, float y) {
121
122
testFloatP(x, y);
123
testFloatL(x, y);
124
testFloatS(x, y);
125
testFloatF(x, y);
126
testFloatA(x, y);
127
testFloatM(x, y);
128
testFloat1(x, y);
129
testFloat2(x, y);
130
testFloat3(x, y);
131
}
132
133
static void testFloatP(float x, float y) {
134
135
check(x, y, x + y, "param", "+");
136
check(x, y, x - y, "param", "-");
137
check(x, y, x * y, "param", "*");
138
check(x, y, x / y, "param", "/");
139
140
}
141
142
static void testFloatL(float x, float y) {
143
144
float xl = x;
145
float yl = y;
146
147
check(xl, yl, xl + yl, "local", "+");
148
check(xl, yl, xl - yl, "local", "-");
149
check(xl, yl, xl * yl, "local", "*");
150
check(xl, yl, xl / yl, "local", "/");
151
152
}
153
154
static void testFloatS(float x, float y) {
155
156
xs = x;
157
ys = y;
158
159
check(xs, ys, xs + ys, "static", "+");
160
check(xs, ys, xs - ys, "static", "-");
161
check(xs, ys, xs * ys, "static", "*");
162
check(xs, ys, xs / ys, "static", "/");
163
164
}
165
166
static void testFloatF(float x, float y) {
167
168
FloatObject xo = new FloatObject(x);
169
FloatObject yo = new FloatObject(y);
170
171
check(xo.f, yo.f, xo.f + yo.f, "field", "+");
172
check(xo.f, yo.f, xo.f - yo.f, "field", "-");
173
check(xo.f, yo.f, xo.f * yo.f, "field", "*");
174
check(xo.f, yo.f, xo.f / yo.f, "field", "/");
175
176
}
177
178
static void testFloatA(float x, float y) {
179
180
int i = index(x);
181
int j = index(y);
182
float a [] = floatValues;
183
184
check(a[i], a[j], a[i] + a[j], "a[i]", "+");
185
check(a[i], a[j], a[i] - a[j], "a[i]", "-");
186
check(a[i], a[j], a[i] * a[j], "a[i]", "*");
187
check(a[i], a[j], a[i] / a[j], "a[i]", "/");
188
189
}
190
191
static void testFloatM(float x, float y) {
192
193
check(i(x), i(y), i(x) + i(y), "f(x)", "+");
194
check(i(x), i(y), i(x) - i(y), "f(x)", "-");
195
check(i(x), i(y), i(x) * i(y), "f(x)", "*");
196
check(i(x), i(y), i(x) / i(y), "f(x)", "/");
197
198
}
199
200
static void testFloat1(float x, float y) {
201
202
float zero = fZero;
203
float one = fOne;
204
205
check(((x + zero) * one), y, ((x + zero) * one) + y, "lExpr", "+");
206
check(((x + zero) * one), y, ((x + zero) * one) - y, "lExpr", "-");
207
check(((x + zero) * one), y, ((x + zero) * one) * y, "lExpr", "*");
208
check(((x + zero) * one), y, ((x + zero) * one) / y, "lExpr", "/");
209
210
}
211
212
static void testFloat3(float x, float y) {
213
214
float zero = fZero;
215
float one = fOne;
216
217
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) + (zero + one * y), "exprs", "+");
218
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) - (zero + one * y), "exprs", "-");
219
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) * (zero + one * y), "exprs", "*");
220
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) / (zero + one * y), "exprs", "/");
221
222
}
223
224
static void testFloat2(float x, float y) {
225
226
float zero = fZero;
227
float one = fOne;
228
229
operandType = "rExpr";
230
231
check(x, (zero + one * y), x + (zero + one * y), "rExpr", "+");
232
check(x, (zero + one * y), x - (zero + one * y), "rExpr", "-");
233
check(x, (zero + one * y), x * (zero + one * y), "rExpr", "*");
234
check(x, (zero + one * y), x / (zero + one * y), "rExpr", "/");
235
236
}
237
238
static void testDouble (double x, double y) {
239
240
testDoubleP(x, y);
241
testDoubleL(x, y);
242
testDoubleS(x, y);
243
testDoubleF(x, y);
244
testDoubleA(x, y);
245
testDoubleM(x, y);
246
testDouble1(x, y);
247
testDouble2(x, y);
248
testDouble3(x, y);
249
}
250
251
static void testDoubleP (double x, double y) {
252
253
check(x, y, x + y, "param", "+");
254
check(x, y, x - y, "param", "-");
255
check(x, y, x * y, "param", "*");
256
check(x, y, x / y, "param", "/");
257
258
}
259
260
static void testDoubleL (double x, double y) {
261
262
double xl = x;
263
double yl = y;
264
265
check(xl, yl, xl + yl, "local", "+");
266
check(xl, yl, xl - yl, "local", "-");
267
check(xl, yl, xl * yl, "local", "*");
268
check(xl, yl, xl / yl, "local", "/");
269
270
}
271
272
static void testDoubleS (double x, double y) {
273
274
xS = x;
275
yS = y;
276
277
check(xS, yS, xS + yS, "static", "+");
278
check(xS, yS, xS - yS, "static", "-");
279
check(xS, yS, xS * yS, "static", "*");
280
check(xS, yS, xS / yS, "static", "/");
281
282
}
283
284
static void testDoubleF (double x, double y) {
285
286
DoubleObject xo = new DoubleObject(x);
287
DoubleObject yo = new DoubleObject(y);
288
289
check(xo.f, yo.f, xo.f + yo.f, "field", "+");
290
check(xo.f, yo.f, xo.f - yo.f, "field", "-");
291
check(xo.f, yo.f, xo.f * yo.f, "field", "*");
292
check(xo.f, yo.f, xo.f / yo.f, "field", "/");
293
294
}
295
296
static void testDoubleA (double x, double y) {
297
298
int i = index(x);
299
int j = index(y);
300
double a [] = doubleValues;
301
302
check(a[i], a[j], a[i] + a[j], "a[i]", "+");
303
check(a[i], a[j], a[i] - a[j], "a[i]", "-");
304
check(a[i], a[j], a[i] * a[j], "a[i]", "*");
305
check(a[i], a[j], a[i] / a[j], "a[i]", "/");
306
307
}
308
309
static void testDoubleM (double x, double y) {
310
311
check(i(x), i(y), i(x) + i(y), "f(x)", "+");
312
check(i(x), i(y), i(x) - i(y), "f(x)", "-");
313
check(i(x), i(y), i(x) * i(y), "f(x)", "*");
314
check(i(x), i(y), i(x) / i(y), "f(x)", "/");
315
316
}
317
318
static void testDouble1 (double x, double y) {
319
320
double zero = dZero;
321
double one = dOne;
322
323
check(((x + zero) * one), y, ((x + zero) * one) + y, "lExpr", "+");
324
check(((x + zero) * one), y, ((x + zero) * one) - y, "lExpr", "-");
325
check(((x + zero) * one), y, ((x + zero) * one) * y, "lExpr", "*");
326
check(((x + zero) * one), y, ((x + zero) * one) / y, "lExpr", "/");
327
328
}
329
330
static void testDouble3 (double x, double y) {
331
332
double zero = dZero;
333
double one = dOne;
334
335
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) + (zero + one * y), "exprs", "+");
336
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) - (zero + one * y), "exprs", "-");
337
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) * (zero + one * y), "exprs", "*");
338
check(((x + zero) * one), (zero + one * y), ((x + zero) * one) / (zero + one * y), "exprs", "/");
339
340
}
341
342
static void testDouble2 (double x, double y) {
343
344
double zero = dZero;
345
double one = dOne;
346
347
check(x, (zero + one * y), x + (zero + one * y), "rExpr", "+");
348
check(x, (zero + one * y), x - (zero + one * y), "rExpr", "-");
349
check(x, (zero + one * y), x * (zero + one * y), "rExpr", "*");
350
check(x, (zero + one * y), x / (zero + one * y), "rExpr", "/");
351
352
}
353
354
355
/* The convoluted coding is intended to prevent inlining */
356
static float i(float x) {
357
while (Float.isNaN(x) && Float.floatToIntBits(x) == 0) {
358
x = 0.0f;
359
}
360
return x;
361
}
362
static double i(double x) {
363
while (Double.isNaN(x) && Double.doubleToLongBits(x) == 0L) {
364
x = 0.0;
365
}
366
return x;
367
}
368
369
static int index(float x) {
370
for (int i = 0; i < floatValues.length; i++) {
371
if (Float.valueOf(x).equals(Float.valueOf(floatValues[i])))
372
return i;
373
}
374
throw new TestFailure("ERROR: can't find " + x + " in floatValues.");
375
}
376
377
static int index(double x) {
378
for (int i = 0; i < doubleValues.length; i++) {
379
if (Double.valueOf(x).equals(Double.valueOf(doubleValues[i])))
380
return i;
381
}
382
throw new TestFailure("ERROR: can't find " + x + " in doubleValues.");
383
}
384
385
static void check (float x, float y, float result,
386
String operands, String operator) {
387
TestFPBinop.goldChecker.println(x + " " + operator + " " + y +
388
" = " + result + ", with float " +
389
operands + " operands");
390
}
391
392
static void check (double x, double y, double result,
393
String operands, String operator) {
394
TestFPBinop.goldChecker.println(x + " " + operator + " " + y +
395
" = " + result + ", with double " +
396
operands + " operands");
397
}
398
399
}
400
401
class FloatObject {
402
public float f;
403
404
public FloatObject(float x) {
405
f = x;
406
}
407
}
408
409
class DoubleObject {
410
public double f;
411
412
public DoubleObject(double x) {
413
f = x;
414
}
415
}
416
417