Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codegen/IntRotateWithImmediate.java
41149 views
1
/*
2
* Copyright (c) 2015 SAP SE. All rights reserved.
3
* Copyright (c) 2016, Red Hat, Inc. 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
* @bug 8080190
28
* @bug 8154537
29
* @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f
30
*
31
* @run main/othervm -Xbatch -XX:-UseOnStackReplacement compiler.codegen.IntRotateWithImmediate
32
* @author [email protected]
33
*/
34
35
package compiler.codegen;
36
37
public class IntRotateWithImmediate {
38
39
// This is currently the same as Integer.rotateRight()
40
static int rotateRight1(int i, int distance) {
41
// On some architectures (i.e. x86_64 and ppc64) the following computation is
42
// matched in the .ad file into a single MachNode which emmits a single rotate
43
// machine instruction. It is important that the shift amount is masked to match
44
// corresponding immediate width in the native instruction. On x86_64 the rotate
45
// left instruction ('rol') encodes an 8-bit immediate while the corresponding
46
// 'rotlwi' instruction on Power only encodes a 5-bit immediate.
47
return ((i >>> distance) | (i << -distance));
48
}
49
50
static int rotateRight2(int i, int distance) {
51
return ((i >>> distance) | (i << (32 - distance)));
52
}
53
54
static int compute1(int x) {
55
return rotateRight1(x, 3);
56
}
57
58
static int compute2(int x) {
59
return rotateRight2(x, 3);
60
}
61
62
public static void main(String args[]) {
63
int val = 4096;
64
65
int firstResult = compute1(val);
66
67
for (int i = 0; i < 100000; i++) {
68
int newResult = compute1(val);
69
if (firstResult != newResult) {
70
throw new InternalError(firstResult + " != " + newResult);
71
}
72
newResult = compute2(val);
73
if (firstResult != newResult) {
74
throw new InternalError(firstResult + " != " + newResult);
75
}
76
}
77
System.out.println("OK");
78
}
79
80
}
81
82