test/compiler/intrinsics/squaretolen/TestSquareToLen.java

Fri, 18 Mar 2016 17:23:07 +0300

author
vkempik
date
Fri, 18 Mar 2016 17:23:07 +0300
changeset 8331
e443d4e588a3
parent 8319
0cd040567d60
permissions
-rw-r--r--

8152098: Fix 8151522 caused test compiler/intrinsics/squaretolen/TestSquareToLen.java to fail
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@8331 31 * -XX:+IgnoreUnrecognizedVMOptions
vkempik@8319 32 * -XX:+UseSquareToLenIntrinsic
igerasim@8307 33 * -XX:CompileCommand=exclude,TestSquareToLen::main
igerasim@8307 34 * -XX:CompileCommand=option,TestSquareToLen::base_multiply,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 35 * -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 36 * -XX:CompileCommand=option,java.math.BigInteger::square,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 37 * -XX:CompileCommand=option,java.math.BigInteger::squareToLen,ccstr,DisableIntrinsic,_squareToLen
igerasim@8307 38 * -XX:CompileCommand=inline,java.math.BigInteger::multiply
igerasim@8307 39 * -XX:CompileCommand=inline,java.math.BigInteger::square
igerasim@8307 40 * -XX:CompileCommand=inline,java.math.BigInteger::squareToLen TestSquareToLen
igerasim@8307 41 */
igerasim@8307 42
igerasim@8307 43 import java.util.Random;
igerasim@8307 44 import java.math.*;
igerasim@8307 45
igerasim@8307 46 public class TestSquareToLen {
igerasim@8307 47
igerasim@8307 48 // Avoid intrinsic by preventing inlining multiply() and squareToLen().
igerasim@8307 49 public static BigInteger base_multiply(BigInteger op1) {
igerasim@8307 50 return op1.multiply(op1);
igerasim@8307 51 }
igerasim@8307 52
igerasim@8307 53 // Generate squareToLen() intrinsic by inlining multiply().
igerasim@8307 54 public static BigInteger new_multiply(BigInteger op1) {
igerasim@8307 55 return op1.multiply(op1);
igerasim@8307 56 }
igerasim@8307 57
igerasim@8307 58 public static boolean bytecompare(BigInteger b1, BigInteger b2) {
igerasim@8307 59 byte[] data1 = b1.toByteArray();
igerasim@8307 60 byte[] data2 = b2.toByteArray();
igerasim@8307 61 if (data1.length != data2.length)
igerasim@8307 62 return false;
igerasim@8307 63 for (int i = 0; i < data1.length; i++) {
igerasim@8307 64 if (data1[i] != data2[i])
igerasim@8307 65 return false;
igerasim@8307 66 }
igerasim@8307 67 return true;
igerasim@8307 68 }
igerasim@8307 69
igerasim@8307 70 public static String stringify(BigInteger b) {
igerasim@8307 71 String strout= "";
igerasim@8307 72 byte [] data = b.toByteArray();
igerasim@8307 73 for (int i = 0; i < data.length; i++) {
igerasim@8307 74 strout += (String.format("%02x",data[i]) + " ");
igerasim@8307 75 }
igerasim@8307 76 return strout;
igerasim@8307 77 }
igerasim@8307 78
igerasim@8307 79 public static void main(String args[]) throws Exception {
igerasim@8307 80
igerasim@8307 81 BigInteger oldsum = new BigInteger("0");
igerasim@8307 82 BigInteger newsum = new BigInteger("0");
igerasim@8307 83
igerasim@8307 84 BigInteger b1, b2, oldres, newres;
igerasim@8307 85
igerasim@8307 86 Random rand = new Random();
igerasim@8307 87 long seed = System.nanoTime();
igerasim@8307 88 Random rand1 = new Random();
igerasim@8307 89 long seed1 = System.nanoTime();
igerasim@8307 90 rand.setSeed(seed);
igerasim@8307 91 rand1.setSeed(seed1);
igerasim@8307 92
igerasim@8307 93 for (int j = 0; j < 100000; j++) {
igerasim@8307 94 int rand_int = rand1.nextInt(3136)+32;
igerasim@8307 95 b1 = new BigInteger(rand_int, rand);
igerasim@8307 96
igerasim@8307 97 oldres = base_multiply(b1);
igerasim@8307 98 newres = new_multiply(b1);
igerasim@8307 99
igerasim@8307 100 oldsum = oldsum.add(oldres);
igerasim@8307 101 newsum = newsum.add(newres);
igerasim@8307 102
igerasim@8307 103 if (!bytecompare(oldres,newres)) {
igerasim@8307 104 System.out.print("mismatch for:b1:" + stringify(b1) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
igerasim@8307 105 System.out.println(b1);
igerasim@8307 106 throw new Exception("Failed");
igerasim@8307 107 }
igerasim@8307 108 }
igerasim@8307 109 if (!bytecompare(oldsum,newsum)) {
igerasim@8307 110 System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
igerasim@8307 111 throw new Exception("Failed");
igerasim@8307 112 } else {
igerasim@8307 113 System.out.println("Success");
igerasim@8307 114 }
igerasim@8307 115 }
igerasim@8307 116 }

mercurial