Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/MacroLogicOpt.java
41161 views
1
/*
2
* Copyright (c) 2020, 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.Throughput)
32
@OutputTimeUnit(TimeUnit.SECONDS)
33
@State(Scope.Thread)
34
public class MacroLogicOpt {
35
@Param({"64","128","256","512","1024","2048","4096"}) private int VECLEN;
36
37
private int [] ai = new int[VECLEN];
38
private int [] bi = new int[VECLEN];
39
private int [] ci = new int[VECLEN];
40
private int [] ri = new int[VECLEN];
41
42
private long [] al = new long[VECLEN];
43
private long [] bl = new long[VECLEN];
44
private long [] cl = new long[VECLEN];
45
private long [] dl = new long[VECLEN];
46
private long [] el = new long[VECLEN];
47
private long [] fl = new long[VECLEN];
48
private long [] rl = new long[VECLEN];
49
50
private Random r = new Random();
51
52
@Setup
53
public void init() {
54
ai = new int[VECLEN];
55
bi = new int[VECLEN];
56
ci = new int[VECLEN];
57
ri = new int[VECLEN];
58
59
al = new long[VECLEN];
60
bl = new long[VECLEN];
61
cl = new long[VECLEN];
62
dl = new long[VECLEN];
63
el = new long[VECLEN];
64
fl = new long[VECLEN];
65
rl = new long[VECLEN];
66
for (int i=0; i<VECLEN; i++) {
67
ai[i] = r.nextInt();
68
bi[i] = r.nextInt();
69
ci[i] = r.nextInt();
70
71
al[i] = r.nextLong();
72
bl[i] = r.nextLong();
73
cl[i] = r.nextLong();
74
dl[i] = r.nextLong();
75
el[i] = r.nextLong();
76
fl[i] = r.nextLong();
77
}
78
}
79
80
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
81
private int run_workload1(int count, int [] a , int [] b, int [] c, int [] r) {
82
for(int i = 0 ; i < r.length ; i++)
83
r[i] = (((a[i] & b[i]) ^ (a[i] & c[i]) ^ (b[i] & c[i])) & ((~a[i] & b[i]) | (~b[i] & c[i]) | ~c[i] & a[i]));
84
return r[count];
85
}
86
87
@Benchmark
88
public void workload1_caller(Blackhole bh) {
89
int r = 0;
90
for(int i = 0 ; i < 10000; i++)
91
r += run_workload1(i&(ri.length-1), ai, bi, ci, ri);
92
bh.consume(r);
93
}
94
95
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
96
private long run_workload2(int count, long [] a , long [] b, long [] c, long [] r) {
97
for(int i = 0 ; i < r.length ; i++)
98
r[i] = (((a[i] & b[i]) ^ (a[i] & c[i]) ^ (b[i] & c[i])) & ((~a[i] & b[i]) | (~b[i] & c[i]) | ~c[i] & a[i]));
99
return r[count];
100
}
101
102
@Benchmark
103
public void workload2_caller(Blackhole bh) {
104
long r = 0;
105
for(int i = 0 ; i < 100000; i++)
106
r += run_workload2(i&(rl.length-1), al, bl, cl, rl);
107
bh.consume(r);
108
}
109
110
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
111
private long run_workload3(int count, long [] a , long [] b, long [] c,
112
long [] d, long [] e, long [] f, long [] r) {
113
for(int i = 0 ; i < r.length ; i++)
114
r[i] = (((~a[i] | ~b[i]) & (~c[i])) | (~d[i] & (~e[i] & f[i])));
115
return r[count];
116
}
117
118
@Benchmark
119
public void workload3_caller(Blackhole bh) {
120
long r = 0;
121
for(int i = 0 ; i < 10000; i++)
122
r += run_workload3(i&(ri.length-1), al, bl, cl, dl, el, fl, rl);
123
bh.consume(r);
124
}
125
}
126
127