1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/6921969/TestMultiplyLongHiZero.java Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,138 @@ 1.4 +/* 1.5 + * Copyright 2010 Google, Inc. 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 6921969 1.31 + * @summary Tests shorter long multiply sequences when the high 32 bits of long operands are known to be zero on x86_32 1.32 + * @run main/othervm -Xbatch -XX:-Inline -XX:CompileOnly=.testNormal,.testLeftOptimized,.testRightOptimized,.testOptimized,.testLeftOptimized_LoadUI2L,.testRightOptimized_LoadUI2L,.testOptimized_LoadUI2L TestMultiplyLongHiZero 1.33 + */ 1.34 + 1.35 +// This test must run without any command line arguments. 1.36 + 1.37 +public class TestMultiplyLongHiZero { 1.38 + 1.39 + private static void check(long leftFactor, long rightFactor, long optimizedProduct, long constantProduct) { 1.40 + long normalProduct = leftFactor * rightFactor; // unaffected by the new optimization 1.41 + if (optimizedProduct != constantProduct || normalProduct != constantProduct) { 1.42 + throw new RuntimeException("Not all three products are equal: " + 1.43 + Long.toHexString(normalProduct) + ", " + 1.44 + Long.toHexString(optimizedProduct) + ", " + 1.45 + Long.toHexString(constantProduct)); 1.46 + } 1.47 + } 1.48 + 1.49 + private static int initInt(String[] args, int v) { 1.50 + if (args.length > 0) { 1.51 + try { 1.52 + return Integer.valueOf(args[0]); 1.53 + } catch (NumberFormatException e) { } 1.54 + } 1.55 + return v; 1.56 + } 1.57 + 1.58 + private static final long mask32 = 0x00000000FFFFFFFFL; 1.59 + 1.60 + private static void testNormal(int leftFactor, int rightFactor, long constantProduct) { 1.61 + check((long) leftFactor, 1.62 + (long) rightFactor, 1.63 + (long) leftFactor * (long) rightFactor, // unaffected by the new optimization 1.64 + constantProduct); 1.65 + } 1.66 + 1.67 + private static void testLeftOptimized(int leftFactor, int rightFactor, long constantProduct) { 1.68 + check((leftFactor & mask32), 1.69 + (long) rightFactor, 1.70 + (leftFactor & mask32) * (long) rightFactor, // left factor optimized 1.71 + constantProduct); 1.72 + } 1.73 + 1.74 + private static void testRightOptimized(int leftFactor, int rightFactor, long constantProduct) { 1.75 + check((long) leftFactor, 1.76 + (rightFactor & mask32), 1.77 + (long) leftFactor * (rightFactor & mask32), // right factor optimized 1.78 + constantProduct); 1.79 + } 1.80 + 1.81 + private static void testOptimized(int leftFactor, int rightFactor, long constantProduct) { 1.82 + check((leftFactor & mask32), 1.83 + (rightFactor & mask32), 1.84 + (leftFactor & mask32) * (rightFactor & mask32), // both factors optimized 1.85 + constantProduct); 1.86 + } 1.87 + 1.88 + private static void testLeftOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) { 1.89 + check((leftFactor & mask32), 1.90 + (long) rightFactor, 1.91 + (factors[0] & mask32) * (long) rightFactor, // left factor optimized 1.92 + constantProduct); 1.93 + } 1.94 + 1.95 + private static void testRightOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) { 1.96 + check((long) leftFactor, 1.97 + (rightFactor & mask32), 1.98 + (long) leftFactor * (factors[1] & mask32), // right factor optimized 1.99 + constantProduct); 1.100 + } 1.101 + 1.102 + private static void testOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) { 1.103 + check((leftFactor & mask32), 1.104 + (rightFactor & mask32), 1.105 + (factors[0] & mask32) * (factors[1] & mask32), // both factors optimized 1.106 + constantProduct); 1.107 + } 1.108 + 1.109 + private static void test(int leftFactor, int rightFactor, 1.110 + long normalConstantProduct, 1.111 + long leftOptimizedConstantProduct, 1.112 + long rightOptimizedConstantProduct, 1.113 + long optimizedConstantProduct) { 1.114 + int[] factors = new int[2]; 1.115 + factors[0] = leftFactor; 1.116 + factors[1] = rightFactor; 1.117 + testNormal(leftFactor, rightFactor, normalConstantProduct); 1.118 + testLeftOptimized(leftFactor, rightFactor, leftOptimizedConstantProduct); 1.119 + testRightOptimized(leftFactor, rightFactor, rightOptimizedConstantProduct); 1.120 + testOptimized(leftFactor, rightFactor, optimizedConstantProduct); 1.121 + testLeftOptimized_LoadUI2L(leftFactor, rightFactor, leftOptimizedConstantProduct, factors); 1.122 + testRightOptimized_LoadUI2L(leftFactor, rightFactor, rightOptimizedConstantProduct, factors); 1.123 + testOptimized_LoadUI2L(leftFactor, rightFactor, optimizedConstantProduct, factors); 1.124 + } 1.125 + 1.126 + public static void main(String[] args) { 1.127 + for (int i = 0; i < 100000; ++i) { // Trigger compilation 1.128 + int i0 = initInt(args, 1); 1.129 + int i1 = initInt(args, 3); 1.130 + int i2 = initInt(args, -1); 1.131 + int i3 = initInt(args, 0x7FFFFFFF); 1.132 + test(i0, i1, 3L, 3L, 3L, 3L); 1.133 + test(i0, i2, -1L, -1L, 0xFFFFFFFFL, 0xFFFFFFFFL); 1.134 + test(i0, i3, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL); 1.135 + test(i1, i2, -3L, -3L, 0x2FFFFFFFDL, 0x2FFFFFFFDL); 1.136 + test(i1, i3, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL); 1.137 + test(i2, i3, 0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L, 1.138 + 0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L); 1.139 + } 1.140 + } 1.141 +}