1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/intrinsics/muladd/TestMulAdd.java Wed Feb 17 13:40:12 2016 +0300 1.3 @@ -0,0 +1,117 @@ 1.4 +/* 1.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +/** 1.29 + * @test 1.30 + * @bug 8081778 1.31 + * @summary Add C2 x86 intrinsic for BigInteger::mulAdd() method 1.32 + * 1.33 + * @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch 1.34 + * -XX:+IgnoreUnrecognizedVMOptions -XX:-UseSquareToLenIntrinsic -XX:-UseMultiplyToLenIntrinsic 1.35 + * -XX:CompileCommand=dontinline,TestMulAdd::main 1.36 + * -XX:CompileCommand=option,TestMulAdd::base_multiply,ccstr,DisableIntrinsic,_mulAdd 1.37 + * -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_mulAdd 1.38 + * -XX:CompileCommand=option,java.math.BigInteger::square,ccstr,DisableIntrinsic,_mulAdd 1.39 + * -XX:CompileCommand=option,java.math.BigInteger::squareToLen,ccstr,DisableIntrinsic,_mulAdd 1.40 + * -XX:CompileCommand=option,java.math.BigInteger::mulAdd,ccstr,DisableIntrinsic,_mulAdd 1.41 + * -XX:CompileCommand=inline,java.math.BigInteger::multiply 1.42 + * -XX:CompileCommand=inline,java.math.BigInteger::square 1.43 + * -XX:CompileCommand=inline,java.math.BigInteger::squareToLen 1.44 + * -XX:CompileCommand=inline,java.math.BigInteger::mulAdd TestMulAdd 1.45 + */ 1.46 + 1.47 +import java.util.Random; 1.48 +import java.math.*; 1.49 + 1.50 +public class TestMulAdd { 1.51 + 1.52 + // Avoid intrinsic by preventing inlining multiply() and mulAdd(). 1.53 + public static BigInteger base_multiply(BigInteger op1) { 1.54 + return op1.multiply(op1); 1.55 + } 1.56 + 1.57 + // Generate mulAdd() intrinsic by inlining multiply(). 1.58 + public static BigInteger new_multiply(BigInteger op1) { 1.59 + return op1.multiply(op1); 1.60 + } 1.61 + 1.62 + public static boolean bytecompare(BigInteger b1, BigInteger b2) { 1.63 + byte[] data1 = b1.toByteArray(); 1.64 + byte[] data2 = b2.toByteArray(); 1.65 + if (data1.length != data2.length) 1.66 + return false; 1.67 + for (int i = 0; i < data1.length; i++) { 1.68 + if (data1[i] != data2[i]) 1.69 + return false; 1.70 + } 1.71 + return true; 1.72 + } 1.73 + 1.74 + public static String stringify(BigInteger b) { 1.75 + String strout= ""; 1.76 + byte [] data = b.toByteArray(); 1.77 + for (int i = 0; i < data.length; i++) { 1.78 + strout += (String.format("%02x",data[i]) + " "); 1.79 + } 1.80 + return strout; 1.81 + } 1.82 + 1.83 + public static void main(String args[]) throws Exception { 1.84 + 1.85 + BigInteger oldsum = new BigInteger("0"); 1.86 + BigInteger newsum = new BigInteger("0"); 1.87 + 1.88 + BigInteger b1, b2, oldres, newres; 1.89 + 1.90 + Random rand = new Random(); 1.91 + long seed = System.nanoTime(); 1.92 + Random rand1 = new Random(); 1.93 + long seed1 = System.nanoTime(); 1.94 + rand.setSeed(seed); 1.95 + rand1.setSeed(seed1); 1.96 + 1.97 + for (int j = 0; j < 100000; j++) { 1.98 + int rand_int = rand1.nextInt(3136)+32; 1.99 + b1 = new BigInteger(rand_int, rand); 1.100 + 1.101 + oldres = base_multiply(b1); 1.102 + newres = new_multiply(b1); 1.103 + 1.104 + oldsum = oldsum.add(oldres); 1.105 + newsum = newsum.add(newres); 1.106 + 1.107 + if (!bytecompare(oldres,newres)) { 1.108 + System.out.print("mismatch for:b1:" + stringify(b1) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres)); 1.109 + System.out.println(b1); 1.110 + throw new Exception("Failed"); 1.111 + } 1.112 + } 1.113 + if (!bytecompare(oldsum,newsum)) { 1.114 + System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum)); 1.115 + throw new Exception("Failed"); 1.116 + } else { 1.117 + System.out.println("Success"); 1.118 + } 1.119 + } 1.120 +}