Path: blob/master/test/hotspot/jtreg/compiler/codegen/BMI1.java
41149 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803132126* @summary Support BMI1 instructions on x86/x6427*28* @run main/othervm -Xbatch -XX:-TieredCompilation29* -XX:CompileCommand=compileonly,compiler.codegen.BMI1$BMITests::*30* compiler.codegen.BMI131*/3233package compiler.codegen;3435public class BMI1 {36private final static int ITERATIONS = 1000000;3738public static void main(String[] args) {39int ix = 0x01234567;40int iy = 0x89abcdef;41MemI imy = new MemI(iy);42long lx = 0x0123456701234567L;43long ly = 0x89abcdef89abcdefL;44MemL lmy = new MemL(ly);4546{ // match(Set dst (AndI (XorI src1 minus_1) src2))47int z = BMITests.andnl(ix, iy);48for (int i = 0; i < ITERATIONS; i++) {49int ii = BMITests.andnl(ix, iy);50if (ii != z) {51throw new Error("andnl with register failed");52}53}54}55{ // match(Set dst (AndL (XorL src1 minus_1) src2))56long z = BMITests.andnq(lx, ly);57for (int i = 0; i < ITERATIONS; i++) {58long ll = BMITests.andnq(lx, ly);59if (ll != z) {60throw new Error("andnq with register failed");61}62}63}64{ // match(Set dst (AndI (XorI src1 minus_1) (LoadI src2)))65int z = BMITests.andnl(ix, imy);66for (int i = 0; i < ITERATIONS; i++) {67int ii = BMITests.andnl(ix, imy);68if (ii != z) {69throw new Error("andnl with memory failed");70}71}72}73{ // match(Set dst (AndL (XorL src1 minus_1) (LoadL src2)))74long z = BMITests.andnq(lx, lmy);75for (int i = 0; i < ITERATIONS; i++) {76long ll = BMITests.andnq(lx, lmy);77if (ll != z) {78throw new Error("andnq with memory failed");79}80}81}82{ // match(Set dst (AndI (SubI imm_zero src) src))83int z = BMITests.blsil(ix);84for (int i = 0; i < ITERATIONS; i++) {85int ii = BMITests.blsil(ix);86if (ii != z) {87throw new Error("blsil with register failed");88}89}90}91{ // match(Set dst (AndL (SubL imm_zero src) src))92long z = BMITests.blsiq(lx);93for (int i = 0; i < ITERATIONS; i++) {94long ll = BMITests.blsiq(lx);95if (ll != z) {96throw new Error("blsiq with register failed");97}98}99}100{ // match(Set dst (AndI (SubI imm_zero (LoadI src) ) (LoadI src) ))101int z = BMITests.blsil(imy);102for (int i = 0; i < ITERATIONS; i++) {103int ii = BMITests.blsil(imy);104if (ii != z) {105throw new Error("blsil with memory failed");106}107}108}109{ // match(Set dst (AndL (SubL imm_zero (LoadL src) ) (LoadL src) ))110long z = BMITests.blsiq(lmy);111for (int i = 0; i < ITERATIONS; i++) {112long ll = BMITests.blsiq(lmy);113if (ll != z) {114throw new Error("blsiq with memory failed");115}116}117}118119{ // match(Set dst (XorI (AddI src minus_1) src))120int z = BMITests.blsmskl(ix);121for (int i = 0; i < ITERATIONS; i++) {122int ii = BMITests.blsmskl(ix);123if (ii != z) {124throw new Error("blsmskl with register failed");125}126}127}128{ // match(Set dst (XorL (AddL src minus_1) src))129long z = BMITests.blsmskq(lx);130for (int i = 0; i < ITERATIONS; i++) {131long ll = BMITests.blsmskq(lx);132if (ll != z) {133throw new Error("blsmskq with register failed");134}135}136}137{ // match(Set dst (XorI (AddI (LoadI src) minus_1) (LoadI src) ) )138int z = BMITests.blsmskl(imy);139for (int i = 0; i < ITERATIONS; i++) {140int ii = BMITests.blsmskl(imy);141if (ii != z) {142throw new Error("blsmskl with memory failed");143}144}145}146{ // match(Set dst (XorL (AddL (LoadL src) minus_1) (LoadL src) ) )147long z = BMITests.blsmskq(lmy);148for (int i = 0; i < ITERATIONS; i++) {149long ll = BMITests.blsmskq(lmy);150if (ll != z) {151throw new Error("blsmskq with memory failed");152}153}154}155156{ // match(Set dst (AndI (AddI src minus_1) src) )157int z = BMITests.blsrl(ix);158for (int i = 0; i < ITERATIONS; i++) {159int ii = BMITests.blsrl(ix);160if (ii != z) {161throw new Error("blsrl with register failed");162}163}164}165{ // match(Set dst (AndL (AddL src minus_1) src) )166long z = BMITests.blsrq(lx);167for (int i = 0; i < ITERATIONS; i++) {168long ll = BMITests.blsrq(lx);169if (ll != z) {170throw new Error("blsrq with register failed");171}172}173}174{ // match(Set dst (AndI (AddI (LoadI src) minus_1) (LoadI src) ) )175int z = BMITests.blsrl(imy);176for (int i = 0; i < ITERATIONS; i++) {177int ii = BMITests.blsrl(imy);178if (ii != z) {179throw new Error("blsrl with memory failed");180}181}182}183{ // match(Set dst (AndL (AddL (LoadL src) minus_1) (LoadL src)) )184long z = BMITests.blsrq(lmy);185for (int i = 0; i < ITERATIONS; i++) {186long ll = BMITests.blsrq(lmy);187if (ll != z) {188throw new Error("blsrq with memory failed");189}190}191}192193{194int z = BMITests.lzcntl(ix);195for (int i = 0; i < ITERATIONS; i++) {196int ii = BMITests.lzcntl(ix);197if (ii != z) {198throw new Error("lzcntl failed");199}200}201}202{203int z = BMITests.lzcntq(lx);204for (int i = 0; i < ITERATIONS; i++) {205int ii = BMITests.lzcntq(lx);206if (ii != z) {207throw new Error("lzcntq failed");208}209}210}211212{213int z = BMITests.tzcntl(ix);214for (int i = 0; i < ITERATIONS; i++) {215int ii = BMITests.tzcntl(ix);216if (ii != z) {217throw new Error("tzcntl failed");218}219}220}221{222int z = BMITests.tzcntq(lx);223for (int i = 0; i < ITERATIONS; i++) {224int ii = BMITests.tzcntq(lx);225if (ii != z) {226throw new Error("tzcntq failed");227}228}229}230}231232static class MemI {233public int x;234235public MemI(int x) {236this.x = x;237}238}239240static class MemL {241public long x;242243public MemL(long x) {244this.x = x;245}246}247248static class BMITests {249static int andnl(int src1, int src2) {250return ~src1 & src2;251}252253static long andnq(long src1, long src2) {254return ~src1 & src2;255}256257static int andnl(int src1, MemI src2) {258return ~src1 & src2.x;259}260261static long andnq(long src1, MemL src2) {262return ~src1 & src2.x;263}264265static int blsil(int src1) {266return src1 & -src1;267}268269static long blsiq(long src1) {270return src1 & -src1;271}272273static int blsil(MemI src1) {274return src1.x & -src1.x;275}276277static long blsiq(MemL src1) {278return src1.x & -src1.x;279}280281static int blsmskl(int src1) {282return (src1 - 1) ^ src1;283}284285static long blsmskq(long src1) {286return (src1 - 1) ^ src1;287}288289static int blsmskl(MemI src1) {290return (src1.x - 1) ^ src1.x;291}292293static long blsmskq(MemL src1) {294return (src1.x - 1) ^ src1.x;295}296297static int blsrl(int src1) {298return (src1 - 1) & src1;299}300301static long blsrq(long src1) {302return (src1 - 1) & src1;303}304305static int blsrl(MemI src1) {306return (src1.x - 1) & src1.x;307}308309static long blsrq(MemL src1) {310return (src1.x - 1) & src1.x;311}312313static int lzcntl(int src1) {314return Integer.numberOfLeadingZeros(src1);315}316317static int lzcntq(long src1) {318return Long.numberOfLeadingZeros(src1);319}320321static int tzcntl(int src1) {322return Integer.numberOfTrailingZeros(src1);323}324325static int tzcntq(long src1) {326return Long.numberOfTrailingZeros(src1);327}328}329}330331332