Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/bigInteger/TestSquareToLen.java
41153 views
1
/*
2
* Copyright (c) 2015, 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 8081778
28
* @summary Add C2 x86 intrinsic for BigInteger::squareToLen() method
29
* @library /test/lib
30
*
31
* @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
32
* -XX:CompileCommand=exclude,compiler.intrinsics.bigInteger.TestSquareToLen::main
33
* -XX:CompileCommand=option,compiler.intrinsics.bigInteger.TestSquareToLen::base_multiply,ccstr,DisableIntrinsic,_squareToLen
34
* -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_squareToLen
35
* -XX:CompileCommand=option,java.math.BigInteger::square,ccstr,DisableIntrinsic,_squareToLen
36
* -XX:CompileCommand=option,java.math.BigInteger::squareToLen,ccstr,DisableIntrinsic,_squareToLen
37
* -XX:CompileCommand=inline,java.math.BigInteger::multiply
38
* -XX:CompileCommand=inline,java.math.BigInteger::square
39
* -XX:CompileCommand=inline,java.math.BigInteger::squareToLen
40
* compiler.intrinsics.bigInteger.TestSquareToLen
41
*/
42
43
package compiler.intrinsics.bigInteger;
44
45
import java.math.BigInteger;
46
import java.util.Random;
47
import jdk.test.lib.Utils;
48
49
public class TestSquareToLen {
50
51
// Avoid intrinsic by preventing inlining multiply() and squareToLen().
52
public static BigInteger base_multiply(BigInteger op1) {
53
return op1.multiply(op1);
54
}
55
56
// Generate squareToLen() intrinsic by inlining multiply().
57
public static BigInteger new_multiply(BigInteger op1) {
58
return op1.multiply(op1);
59
}
60
61
public static boolean bytecompare(BigInteger b1, BigInteger b2) {
62
byte[] data1 = b1.toByteArray();
63
byte[] data2 = b2.toByteArray();
64
if (data1.length != data2.length)
65
return false;
66
for (int i = 0; i < data1.length; i++) {
67
if (data1[i] != data2[i])
68
return false;
69
}
70
return true;
71
}
72
73
public static String stringify(BigInteger b) {
74
String strout= "";
75
byte [] data = b.toByteArray();
76
for (int i = 0; i < data.length; i++) {
77
strout += (String.format("%02x",data[i]) + " ");
78
}
79
return strout;
80
}
81
82
public static void main(String args[]) throws Exception {
83
84
BigInteger oldsum = new BigInteger("0");
85
BigInteger newsum = new BigInteger("0");
86
87
BigInteger b1, b2, oldres, newres;
88
89
Random rand = new Random(Utils.getRandomInstance().nextLong());
90
Random rand1 = new Random(Utils.getRandomInstance().nextLong());
91
92
for (int j = 0; j < 100000; j++) {
93
int rand_int = rand1.nextInt(3136)+32;
94
b1 = new BigInteger(rand_int, rand);
95
96
oldres = base_multiply(b1);
97
newres = new_multiply(b1);
98
99
oldsum = oldsum.add(oldres);
100
newsum = newsum.add(newres);
101
102
if (!bytecompare(oldres,newres)) {
103
System.out.print("mismatch for:b1:" + stringify(b1) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
104
System.out.println(b1);
105
throw new Exception("Failed");
106
}
107
}
108
if (!bytecompare(oldsum,newsum)) {
109
System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
110
throw new Exception("Failed");
111
} else {
112
System.out.println("Success");
113
}
114
}
115
}
116
117