Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/FpMinMaxIntrinsics.java
41161 views
1
/*
2
* Copyright (c) 2019, 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
package org.openjdk.bench.vm.compiler;
24
25
import org.openjdk.jmh.annotations.*;
26
import org.openjdk.jmh.infra.*;
27
28
import java.util.concurrent.TimeUnit;
29
import java.util.Random;
30
31
@BenchmarkMode(Mode.AverageTime)
32
@OutputTimeUnit(TimeUnit.NANOSECONDS)
33
@State(Scope.Thread)
34
public class FpMinMaxIntrinsics {
35
private static final int COUNT = 1000;
36
37
private double[] doubles = new double[COUNT];
38
private float[] floats = new float[COUNT];
39
40
private int c1, c2, s1, s2;
41
42
private Random r = new Random();
43
44
@Setup
45
public void init() {
46
c1 = s1 = step();
47
c2 = COUNT - (s2 = step());
48
49
for (int i=0; i<COUNT; i++) {
50
floats[i] = r.nextFloat();
51
doubles[i] = r.nextDouble();
52
}
53
}
54
55
private int step() {
56
return (r.nextInt() & 0xf) + 1;
57
}
58
59
@Benchmark
60
public void dMax(Blackhole bh) {
61
for (int i=0; i<COUNT; i++)
62
bh.consume(dMaxBench());
63
}
64
65
@Benchmark
66
public void dMin(Blackhole bh) {
67
for (int i=0; i<COUNT; i++)
68
bh.consume(dMinBench());
69
}
70
71
@Benchmark
72
public void fMax(Blackhole bh) {
73
for (int i=0; i<COUNT; i++)
74
bh.consume(fMaxBench());
75
}
76
77
@Benchmark
78
public void fMin(Blackhole bh) {
79
for (int i=0; i<COUNT; i++)
80
bh.consume(fMinBench());
81
}
82
83
private double dMaxBench() {
84
inc();
85
return Math.max(doubles[c1], doubles[c2]);
86
}
87
88
private double dMinBench() {
89
inc();
90
return Math.min(doubles[c1], doubles[c2]);
91
}
92
93
private float fMaxBench() {
94
inc();
95
return Math.max(floats[c1], floats[c2]);
96
}
97
98
private float fMinBench() {
99
inc();
100
return Math.min(floats[c1], floats[c2]);
101
}
102
103
private void inc() {
104
c1 = c1 + s1 < COUNT ? c1 + s1 : (s1 = step());
105
c2 = c2 - s2 > 0 ? c2 - s2 : COUNT - (s2 = step());
106
}
107
108
@Benchmark
109
public float fMinReduce() {
110
float result = Float.MAX_VALUE;
111
112
for (int i=0; i<COUNT; i++)
113
result = Math.min(result, floats[i]);
114
115
return result;
116
}
117
118
@Benchmark
119
public double dMinReduce() {
120
double result = Double.MAX_VALUE;
121
122
for (int i=0; i<COUNT; i++)
123
result = Math.min(result, doubles[i]);
124
125
return result;
126
}
127
}
128
129