Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/bigInteger/TestShift.java
41153 views
1
/*
2
* Copyright (c) 2019, 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
24
/**
25
* @test
26
* @key randomness
27
* @bug 8234692
28
* @summary Add C2 x86 intrinsic for BigInteger::shiftLeft() and BigInteger::shiftRight() method
29
* @library /test/lib
30
* @requires vm.compiler2.enabled
31
*
32
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
33
* -XX:CompileCommand=exclude,compiler.intrinsics.bigInteger.TestShift::main
34
* -XX:CompileCommand=option,compiler.intrinsics.bigInteger.TestShift::base_left_shift,ccstr,DisableIntrinsic,_bigIntegerLeftShiftWorker
35
* -XX:CompileCommand=option,compiler.intrinsics.bigInteger.TestShift::base_right_shift,ccstr,DisableIntrinsic,_bigIntegerRightShiftWorker
36
* -XX:CompileCommand=inline,java.math.BigInteger::shiftLeft
37
* -XX:CompileCommand=inline,java.math.BigInteger::shiftRight
38
* compiler.intrinsics.bigInteger.TestShift
39
*
40
* @run main/othervm/timeout=600
41
* -XX:CompileCommand=exclude,compiler.intrinsics.bigInteger.TestShift::main
42
* -XX:CompileCommand=option,compiler.intrinsics.bigInteger.TestShift::base_left_shift,ccstr,DisableIntrinsic,_bigIntegerLeftShiftWorker
43
* -XX:CompileCommand=option,compiler.intrinsics.bigInteger.TestShift::base_right_shift,ccstr,DisableIntrinsic,_bigIntegerRightShiftWorker
44
* -XX:CompileCommand=inline,java.math.BigInteger::shiftLeft
45
* -XX:CompileCommand=inline,java.math.BigInteger::shiftRight
46
* compiler.intrinsics.bigInteger.TestShift
47
*
48
*/
49
50
package compiler.intrinsics.bigInteger;
51
52
import java.math.BigInteger;
53
import java.util.Arrays;
54
import java.util.Random;
55
import jdk.test.lib.Utils;
56
57
public class TestShift {
58
59
public static BigInteger base_left_shift(BigInteger op1, int shift) {
60
return op1.shiftLeft(shift);
61
}
62
63
public static BigInteger new_left_shift(BigInteger op1, int shift) {
64
return op1.shiftLeft(shift);
65
}
66
67
public static BigInteger base_right_shift(BigInteger op1, int shift) {
68
return op1.shiftRight(shift);
69
}
70
71
public static BigInteger new_right_shift(BigInteger op1, int shift) {
72
return op1.shiftRight(shift);
73
}
74
75
public static boolean bytecompare(BigInteger b1, BigInteger b2) {
76
byte[] data1 = b1.toByteArray();
77
byte[] data2 = b2.toByteArray();
78
if (data1.length != data2.length)
79
return false;
80
for (int i = 0; i < data1.length; i++) {
81
if (data1[i] != data2[i])
82
return false;
83
}
84
return true;
85
}
86
87
public static String stringify(BigInteger b) {
88
String strout= "";
89
byte [] data = b.toByteArray();
90
for (int i = 0; i < data.length; i++) {
91
strout += (String.format("%02x",data[i]) + " ");
92
}
93
return strout;
94
}
95
96
public static void main(String args[]) throws Exception {
97
BigInteger [] inputbuffer = new BigInteger[10];
98
BigInteger [] oldLeftShiftResult = new BigInteger[10];
99
BigInteger [] newLeftShiftResult = new BigInteger[10];
100
BigInteger [] oldRightShiftResult = new BigInteger[10];
101
BigInteger [] newRightShiftResult = new BigInteger[10];
102
103
Random rand = Utils.getRandomInstance();
104
int shiftCount = rand.nextInt(30) + 1;
105
106
for(int i = 0; i < inputbuffer.length; i++) {
107
int numbits = rand.nextInt(4096)+32;
108
inputbuffer[i] = new BigInteger(numbits, rand);
109
}
110
111
for (int j = 0; j < 100000; j++) {
112
for(int i = 0; i < inputbuffer.length; i++) {
113
oldLeftShiftResult[i] = base_left_shift(inputbuffer[i], shiftCount);
114
newLeftShiftResult[i] = new_left_shift(inputbuffer[i], shiftCount);
115
if (!bytecompare(oldLeftShiftResult[i], newLeftShiftResult[i])) {
116
System.out.println("mismatch for input:" + stringify(inputbuffer[i]) + "\n" + "expected left shift result:" + stringify(oldLeftShiftResult[i]) + "\n" +
117
"calculated left shift result:" + stringify(newLeftShiftResult[i]));
118
throw new Exception("Failed");
119
}
120
121
oldRightShiftResult[i] = base_right_shift(inputbuffer[i], shiftCount);
122
newRightShiftResult[i] = new_right_shift(inputbuffer[i], shiftCount);
123
if (!bytecompare(oldRightShiftResult[i], newRightShiftResult[i])) {
124
System.out.println("mismatch for input:" + stringify(inputbuffer[i]) + "\n" + "expected right shift result:" + stringify(oldRightShiftResult[i]) + "\n" +
125
"calculated right shift result:" + stringify(newRightShiftResult[i]));
126
throw new Exception("Failed");
127
}
128
}
129
}
130
}
131
}
132
133