Path: blob/master/test/hotspot/jtreg/compiler/codegen/BMI2.java
41149 views
/*1* Copyright (c) 2021, 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* @summary Support BMI2 instructions on x86/x6426*27* @run main/othervm -Xbatch -XX:-TieredCompilation -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure28* -XX:CompileCommand=dontinline,compiler.codegen.BMI2$BMITests::*29* compiler.codegen.BMI230*/3132package compiler.codegen;3334public class BMI2 {35private final static int ITERATIONS = 30000;3637// match(Set dst (ConvI2L (AndI src1 mask)))38public static void testBzhiI2L(int ix) {39long[] goldv = new long[16];40for (int i = 0; i <= 15; i++) {41goldv[i] = BMITests.bzhiI2L(ix, i);42}43for (int i2 = 0; i2 < ITERATIONS; i2++) {44for (int i = 0; i <= 15; i++) {45long v = BMITests.bzhiI2L(ix, i);46if (v != goldv[i]) {47throw new Error(returnBzhiI2LErrMessage (goldv[i], v));48}49}50}51}5253private static String returnBzhiI2LErrMessage (long value, long value2) {54return "bzhi I2L with register failed, uncompiled result: " + value + " does not match compiled result: " + value2;55}5657static class BMITests {5859static long bzhiI2L(int src1, int src2) {6061switch(src2) {62case 0:63return (long)(src1 & 0x1);64case 1:65return (long)(src1 & 0x3);66case 2:67return (long)(src1 & 0x7);68case 3:69return (long)(src1 & 0xF);70case 4:71return (long)(src1 & 0x1F);72case 5:73return (long)(src1 & 0x3F);74case 6:75return (long)(src1 & 0x7F);76case 7:77return (long)(src1 & 0xFF);78case 8:79return (long)(src1 & 0x1FF);80case 9:81return (long)(src1 & 0x3FF);82case 10:83return (long)(src1 & 0x7FF);84case 11:85return (long)(src1 & 0xFFF);86case 12:87return (long)(src1 & 0x1FFF);88case 13:89return (long)(src1 & 0x3FFF);90case 14:91return (long)(src1 & 0x7FFF);92case 15:93return (long)(src1 & 0xFFFF);94default:95return (long)(src1 & 0xFFFF);96}97}98}99100public static void main(String[] args) {101testBzhiI2L(0);102testBzhiI2L(1);103}104}105106107