10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
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 * @test
26 * @bug 6823354
27 * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
28 * @modules java.base/jdk.internal.misc
29 * @library /testlibrary
30 * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
31 */
32
33 import jdk.test.lib.Utils;
34
35 public class Test6823354 {
36 // Arrays of corner case values.
37 static final int[] ia = new int[] { 0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE };
38 static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE };
39
40 public static void main(String[] args) throws Exception {
41 // Load the classes and the methods.
42 Integer.numberOfLeadingZeros(0);
43 Integer.numberOfTrailingZeros(0);
44 Long.numberOfLeadingZeros(0);
45 Long.numberOfTrailingZeros(0);
46
47 lz();
48 tz();
49 }
50
51 static void lz() throws Exception {
52 // int
53
54 // Test corner cases.
55 for (int i = 0; i < ia.length; i++) {
56 int x = ia[i];
57 check(x, lzcomp(x), lzint(x));
58 }
59
60 // Test all possible return values.
61 for (int i = 0; i < Integer.SIZE; i++) {
62 int x = 1 << i;
63 check(x, lzcomp(x), lzint(x));
64 }
65
66 String classname = "Test6823354$lzconI";
67
68 // Test Ideal optimizations (constant values).
69 for (int i = 0; i < ia.length; i++) {
70 testclass(classname, ia[i]);
71 }
72
73 // Test Ideal optimizations (constant values).
74 for (int i = 0; i < Integer.SIZE; i++) {
75 int x = 1 << i;
76 testclass(classname, x);
77 }
78
79
80 // long
81
82 // Test corner cases.
83 for (int i = 0; i < ia.length; i++) {
84 long x = la[i];
85 check(x, lzcomp(x), lzint(x));
86 }
87
88 // Test all possible return values.
89 for (int i = 0; i < Long.SIZE; i++) {
90 long x = 1L << i;
91 check(x, lzcomp(x), lzint(x));
92 }
93
94 classname = "Test6823354$lzconL";
95
96 // Test Ideal optimizations (constant values).
97 for (int i = 0; i < la.length; i++) {
98 testclass(classname, la[i]);
99 }
100
101 // Test Ideal optimizations (constant values).
102 for (int i = 0; i < Long.SIZE; i++) {
103 long x = 1L << i;
104 testclass(classname, x);
105 }
106 }
107
108 static void tz() throws Exception {
109 // int
110
111 // Test corner cases.
112 for (int i = 0; i < ia.length; i++) {
113 int x = ia[i];
114 check(x, tzcomp(x), tzint(x));
115 }
116
117 // Test all possible return values.
118 for (int i = 0; i < Integer.SIZE; i++) {
119 int x = 1 << i;
120 check(x, tzcomp(x), tzint(x));
121 }
122
123 String classname = "Test6823354$tzconI";
124
125 // Test Ideal optimizations (constant values).
126 for (int i = 0; i < ia.length; i++) {
127 testclass(classname, ia[i]);
128 }
129
130 // Test Ideal optimizations (constant values).
131 for (int i = 0; i < Integer.SIZE; i++) {
132 int x = 1 << i;
133 testclass(classname, x);
134 }
135
136
137 // long
138
139 // Test corner cases.
140 for (int i = 0; i < la.length; i++) {
141 long x = la[i];
142 check(x, tzcomp(x), tzint(x));
143 }
144
145 // Test all possible return values.
146 for (int i = 0; i < Long.SIZE; i++) {
147 long x = 1L << i;
148 check(x, tzcomp(x), tzint(x));
149 }
150
151 classname = "Test6823354$tzconL";
152
153 // Test Ideal optimizations (constant values).
154 for (int i = 0; i < la.length; i++) {
155 testclass(classname, la[i]);
156 }
157
158 // Test Ideal optimizations (constant values).
159 for (int i = 0; i < Long.SIZE; i++) {
160 long x = 1L << i;
161 testclass(classname, x);
162 }
163 }
164
165 static void check(int value, int result, int expected) {
166 //System.out.println(value + ": " + result + ", " + expected);
167 if (result != expected)
168 throw new InternalError(value + " failed: " + result + " != " + expected);
169 }
170
171 static void check(long value, long result, long expected) {
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
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 * @test
26 * @bug 6823354
27 * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
28 * @modules java.base/jdk.internal.misc
29 * @library /testlibrary
30 *
31 * @run main/othervm -Xcomp
32 * -XX:CompileCommand=compileonly,compiler.codegen.Test6823354::lzcomp
33 * -XX:CompileCommand=compileonly,compiler.codegen.Test6823354::tzcomp
34 * -XX:CompileCommand=compileonly,compiler.codegen.*::dolzcomp
35 * -XX:CompileCommand=compileonly,compiler.codegen.*::dotzcomp
36 * compiler.codegen.Test6823354
37 */
38
39 package compiler.codegen;
40
41 import jdk.test.lib.Utils;
42
43 public class Test6823354 {
44 // Arrays of corner case values.
45 static final int[] ia = new int[] { 0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE };
46 static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE };
47
48 public static void main(String[] args) throws Exception {
49 // Load the classes and the methods.
50 Integer.numberOfLeadingZeros(0);
51 Integer.numberOfTrailingZeros(0);
52 Long.numberOfLeadingZeros(0);
53 Long.numberOfTrailingZeros(0);
54
55 lz();
56 tz();
57 }
58
59 static void lz() throws Exception {
60 // int
61
62 // Test corner cases.
63 for (int i = 0; i < ia.length; i++) {
64 int x = ia[i];
65 check(x, lzcomp(x), lzint(x));
66 }
67
68 // Test all possible return values.
69 for (int i = 0; i < Integer.SIZE; i++) {
70 int x = 1 << i;
71 check(x, lzcomp(x), lzint(x));
72 }
73
74 String classname = Test6823354.class.getName() + "$lzconI";
75
76 // Test Ideal optimizations (constant values).
77 for (int i = 0; i < ia.length; i++) {
78 testclass(classname, ia[i]);
79 }
80
81 // Test Ideal optimizations (constant values).
82 for (int i = 0; i < Integer.SIZE; i++) {
83 int x = 1 << i;
84 testclass(classname, x);
85 }
86
87
88 // long
89
90 // Test corner cases.
91 for (int i = 0; i < ia.length; i++) {
92 long x = la[i];
93 check(x, lzcomp(x), lzint(x));
94 }
95
96 // Test all possible return values.
97 for (int i = 0; i < Long.SIZE; i++) {
98 long x = 1L << i;
99 check(x, lzcomp(x), lzint(x));
100 }
101
102 classname = Test6823354.class.getName() + "$lzconL";
103
104 // Test Ideal optimizations (constant values).
105 for (int i = 0; i < la.length; i++) {
106 testclass(classname, la[i]);
107 }
108
109 // Test Ideal optimizations (constant values).
110 for (int i = 0; i < Long.SIZE; i++) {
111 long x = 1L << i;
112 testclass(classname, x);
113 }
114 }
115
116 static void tz() throws Exception {
117 // int
118
119 // Test corner cases.
120 for (int i = 0; i < ia.length; i++) {
121 int x = ia[i];
122 check(x, tzcomp(x), tzint(x));
123 }
124
125 // Test all possible return values.
126 for (int i = 0; i < Integer.SIZE; i++) {
127 int x = 1 << i;
128 check(x, tzcomp(x), tzint(x));
129 }
130
131 String classname = Test6823354.class.getName() + "$tzconI";
132
133 // Test Ideal optimizations (constant values).
134 for (int i = 0; i < ia.length; i++) {
135 testclass(classname, ia[i]);
136 }
137
138 // Test Ideal optimizations (constant values).
139 for (int i = 0; i < Integer.SIZE; i++) {
140 int x = 1 << i;
141 testclass(classname, x);
142 }
143
144
145 // long
146
147 // Test corner cases.
148 for (int i = 0; i < la.length; i++) {
149 long x = la[i];
150 check(x, tzcomp(x), tzint(x));
151 }
152
153 // Test all possible return values.
154 for (int i = 0; i < Long.SIZE; i++) {
155 long x = 1L << i;
156 check(x, tzcomp(x), tzint(x));
157 }
158
159 classname = Test6823354.class.getName() + "$tzconL";
160
161 // Test Ideal optimizations (constant values).
162 for (int i = 0; i < la.length; i++) {
163 testclass(classname, la[i]);
164 }
165
166 // Test Ideal optimizations (constant values).
167 for (int i = 0; i < Long.SIZE; i++) {
168 long x = 1L << i;
169 testclass(classname, x);
170 }
171 }
172
173 static void check(int value, int result, int expected) {
174 //System.out.println(value + ": " + result + ", " + expected);
175 if (result != expected)
176 throw new InternalError(value + " failed: " + result + " != " + expected);
177 }
178
179 static void check(long value, long result, long expected) {
|