Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/Rotation.java
41161 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2021, Arm Limited. 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
package org.openjdk.bench.vm.compiler;
26
27
import java.util.concurrent.TimeUnit;
28
29
import org.openjdk.jmh.annotations.Benchmark;
30
import org.openjdk.jmh.annotations.BenchmarkMode;
31
import org.openjdk.jmh.annotations.CompilerControl;
32
import org.openjdk.jmh.annotations.Fork;
33
import org.openjdk.jmh.annotations.Measurement;
34
import org.openjdk.jmh.annotations.Mode;
35
import org.openjdk.jmh.annotations.OutputTimeUnit;
36
import org.openjdk.jmh.annotations.Scope;
37
import org.openjdk.jmh.annotations.Setup;
38
import org.openjdk.jmh.annotations.State;
39
import org.openjdk.jmh.annotations.Warmup;
40
import org.openjdk.jmh.infra.Blackhole;
41
42
@BenchmarkMode(Mode.AverageTime)
43
@OutputTimeUnit(TimeUnit.NANOSECONDS)
44
@State(Scope.Benchmark)
45
@Fork(value = 3)
46
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
47
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
48
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
49
public class Rotation {
50
51
private static final int COUNT = 5000;
52
53
@State(Scope.Benchmark)
54
public static class MyState {
55
public int xi = 10;
56
public int yi = 24;
57
}
58
59
@Benchmark
60
public void xorRotateRight(MyState s, Blackhole blackhole) {
61
int x = s.xi;
62
int y = s.yi;
63
for (int i = 0; i < COUNT; i++) {
64
y = x ^ ((y >>> 5) | (y << -5));
65
}
66
blackhole.consume(y);
67
}
68
69
@Benchmark
70
public void bicRotateRight(MyState s, Blackhole blackhole) {
71
int x = s.xi;
72
int y = s.yi;
73
for (int i = 0; i < COUNT; i++) {
74
y = x & (-1 ^ ((y >>> 5) | (y << -5)));
75
}
76
blackhole.consume(y);
77
}
78
79
@Benchmark
80
public void eonRotateRight(MyState s, Blackhole blackhole) {
81
int x = s.xi;
82
int y = s.yi;
83
for (int i = 0; i < COUNT; i++) {
84
y = x ^ (-1 ^ ((y >>> 5) | (y << -5)));
85
}
86
blackhole.consume(y);
87
}
88
89
@Benchmark
90
public void ornRotateRight(MyState s, Blackhole blackhole) {
91
int x = s.xi;
92
int y = s.yi;
93
for (int i = 0; i < COUNT; i++) {
94
y = x | (-1 ^ ((y >>> 5) | (y << -5)));
95
}
96
blackhole.consume(y);
97
}
98
99
@Benchmark
100
public void andRotateRight(MyState s, Blackhole blackhole) {
101
int x = s.xi;
102
int y = s.yi;
103
for (int i = 0; i < COUNT; i++) {
104
y = x & ((y >>> 5) | (y << -5));
105
}
106
blackhole.consume(y);
107
}
108
}
109
110