Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/bmi/TestBzhiI2L.java
41155 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* @key randomness26* @summary Verify that results of computations are the same w/27* and w/o usage of BZHI instruction28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions34* -XX:+WhiteBoxAPI compiler.intrinsics.bmi.TestBzhiI2L35*/3637package compiler.intrinsics.bmi;3839import jdk.test.lib.Platform;40import sun.hotspot.cpuinfo.CPUInfo;4142public class TestBzhiI2L {4344public static void main(String args[]) throws Throwable {45if (Platform.isX86()) {46System.out.println("INFO: Bzhiq not implemented for x86_32, test SKIPPED" );47return;48}49if (!CPUInfo.hasFeature("bmi2")) {50System.out.println("INFO: CPU does not support bmi2 feature, test SKIPPED" );51return;52}5354BMITestRunner.runTests(BzhiI2LExpr.class, args,55"-XX:+IgnoreUnrecognizedVMOptions",56"-XX:+UseBMI2Instructions");57BMITestRunner.runTests(BzhiI2LCommutativeExpr.class, args,58"-XX:+IgnoreUnrecognizedVMOptions",59"-XX:+UseBMI2Instructions");60}6162public static class BzhiI2LExpr extends Expr.BMIUnaryIntToLongExpr {6364public long intToLongExpr(int src1) {65int value = src1;66long returnValue = 0L;6768for(int i = 0; i < 10000; ++i) {69returnValue =70(long)(value & 0x1) ^ (long)(value & 0x3) ^ (long)(value & 0x7) ^ (long)(value & 0xF) ^71(long)(value & 0x1F) ^ (long)(value & 0x3F) ^ (long)(value & 0x7F) ^ (long)(value & 0xFF) ^72(long)(value & 0x1FF) ^ (long)(value & 0x3FF) ^ (long)(value & 0x7FF) ^ (long)(value & 0xFFF) ^73(long)(value & 0x1FFF) ^ (long)(value & 0x3FFF) ^ (long)(value & 0x7FFF) ^ (long)(value & 0xFFFF);74}75return returnValue;76}77}7879public static class BzhiI2LCommutativeExpr extends Expr.BMIUnaryIntToLongExpr {8081public long intToLongExpr(int src1) {82int value = src1;83long returnValue = 0L;8485for(int i = 0; i < 10000; ++i) {86returnValue =87(long)(value & 0x1) ^ (long)(value & 0x3) ^ (long)(value & 0x7) ^ (long)(value & 0xF) ^88(long)(value & 0x1F) ^ (long)(value & 0x3F) ^ (long)(value & 0x7F) ^ (long)(value & 0xFF) ^89(long)(value & 0x1FF) ^ (long)(value & 0x3FF) ^ (long)(value & 0x7FF) ^ (long)(value & 0xFFF) ^90(long)(value & 0x1FFF) ^ (long)(value & 0x3FFF) ^ (long)(value & 0x7FFF) ^ (long)(value & 0xFFFF);91}92return returnValue;93}94}95}969798