author | prr |
Thu, 25 Apr 2013 16:49:54 -0700 | |
changeset 18254 | e4083179f1c9 |
parent 5547 | f4b087cbb361 |
permissions | -rw-r--r-- |
4757
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
1 |
/* |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
2 |
* Copyright 2010 Google, Inc. All Rights Reserved. |
1fe15ef4fc8a
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. |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
4 |
* |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
8 |
* |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
13 |
* accompanied this code). |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
14 |
* |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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, |
1fe15ef4fc8a
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. |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
18 |
* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4757
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4757
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4757
diff
changeset
|
21 |
* questions. |
4757
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
22 |
* |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
23 |
*/ |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
24 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
25 |
/* |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
26 |
* @test |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
27 |
* @bug 6921969 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
30 |
*/ |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
31 |
|
1fe15ef4fc8a
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. |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
33 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
34 |
public class TestMultiplyLongHiZero { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
35 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
38 |
if (optimizedProduct != constantProduct || normalProduct != constantProduct) { |
1fe15ef4fc8a
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: " + |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
40 |
Long.toHexString(normalProduct) + ", " + |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
41 |
Long.toHexString(optimizedProduct) + ", " + |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
42 |
Long.toHexString(constantProduct)); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
43 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
44 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
45 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
46 |
private static int initInt(String[] args, int v) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
47 |
if (args.length > 0) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
48 |
try { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
49 |
return Integer.valueOf(args[0]); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
50 |
} catch (NumberFormatException e) { } |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
51 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
52 |
return v; |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
53 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
54 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
55 |
private static final long mask32 = 0x00000000FFFFFFFFL; |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
56 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
58 |
check((long) leftFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
59 |
(long) rightFactor, |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
61 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
62 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
63 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
65 |
check((leftFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
66 |
(long) rightFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
67 |
(leftFactor & mask32) * (long) rightFactor, // left factor optimized |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
68 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
69 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
70 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
72 |
check((long) leftFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
73 |
(rightFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
74 |
(long) leftFactor * (rightFactor & mask32), // right factor optimized |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
75 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
76 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
77 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
79 |
check((leftFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
80 |
(rightFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
81 |
(leftFactor & mask32) * (rightFactor & mask32), // both factors optimized |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
82 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
83 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
84 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
86 |
check((leftFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
87 |
(long) rightFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
88 |
(factors[0] & mask32) * (long) rightFactor, // left factor optimized |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
89 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
90 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
91 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
93 |
check((long) leftFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
94 |
(rightFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
95 |
(long) leftFactor * (factors[1] & mask32), // right factor optimized |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
96 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
97 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
98 |
|
1fe15ef4fc8a
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) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
100 |
check((leftFactor & mask32), |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
101 |
(rightFactor & mask32), |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
103 |
constantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
104 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
105 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
106 |
private static void test(int leftFactor, int rightFactor, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
107 |
long normalConstantProduct, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
108 |
long leftOptimizedConstantProduct, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
109 |
long rightOptimizedConstantProduct, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
110 |
long optimizedConstantProduct) { |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
111 |
int[] factors = new int[2]; |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
112 |
factors[0] = leftFactor; |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
113 |
factors[1] = rightFactor; |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
114 |
testNormal(leftFactor, rightFactor, normalConstantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
115 |
testLeftOptimized(leftFactor, rightFactor, leftOptimizedConstantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
116 |
testRightOptimized(leftFactor, rightFactor, rightOptimizedConstantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
117 |
testOptimized(leftFactor, rightFactor, optimizedConstantProduct); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
118 |
testLeftOptimized_LoadUI2L(leftFactor, rightFactor, leftOptimizedConstantProduct, factors); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
119 |
testRightOptimized_LoadUI2L(leftFactor, rightFactor, rightOptimizedConstantProduct, factors); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
120 |
testOptimized_LoadUI2L(leftFactor, rightFactor, optimizedConstantProduct, factors); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
121 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
122 |
|
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
123 |
public static void main(String[] args) { |
1fe15ef4fc8a
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 |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
125 |
int i0 = initInt(args, 1); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
126 |
int i1 = initInt(args, 3); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
127 |
int i2 = initInt(args, -1); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
128 |
int i3 = initInt(args, 0x7FFFFFFF); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
129 |
test(i0, i1, 3L, 3L, 3L, 3L); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
130 |
test(i0, i2, -1L, -1L, 0xFFFFFFFFL, 0xFFFFFFFFL); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
131 |
test(i0, i3, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL, 0x7FFFFFFFL); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
132 |
test(i1, i2, -3L, -3L, 0x2FFFFFFFDL, 0x2FFFFFFFDL); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
133 |
test(i1, i3, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL, 0x17FFFFFFDL); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
134 |
test(i2, i3, 0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L, |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
135 |
0xFFFFFFFF80000001L, 0x7FFFFFFE80000001L); |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
136 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
137 |
} |
1fe15ef4fc8a
6921969: optimize 64 long multiply for case with high bits zero
never
parents:
diff
changeset
|
138 |
} |