< prev index next >

test/compiler/intrinsics/multiplytolen/TestMultiplyToLen.java

Print this page




  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 /**
  26  * @test
  27  * @bug 8055494
  28  * @summary Add C2 x86 intrinsic for BigInteger::multiplyToLen() method
  29  *
  30  * @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
  31  *      -XX:CompileCommand=exclude,TestMultiplyToLen::main
  32  *      -XX:CompileCommand=option,TestMultiplyToLen::base_multiply,ccstr,DisableIntrinsic,_multiplyToLen
  33  *      -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_multiplyToLen
  34  *      -XX:CompileCommand=inline,java.math.BigInteger::multiply TestMultiplyToLen
  35  */
  36 

  37 import java.util.Random;
  38 import java.math.*;
  39 
  40 public class TestMultiplyToLen {
  41 
  42     // Avoid intrinsic by preventing inlining multiply() and multiplyToLen().
  43     public static BigInteger base_multiply(BigInteger op1, BigInteger op2) {
  44       return op1.multiply(op2);
  45     }
  46 
  47     // Generate multiplyToLen() intrinsic by inlining multiply().
  48     public static BigInteger new_multiply(BigInteger op1, BigInteger op2) {
  49       return op1.multiply(op2);
  50     }
  51 
  52     public static boolean bytecompare(BigInteger b1, BigInteger b2) {
  53       byte[] data1 = b1.toByteArray();
  54       byte[] data2 = b2.toByteArray();
  55       if (data1.length != data2.length)
  56         return false;


  80       Random rand = new Random();
  81       long seed = System.nanoTime();
  82       Random rand1 = new Random();
  83       long seed1 = System.nanoTime();
  84       rand.setSeed(seed);
  85       rand1.setSeed(seed1);
  86 
  87       for (int j = 0; j < 1000000; j++) {
  88         int rand_int = rand1.nextInt(3136)+32;
  89         int rand_int1 = rand1.nextInt(3136)+32;
  90         b1 = new BigInteger(rand_int, rand);
  91         b2 = new BigInteger(rand_int1, rand);
  92 
  93         oldres = base_multiply(b1,b2);
  94         newres = new_multiply(b1,b2);
  95 
  96         oldsum = oldsum.add(oldres);
  97         newsum = newsum.add(newres);
  98 
  99         if (!bytecompare(oldres,newres)) {























 100           System.out.print("mismatch for:b1:" + stringify(b1) + " :b2:" + stringify(b2) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
 101           System.out.println(b1);
 102           System.out.println(b2);
 103           throw new Exception("Failed");
 104         }
 105       }

 106       if (!bytecompare(oldsum,newsum))  {
 107         System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
 108         throw new Exception("Failed");
 109       } else {
 110         System.out.println("Success");
 111       }
 112    }
 113 }


  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 /**
  26  * @test
  27  * @bug 8055494
  28  * @summary Add C2 x86 intrinsic for BigInteger::multiplyToLen() method
  29  *
  30  * @run main/othervm/timeout=600 -XX:-TieredCompilation -Xbatch
  31  *      -XX:CompileCommand=exclude,TestMultiplyToLen::main
  32  *      -XX:CompileCommand=option,TestMultiplyToLen::base_multiply,ccstr,DisableIntrinsic,_multiplyToLen
  33  *      -XX:CompileCommand=option,java.math.BigInteger::multiply,ccstr,DisableIntrinsic,_multiplyToLen
  34  *      -XX:CompileCommand=inline,java.math.BigInteger::multiply TestMultiplyToLen
  35  */
  36 
  37 import java.util.Arrays;
  38 import java.util.Random;
  39 import java.math.*;
  40 
  41 public class TestMultiplyToLen {
  42 
  43     // Avoid intrinsic by preventing inlining multiply() and multiplyToLen().
  44     public static BigInteger base_multiply(BigInteger op1, BigInteger op2) {
  45       return op1.multiply(op2);
  46     }
  47 
  48     // Generate multiplyToLen() intrinsic by inlining multiply().
  49     public static BigInteger new_multiply(BigInteger op1, BigInteger op2) {
  50       return op1.multiply(op2);
  51     }
  52 
  53     public static boolean bytecompare(BigInteger b1, BigInteger b2) {
  54       byte[] data1 = b1.toByteArray();
  55       byte[] data2 = b2.toByteArray();
  56       if (data1.length != data2.length)
  57         return false;


  81       Random rand = new Random();
  82       long seed = System.nanoTime();
  83       Random rand1 = new Random();
  84       long seed1 = System.nanoTime();
  85       rand.setSeed(seed);
  86       rand1.setSeed(seed1);
  87 
  88       for (int j = 0; j < 1000000; j++) {
  89         int rand_int = rand1.nextInt(3136)+32;
  90         int rand_int1 = rand1.nextInt(3136)+32;
  91         b1 = new BigInteger(rand_int, rand);
  92         b2 = new BigInteger(rand_int1, rand);
  93 
  94         oldres = base_multiply(b1,b2);
  95         newres = new_multiply(b1,b2);
  96 
  97         oldsum = oldsum.add(oldres);
  98         newsum = newsum.add(newres);
  99 
 100         if (!bytecompare(oldres,newres)) {
 101           System.out.println(b1);
 102           System.out.println(b2);
 103           System.out.print("mismatch for:b1:" + stringify(b1) + " :b2:" + stringify(b2) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
 104           throw new Exception("Failed");
 105         }
 106       }
 107 
 108       // Test carry propagation.  Multiple carries during bignum
 109       // multiplication are rare (especially when using 64-bit
 110       // arithmetic) so we have to provoke them deliberately.
 111       for (int j = 4; j <= 396; j += 4) {
 112         byte[] bytes = new byte[j];
 113         Arrays.fill(bytes, (byte)255);
 114         b1 = new BigInteger(bytes);
 115         b2 = new BigInteger(bytes);
 116 
 117         oldres = base_multiply(b1,b2);
 118         newres = new_multiply(b1,b2);
 119 
 120         oldsum = oldsum.add(oldres);
 121         newsum = newsum.add(newres);
 122 
 123         if (!bytecompare(oldres,newres)) {
 124           System.out.print("mismatch for:b1:" + stringify(b1) + " :b2:" + stringify(b2) + " :oldres:" + stringify(oldres) + " :newres:" + stringify(newres));
 125           System.out.println(b1);
 126           System.out.println(b2);
 127           throw new Exception("Failed");
 128         }
 129       }
 130 
 131       if (!bytecompare(oldsum,newsum))  {
 132         System.out.println("Failure: oldsum:" + stringify(oldsum) + " newsum:" + stringify(newsum));
 133         throw new Exception("Failed");
 134       } else {
 135         System.out.println("Success");
 136       }
 137    }
 138 }
< prev index next >