annotate test/compiler/6921969/TestMultiplyLongHiZero.java @ 2221:0aa3b4908911 jdk7-b131

Merge
author cl
date Wed, 23 Feb 2011 15:48:46 -0800
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1209
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
1 /*
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
2 * Copyright 2010 Google, Inc. All Rights Reserved.
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
4 *
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
7 * published by the Free Software Foundation.
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
8 *
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
13 * accompanied this code).
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
14 *
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1209
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1209
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1209
diff changeset
21 * questions.
1209
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
22 *
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
23 */
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
24
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
25 /*
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
26 * @test
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
27 * @bug 6921969
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
28 * @summary Tests shorter long multiply sequences when the high 32 bits of long operands are known to be zero on x86_32
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
29 * @run main/othervm -Xbatch -XX:-Inline -XX:CompileOnly=.testNormal,.testLeftOptimized,.testRightOptimized,.testOptimized,.testLeftOptimized_LoadUI2L,.testRightOptimized_LoadUI2L,.testOptimized_LoadUI2L TestMultiplyLongHiZero
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
30 */
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
31
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
32 // This test must run without any command line arguments.
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
33
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
34 public class TestMultiplyLongHiZero {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
35
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
36 private static void check(long leftFactor, long rightFactor, long optimizedProduct, long constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
37 long normalProduct = leftFactor * rightFactor; // unaffected by the new optimization
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
38 if (optimizedProduct != constantProduct || normalProduct != constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
39 throw new RuntimeException("Not all three products are equal: " +
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
40 Long.toHexString(normalProduct) + ", " +
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
41 Long.toHexString(optimizedProduct) + ", " +
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
42 Long.toHexString(constantProduct));
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
43 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
44 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
45
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
46 private static int initInt(String[] args, int v) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
47 if (args.length > 0) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
48 try {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
49 return Integer.valueOf(args[0]);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
50 } catch (NumberFormatException e) { }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
51 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
52 return v;
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
53 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
54
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
55 private static final long mask32 = 0x00000000FFFFFFFFL;
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
56
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
57 private static void testNormal(int leftFactor, int rightFactor, long constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
58 check((long) leftFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
59 (long) rightFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
60 (long) leftFactor * (long) rightFactor, // unaffected by the new optimization
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
61 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
62 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
63
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
64 private static void testLeftOptimized(int leftFactor, int rightFactor, long constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
65 check((leftFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
66 (long) rightFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
67 (leftFactor & mask32) * (long) rightFactor, // left factor optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
68 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
69 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
70
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
71 private static void testRightOptimized(int leftFactor, int rightFactor, long constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
72 check((long) leftFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
73 (rightFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
74 (long) leftFactor * (rightFactor & mask32), // right factor optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
75 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
76 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
77
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
78 private static void testOptimized(int leftFactor, int rightFactor, long constantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
79 check((leftFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
80 (rightFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
81 (leftFactor & mask32) * (rightFactor & mask32), // both factors optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
82 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
83 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
84
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
85 private static void testLeftOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
86 check((leftFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
87 (long) rightFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
88 (factors[0] & mask32) * (long) rightFactor, // left factor optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
89 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
90 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
91
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
92 private static void testRightOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
93 check((long) leftFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
94 (rightFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
95 (long) leftFactor * (factors[1] & mask32), // right factor optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
96 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
97 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
98
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
99 private static void testOptimized_LoadUI2L(int leftFactor, int rightFactor, long constantProduct, int[] factors) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
100 check((leftFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
101 (rightFactor & mask32),
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
102 (factors[0] & mask32) * (factors[1] & mask32), // both factors optimized
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
103 constantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
104 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
105
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
106 private static void test(int leftFactor, int rightFactor,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
107 long normalConstantProduct,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
108 long leftOptimizedConstantProduct,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
109 long rightOptimizedConstantProduct,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
110 long optimizedConstantProduct) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
111 int[] factors = new int[2];
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
112 factors[0] = leftFactor;
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
113 factors[1] = rightFactor;
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
114 testNormal(leftFactor, rightFactor, normalConstantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
115 testLeftOptimized(leftFactor, rightFactor, leftOptimizedConstantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
116 testRightOptimized(leftFactor, rightFactor, rightOptimizedConstantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
117 testOptimized(leftFactor, rightFactor, optimizedConstantProduct);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
118 testLeftOptimized_LoadUI2L(leftFactor, rightFactor, leftOptimizedConstantProduct, factors);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
119 testRightOptimized_LoadUI2L(leftFactor, rightFactor, rightOptimizedConstantProduct, factors);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
120 testOptimized_LoadUI2L(leftFactor, rightFactor, optimizedConstantProduct, factors);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
121 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
122
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
123 public static void main(String[] args) {
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
124 for (int i = 0; i < 100000; ++i) { // Trigger compilation
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
125 int i0 = initInt(args, 1);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
126 int i1 = initInt(args, 3);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
127 int i2 = initInt(args, -1);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
128 int i3 = initInt(args, 0x7FFFFFFF);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
129 test(i0, i1, 3L, 3L, 3L, 3L);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
130 test(i0, i2, -1L, -1L, 0xFFFFFFFFL, 0xFFFFFFFFL);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
131 test(i0, i3, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
132 test(i1, i2, -3L, -3L, 0x2FFFFFFFDL, 0x2FFFFFFFDL);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
133 test(i1, i3, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
134 test(i2, i3, 0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L,
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
135 0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L);
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
136 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
137 }
e8443c7be117 6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff changeset
138 }