1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/codegen/BMI1.java Wed Mar 12 11:24:26 2014 -0700 1.3 @@ -0,0 +1,301 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. 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 + * @test 1.29 + * @bug 8031321 1.30 + * @summary Support BMI1 instructions on x86/x64 1.31 + * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=compileonly,BMITests.* BMI1 1.32 + * 1.33 + */ 1.34 + 1.35 +class MemI { 1.36 + public int x; 1.37 + public MemI(int x) { this.x = x; } 1.38 +} 1.39 + 1.40 +class MemL { 1.41 + public long x; 1.42 + public MemL(long x) { this.x = x; } 1.43 +} 1.44 + 1.45 +class BMITests { 1.46 + static int andnl(int src1, int src2) { 1.47 + return ~src1 & src2; 1.48 + } 1.49 + static long andnq(long src1, long src2) { 1.50 + return ~src1 & src2; 1.51 + } 1.52 + static int andnl(int src1, MemI src2) { 1.53 + return ~src1 & src2.x; 1.54 + } 1.55 + static long andnq(long src1, MemL src2) { 1.56 + return ~src1 & src2.x; 1.57 + } 1.58 + static int blsil(int src1) { 1.59 + return src1 & -src1; 1.60 + } 1.61 + static long blsiq(long src1) { 1.62 + return src1 & -src1; 1.63 + } 1.64 + static int blsil(MemI src1) { 1.65 + return src1.x & -src1.x; 1.66 + } 1.67 + static long blsiq(MemL src1) { 1.68 + return src1.x & -src1.x; 1.69 + } 1.70 + static int blsmskl(int src1) { 1.71 + return (src1 - 1) ^ src1; 1.72 + } 1.73 + static long blsmskq(long src1) { 1.74 + return (src1 - 1) ^ src1; 1.75 + } 1.76 + static int blsmskl(MemI src1) { 1.77 + return (src1.x - 1) ^ src1.x; 1.78 + } 1.79 + static long blsmskq(MemL src1) { 1.80 + return (src1.x - 1) ^ src1.x; 1.81 + } 1.82 + static int blsrl(int src1) { 1.83 + return (src1 - 1) & src1; 1.84 + } 1.85 + static long blsrq(long src1) { 1.86 + return (src1 - 1) & src1; 1.87 + } 1.88 + static int blsrl(MemI src1) { 1.89 + return (src1.x - 1) & src1.x; 1.90 + } 1.91 + static long blsrq(MemL src1) { 1.92 + return (src1.x - 1) & src1.x; 1.93 + } 1.94 + static int lzcntl(int src1) { 1.95 + return Integer.numberOfLeadingZeros(src1); 1.96 + } 1.97 + static int lzcntq(long src1) { 1.98 + return Long.numberOfLeadingZeros(src1); 1.99 + } 1.100 + static int tzcntl(int src1) { 1.101 + return Integer.numberOfTrailingZeros(src1); 1.102 + } 1.103 + static int tzcntq(long src1) { 1.104 + return Long.numberOfTrailingZeros(src1); 1.105 + } 1.106 +} 1.107 + 1.108 +public class BMI1 { 1.109 + private final static int ITERATIONS = 1000000; 1.110 + 1.111 + public static void main(String[] args) { 1.112 + int ix = 0x01234567; 1.113 + int iy = 0x89abcdef; 1.114 + MemI imy = new MemI(iy); 1.115 + long lx = 0x0123456701234567L; 1.116 + long ly = 0x89abcdef89abcdefL; 1.117 + MemL lmy = new MemL(ly); 1.118 + 1.119 + { // match(Set dst (AndI (XorI src1 minus_1) src2)) 1.120 + int z = BMITests.andnl(ix, iy); 1.121 + for (int i = 0; i < ITERATIONS; i++) { 1.122 + int ii = BMITests.andnl(ix, iy); 1.123 + if (ii != z) { 1.124 + throw new Error("andnl with register failed"); 1.125 + } 1.126 + } 1.127 + } 1.128 + { // match(Set dst (AndL (XorL src1 minus_1) src2)) 1.129 + long z = BMITests.andnq(lx, ly); 1.130 + for (int i = 0; i < ITERATIONS; i++) { 1.131 + long ll = BMITests.andnq(lx, ly); 1.132 + if (ll != z) { 1.133 + throw new Error("andnq with register failed"); 1.134 + } 1.135 + } 1.136 + } 1.137 + { // match(Set dst (AndI (XorI src1 minus_1) (LoadI src2))) 1.138 + int z = BMITests.andnl(ix, imy); 1.139 + for (int i = 0; i < ITERATIONS; i++) { 1.140 + int ii = BMITests.andnl(ix, imy); 1.141 + if (ii != z) { 1.142 + throw new Error("andnl with memory failed"); 1.143 + } 1.144 + } 1.145 + } 1.146 + { // match(Set dst (AndL (XorL src1 minus_1) (LoadL src2))) 1.147 + long z = BMITests.andnq(lx, lmy); 1.148 + for (int i = 0; i < ITERATIONS; i++) { 1.149 + long ll = BMITests.andnq(lx, lmy); 1.150 + if (ll != z) { 1.151 + throw new Error("andnq with memory failed"); 1.152 + } 1.153 + } 1.154 + } 1.155 + { // match(Set dst (AndI (SubI imm_zero src) src)) 1.156 + int z = BMITests.blsil(ix); 1.157 + for (int i = 0; i < ITERATIONS; i++) { 1.158 + int ii = BMITests.blsil(ix); 1.159 + if (ii != z) { 1.160 + throw new Error("blsil with register failed"); 1.161 + } 1.162 + } 1.163 + } 1.164 + { // match(Set dst (AndL (SubL imm_zero src) src)) 1.165 + long z = BMITests.blsiq(lx); 1.166 + for (int i = 0; i < ITERATIONS; i++) { 1.167 + long ll = BMITests.blsiq(lx); 1.168 + if (ll != z) { 1.169 + throw new Error("blsiq with register failed"); 1.170 + } 1.171 + } 1.172 + } 1.173 + { // match(Set dst (AndI (SubI imm_zero (LoadI src) ) (LoadI src) )) 1.174 + int z = BMITests.blsil(imy); 1.175 + for (int i = 0; i < ITERATIONS; i++) { 1.176 + int ii = BMITests.blsil(imy); 1.177 + if (ii != z) { 1.178 + throw new Error("blsil with memory failed"); 1.179 + } 1.180 + } 1.181 + } 1.182 + { // match(Set dst (AndL (SubL imm_zero (LoadL src) ) (LoadL src) )) 1.183 + long z = BMITests.blsiq(lmy); 1.184 + for (int i = 0; i < ITERATIONS; i++) { 1.185 + long ll = BMITests.blsiq(lmy); 1.186 + if (ll != z) { 1.187 + throw new Error("blsiq with memory failed"); 1.188 + } 1.189 + } 1.190 + } 1.191 + 1.192 + { // match(Set dst (XorI (AddI src minus_1) src)) 1.193 + int z = BMITests.blsmskl(ix); 1.194 + for (int i = 0; i < ITERATIONS; i++) { 1.195 + int ii = BMITests.blsmskl(ix); 1.196 + if (ii != z) { 1.197 + throw new Error("blsmskl with register failed"); 1.198 + } 1.199 + } 1.200 + } 1.201 + { // match(Set dst (XorL (AddL src minus_1) src)) 1.202 + long z = BMITests.blsmskq(lx); 1.203 + for (int i = 0; i < ITERATIONS; i++) { 1.204 + long ll = BMITests.blsmskq(lx); 1.205 + if (ll != z) { 1.206 + throw new Error("blsmskq with register failed"); 1.207 + } 1.208 + } 1.209 + } 1.210 + { // match(Set dst (XorI (AddI (LoadI src) minus_1) (LoadI src) ) ) 1.211 + int z = BMITests.blsmskl(imy); 1.212 + for (int i = 0; i < ITERATIONS; i++) { 1.213 + int ii = BMITests.blsmskl(imy); 1.214 + if (ii != z) { 1.215 + throw new Error("blsmskl with memory failed"); 1.216 + } 1.217 + } 1.218 + } 1.219 + { // match(Set dst (XorL (AddL (LoadL src) minus_1) (LoadL src) ) ) 1.220 + long z = BMITests.blsmskq(lmy); 1.221 + for (int i = 0; i < ITERATIONS; i++) { 1.222 + long ll = BMITests.blsmskq(lmy); 1.223 + if (ll != z) { 1.224 + throw new Error("blsmskq with memory failed"); 1.225 + } 1.226 + } 1.227 + } 1.228 + 1.229 + { // match(Set dst (AndI (AddI src minus_1) src) ) 1.230 + int z = BMITests.blsrl(ix); 1.231 + for (int i = 0; i < ITERATIONS; i++) { 1.232 + int ii = BMITests.blsrl(ix); 1.233 + if (ii != z) { 1.234 + throw new Error("blsrl with register failed"); 1.235 + } 1.236 + } 1.237 + } 1.238 + { // match(Set dst (AndL (AddL src minus_1) src) ) 1.239 + long z = BMITests.blsrq(lx); 1.240 + for (int i = 0; i < ITERATIONS; i++) { 1.241 + long ll = BMITests.blsrq(lx); 1.242 + if (ll != z) { 1.243 + throw new Error("blsrq with register failed"); 1.244 + } 1.245 + } 1.246 + } 1.247 + { // match(Set dst (AndI (AddI (LoadI src) minus_1) (LoadI src) ) ) 1.248 + int z = BMITests.blsrl(imy); 1.249 + for (int i = 0; i < ITERATIONS; i++) { 1.250 + int ii = BMITests.blsrl(imy); 1.251 + if (ii != z) { 1.252 + throw new Error("blsrl with memory failed"); 1.253 + } 1.254 + } 1.255 + } 1.256 + { // match(Set dst (AndL (AddL (LoadL src) minus_1) (LoadL src)) ) 1.257 + long z = BMITests.blsrq(lmy); 1.258 + for (int i = 0; i < ITERATIONS; i++) { 1.259 + long ll = BMITests.blsrq(lmy); 1.260 + if (ll != z) { 1.261 + throw new Error("blsrq with memory failed"); 1.262 + } 1.263 + } 1.264 + } 1.265 + 1.266 + { 1.267 + int z = BMITests.lzcntl(ix); 1.268 + for (int i = 0; i < ITERATIONS; i++) { 1.269 + int ii = BMITests.lzcntl(ix); 1.270 + if (ii != z) { 1.271 + throw new Error("lzcntl failed"); 1.272 + } 1.273 + } 1.274 + } 1.275 + { 1.276 + int z = BMITests.lzcntq(lx); 1.277 + for (int i = 0; i < ITERATIONS; i++) { 1.278 + int ii = BMITests.lzcntq(lx); 1.279 + if (ii != z) { 1.280 + throw new Error("lzcntq failed"); 1.281 + } 1.282 + } 1.283 + } 1.284 + 1.285 + { 1.286 + int z = BMITests.tzcntl(ix); 1.287 + for (int i = 0; i < ITERATIONS; i++) { 1.288 + int ii = BMITests.tzcntl(ix); 1.289 + if (ii != z) { 1.290 + throw new Error("tzcntl failed"); 1.291 + } 1.292 + } 1.293 + } 1.294 + { 1.295 + int z = BMITests.tzcntq(lx); 1.296 + for (int i = 0; i < ITERATIONS; i++) { 1.297 + int ii = BMITests.tzcntq(lx); 1.298 + if (ii != z) { 1.299 + throw new Error("tzcntq failed"); 1.300 + } 1.301 + } 1.302 + } 1.303 + } 1.304 +}