test/compiler/intrinsics/squaretolen/TestSquareToLen.java

Wed, 09 Mar 2016 19:51:23 +0300

author
vkempik
date
Wed, 09 Mar 2016 19:51:23 +0300
changeset 8319
0cd040567d60
parent 8307
daaf806995b3
child 8331
e443d4e588a3
permissions
-rw-r--r--

8151522: Disable 8130150 and 8081778 intrinsics by default
Reviewed-by: kvn

igerasim@8307 1 /*
igerasim@8307 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
igerasim@8307 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
igerasim@8307 4 *
igerasim@8307 5 * This code is free software; you can redistribute it and/or modify it
igerasim@8307 6 * under the terms of the GNU General Public License version 2 only, as
igerasim@8307 7 * published by the Free Software Foundation.
igerasim@8307 8 *
igerasim@8307 9 * This code is distributed in the hope that it will be useful, but WITHOUT
igerasim@8307 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
igerasim@8307 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
igerasim@8307 12 * version 2 for more details (a copy is included in the LICENSE file that
igerasim@8307 13 * accompanied this code).
igerasim@8307 14 *
igerasim@8307 15 * You should have received a copy of the GNU General Public License version
igerasim@8307 16 * 2 along with this work; if not, write to the Free Software Foundation,
igerasim@8307 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
igerasim@8307 18 *
igerasim@8307 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
igerasim@8307 20 * or visit www.oracle.com if you need additional information or have any
igerasim@8307 21 * questions.
igerasim@8307 22 *
igerasim@8307 23 */
igerasim@8307 24
igerasim@8307 25 /**
igerasim@8307 26 * @test
igerasim@8307 27 * @bug 8081778
igerasim@8307 28 * @summary Add C2 x86 intrinsic for BigInteger::squareToLen() method
igerasim@8307 29 *
igerasim@8307 30 * @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
vkempik@8319 31 * -XX:+UseSquareToLenIntrinsic
igerasim@8307 32 * -XX:CompileCommand=exclude,TestSquareToLen::main
igerasim@8307 33 * -XX:CompileCommand=option,TestSquareToLen::base_multiply,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 34 * -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 35 * -XX:CompileCommand=option,java.math.BigInteger::square,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 36 * -XX:CompileCommand=option,java.math.BigInteger::squareToLen,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 37 * -XX:CompileCommand=inline,java.math.BigInteger::multiply
igerasim@8307 38 * -XX:CompileCommand=inline,java.math.BigInteger::square
igerasim@8307 39 * -XX:CompileCommand=inline,java.math.BigInteger::squareToLen TestSquareToLen
igerasim@8307 40 */
igerasim@8307 41
igerasim@8307 42 import java.util.Random;
igerasim@8307 43 import java.math.*;
igerasim@8307 44
igerasim@8307 45 public class TestSquareToLen {
igerasim@8307 46
igerasim@8307 47 // Avoid intrinsic by preventing inlining multiply() and squareToLen().
igerasim@8307 48 public static BigInteger base_multiply(BigInteger op1) {
igerasim@8307 49 return op1.multiply(op1);
igerasim@8307 50 }
igerasim@8307 51
igerasim@8307 52 // Generate squareToLen() intrinsic by inlining multiply().
igerasim@8307 53 public static BigInteger new_multiply(BigInteger op1) {
igerasim@8307 54 return op1.multiply(op1);
igerasim@8307 55 }
igerasim@8307 56
igerasim@8307 57 public static boolean bytecompare(BigInteger b1, BigInteger b2) {
igerasim@8307 58 byte[] data1 = b1.toByteArray();
igerasim@8307 59 byte[] data2 = b2.toByteArray();
igerasim@8307 60 if (data1.length != data2.length)
igerasim@8307 61 return false;
igerasim@8307 62 for (int i = 0; i < data1.length; i++) {
igerasim@8307 63 if (data1[i] != data2[i])
igerasim@8307 64 return false;
igerasim@8307 65 }
igerasim@8307 66 return true;
igerasim@8307 67 }
igerasim@8307 68
igerasim@8307 69 public static String stringify(BigInteger b) {
igerasim@8307 70 String strout= "";
igerasim@8307 71 byte [] data = b.toByteArray();
igerasim@8307 72 for (int i = 0; i < data.length; i++) {
igerasim@8307 73 strout += (String.format("%02x",data[i]) + " ");
igerasim@8307 74 }
igerasim@8307 75 return strout;
igerasim@8307 76 }
igerasim@8307 77
igerasim@8307 78 public static void main(String args[]) throws Exception {
igerasim@8307 79
igerasim@8307 80 BigInteger oldsum = new BigInteger("0");
igerasim@8307 81 BigInteger newsum = new BigInteger("0");
igerasim@8307 82
igerasim@8307 83 BigInteger b1, b2, oldres, newres;
igerasim@8307 84
igerasim@8307 85 Random rand = new Random();
igerasim@8307 86 long seed = System.nanoTime();
igerasim@8307 87 Random rand1 = new Random();
igerasim@8307 88 long seed1 = System.nanoTime();
igerasim@8307 89 rand.setSeed(seed);
igerasim@8307 90 rand1.setSeed(seed1);
igerasim@8307 91
igerasim@8307 92 for (int j = 0; j < 100000; j++) {
igerasim@8307 93 int rand_int = rand1.nextInt(3136)+32;
igerasim@8307 94 b1 = new BigInteger(rand_int, rand);
igerasim@8307 95
igerasim@8307 96 oldres = base_multiply(b1);
igerasim@8307 97 newres = new_multiply(b1);
igerasim@8307 98
igerasim@8307 99 oldsum = oldsum.add(oldres);
igerasim@8307 100 newsum = newsum.add(newres);
igerasim@8307 101
igerasim@8307 102 if (!bytecompare(oldres,newres)) {
igerasim@8307 103 System.out.print("mismatch for:b1:" + stringify(b1) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
igerasim@8307 104 System.out.println(b1);
igerasim@8307 105 throw new Exception("Failed");
igerasim@8307 106 }
igerasim@8307 107 }
igerasim@8307 108 if (!bytecompare(oldsum,newsum)) {
igerasim@8307 109 System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
igerasim@8307 110 throw new Exception("Failed");
igerasim@8307 111 } else {
igerasim@8307 112 System.out.println("Success");
igerasim@8307 113 }
igerasim@8307 114 }
igerasim@8307 115 }

mercurial