aoqi@0: /* aoqi@0: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8031321 aoqi@0: * @summary Support BMI1 instructions on x86/x64 aoqi@0: * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=compileonly,BMITests.* BMI1 aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: class MemI { aoqi@0: public int x; aoqi@0: public MemI(int x) { this.x = x; } aoqi@0: } aoqi@0: aoqi@0: class MemL { aoqi@0: public long x; aoqi@0: public MemL(long x) { this.x = x; } aoqi@0: } aoqi@0: aoqi@0: class BMITests { aoqi@0: static int andnl(int src1, int src2) { aoqi@0: return ~src1 & src2; aoqi@0: } aoqi@0: static long andnq(long src1, long src2) { aoqi@0: return ~src1 & src2; aoqi@0: } aoqi@0: static int andnl(int src1, MemI src2) { aoqi@0: return ~src1 & src2.x; aoqi@0: } aoqi@0: static long andnq(long src1, MemL src2) { aoqi@0: return ~src1 & src2.x; aoqi@0: } aoqi@0: static int blsil(int src1) { aoqi@0: return src1 & -src1; aoqi@0: } aoqi@0: static long blsiq(long src1) { aoqi@0: return src1 & -src1; aoqi@0: } aoqi@0: static int blsil(MemI src1) { aoqi@0: return src1.x & -src1.x; aoqi@0: } aoqi@0: static long blsiq(MemL src1) { aoqi@0: return src1.x & -src1.x; aoqi@0: } aoqi@0: static int blsmskl(int src1) { aoqi@0: return (src1 - 1) ^ src1; aoqi@0: } aoqi@0: static long blsmskq(long src1) { aoqi@0: return (src1 - 1) ^ src1; aoqi@0: } aoqi@0: static int blsmskl(MemI src1) { aoqi@0: return (src1.x - 1) ^ src1.x; aoqi@0: } aoqi@0: static long blsmskq(MemL src1) { aoqi@0: return (src1.x - 1) ^ src1.x; aoqi@0: } aoqi@0: static int blsrl(int src1) { aoqi@0: return (src1 - 1) & src1; aoqi@0: } aoqi@0: static long blsrq(long src1) { aoqi@0: return (src1 - 1) & src1; aoqi@0: } aoqi@0: static int blsrl(MemI src1) { aoqi@0: return (src1.x - 1) & src1.x; aoqi@0: } aoqi@0: static long blsrq(MemL src1) { aoqi@0: return (src1.x - 1) & src1.x; aoqi@0: } aoqi@0: static int lzcntl(int src1) { aoqi@0: return Integer.numberOfLeadingZeros(src1); aoqi@0: } aoqi@0: static int lzcntq(long src1) { aoqi@0: return Long.numberOfLeadingZeros(src1); aoqi@0: } aoqi@0: static int tzcntl(int src1) { aoqi@0: return Integer.numberOfTrailingZeros(src1); aoqi@0: } aoqi@0: static int tzcntq(long src1) { aoqi@0: return Long.numberOfTrailingZeros(src1); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public class BMI1 { aoqi@0: private final static int ITERATIONS = 1000000; aoqi@0: aoqi@0: public static void main(String[] args) { aoqi@0: int ix = 0x01234567; aoqi@0: int iy = 0x89abcdef; aoqi@0: MemI imy = new MemI(iy); aoqi@0: long lx = 0x0123456701234567L; aoqi@0: long ly = 0x89abcdef89abcdefL; aoqi@0: MemL lmy = new MemL(ly); aoqi@0: aoqi@0: { // match(Set dst (AndI (XorI src1 minus_1) src2)) aoqi@0: int z = BMITests.andnl(ix, iy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.andnl(ix, iy); aoqi@0: if (ii != z) { aoqi@0: throw new Error("andnl with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (XorL src1 minus_1) src2)) aoqi@0: long z = BMITests.andnq(lx, ly); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.andnq(lx, ly); aoqi@0: if (ll != z) { aoqi@0: throw new Error("andnq with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndI (XorI src1 minus_1) (LoadI src2))) aoqi@0: int z = BMITests.andnl(ix, imy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.andnl(ix, imy); aoqi@0: if (ii != z) { aoqi@0: throw new Error("andnl with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (XorL src1 minus_1) (LoadL src2))) aoqi@0: long z = BMITests.andnq(lx, lmy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.andnq(lx, lmy); aoqi@0: if (ll != z) { aoqi@0: throw new Error("andnq with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndI (SubI imm_zero src) src)) aoqi@0: int z = BMITests.blsil(ix); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsil(ix); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsil with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (SubL imm_zero src) src)) aoqi@0: long z = BMITests.blsiq(lx); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsiq(lx); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsiq with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndI (SubI imm_zero (LoadI src) ) (LoadI src) )) aoqi@0: int z = BMITests.blsil(imy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsil(imy); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsil with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (SubL imm_zero (LoadL src) ) (LoadL src) )) aoqi@0: long z = BMITests.blsiq(lmy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsiq(lmy); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsiq with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: { // match(Set dst (XorI (AddI src minus_1) src)) aoqi@0: int z = BMITests.blsmskl(ix); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsmskl(ix); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsmskl with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (XorL (AddL src minus_1) src)) aoqi@0: long z = BMITests.blsmskq(lx); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsmskq(lx); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsmskq with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (XorI (AddI (LoadI src) minus_1) (LoadI src) ) ) aoqi@0: int z = BMITests.blsmskl(imy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsmskl(imy); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsmskl with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (XorL (AddL (LoadL src) minus_1) (LoadL src) ) ) aoqi@0: long z = BMITests.blsmskq(lmy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsmskq(lmy); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsmskq with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: { // match(Set dst (AndI (AddI src minus_1) src) ) aoqi@0: int z = BMITests.blsrl(ix); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsrl(ix); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsrl with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (AddL src minus_1) src) ) aoqi@0: long z = BMITests.blsrq(lx); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsrq(lx); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsrq with register failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndI (AddI (LoadI src) minus_1) (LoadI src) ) ) aoqi@0: int z = BMITests.blsrl(imy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.blsrl(imy); aoqi@0: if (ii != z) { aoqi@0: throw new Error("blsrl with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { // match(Set dst (AndL (AddL (LoadL src) minus_1) (LoadL src)) ) aoqi@0: long z = BMITests.blsrq(lmy); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: long ll = BMITests.blsrq(lmy); aoqi@0: if (ll != z) { aoqi@0: throw new Error("blsrq with memory failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: { aoqi@0: int z = BMITests.lzcntl(ix); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.lzcntl(ix); aoqi@0: if (ii != z) { aoqi@0: throw new Error("lzcntl failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { aoqi@0: int z = BMITests.lzcntq(lx); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.lzcntq(lx); aoqi@0: if (ii != z) { aoqi@0: throw new Error("lzcntq failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: { aoqi@0: int z = BMITests.tzcntl(ix); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.tzcntl(ix); aoqi@0: if (ii != z) { aoqi@0: throw new Error("tzcntl failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: { aoqi@0: int z = BMITests.tzcntq(lx); aoqi@0: for (int i = 0; i < ITERATIONS; i++) { aoqi@0: int ii = BMITests.tzcntq(lx); aoqi@0: if (ii != z) { aoqi@0: throw new Error("tzcntq failed"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }