Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
41153 views
1
/*
2
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2020, BELLSOFT. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/*
26
* @test
27
* @summary Test compiler intrinsics for signum
28
* @library /test/lib
29
*
30
* @run main/othervm
31
* -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
32
* -XX:+UseSignumIntrinsic
33
* compiler.intrinsics.math.TestSignumIntrinsic
34
* @run main/othervm
35
* -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
36
* -XX:-UseSignumIntrinsic -XX:+UseCopySignIntrinsic
37
* compiler.intrinsics.math.TestSignumIntrinsic
38
*/
39
40
package compiler.intrinsics.math;
41
42
import jdk.test.lib.Asserts;
43
44
public class TestSignumIntrinsic {
45
46
private static final float[][] float_cases = {
47
{123.4f, 1.0f},
48
{-56.7f, -1.0f},
49
{7e30f, 1.0f},
50
{-0.3e30f, -1.0f},
51
{Float.MAX_VALUE, 1.0f},
52
{-Float.MAX_VALUE, -1.0f},
53
{Float.MIN_VALUE, 1.0f},
54
{-Float.MIN_VALUE, -1.0f},
55
{0.0f, 0.0f},
56
{-0.0f, -0.0f},
57
{Float.POSITIVE_INFINITY, 1.0f},
58
{Float.NEGATIVE_INFINITY, -1.0f},
59
{Float.NaN, Float.NaN},
60
{Float.MIN_NORMAL, 1.0f},
61
{-Float.MIN_NORMAL, -1.0f},
62
{0x0.0002P-126f, 1.0f},
63
{-0x0.0002P-126f, -1.0f}
64
};
65
66
private static final double[][] double_cases = {
67
{123.4d, 1.0d},
68
{-56.7d, -1.0d},
69
{7e30d, 1.0d},
70
{-0.3e30d, -1.0d},
71
{Double.MAX_VALUE, 1.0d},
72
{-Double.MAX_VALUE, -1.0d},
73
{Double.MIN_VALUE, 1.0d},
74
{-Double.MIN_VALUE, -1.0d},
75
{0.0d, 0.0d},
76
{-0.0d, -0.0d},
77
{Double.POSITIVE_INFINITY, 1.0d},
78
{Double.NEGATIVE_INFINITY, -1.0d},
79
{Double.NaN, Double.NaN},
80
{Double.MIN_NORMAL, 1.0d},
81
{-Double.MIN_NORMAL, -1.0d},
82
{0x0.00000001P-1022, 1.0d},
83
{-0x0.00000001P-1022, -1.0d}
84
};
85
86
public static void main(String[] args) throws Exception {
87
float fAccum = 0.0f;
88
double dAccum = 0.0d;
89
for (int i = 0; i < 100_000; i++) {
90
fAccum += floatTest();
91
dAccum += doubleTest();
92
}
93
System.out.println("SUCCESS. Accum values: " + fAccum + " and " + dAccum);
94
}
95
96
private static float floatTest() {
97
float accum = 0.0f;
98
for (float[] fcase : float_cases) {
99
float arg = fcase[0];
100
float expected = fcase[1];
101
float calculated = Math.signum(arg);
102
Asserts.assertEQ(expected, calculated, "Unexpected float result from " + arg);
103
accum += calculated;
104
}
105
return accum;
106
}
107
108
private static double doubleTest() {
109
double accum = 0.0d;
110
for (double[] dcase : double_cases) {
111
double arg = dcase[0];
112
double expected = dcase[1];
113
double calculated = Math.signum(arg);
114
Asserts.assertEQ(expected, calculated, "Unexpected double result from " + arg);
115
accum += calculated;
116
}
117
return accum;
118
}
119
}
120
121