Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/VectorizedMismatchTest.java
64474 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*/2223package compiler.intrinsics;2425/*26* @test27* @requires vm.opt.final.UseVectorizedMismatchIntrinsic == true28* @modules java.base/jdk.internal.misc29* java.base/jdk.internal.util30*31* @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,*::test*32* -Xbatch -XX:-TieredCompilation33* -XX:UseAVX=334* compiler.intrinsics.VectorizedMismatchTest35*36* @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,*::test*37* -Xbatch -XX:-TieredCompilation38* -XX:+UnlockDiagnosticVMOptions -XX:UseAVX=3 -XX:AVX3Threshold=039* compiler.intrinsics.VectorizedMismatchTest40*/4142import jdk.internal.misc.Unsafe;43import jdk.internal.util.ArraysSupport;4445public class VectorizedMismatchTest {46private boolean[] boolean_a = new boolean[128];47private boolean[] boolean_b = new boolean[128];4849int testBooleanConstantLength(int length) {50boolean[] obja = boolean_a;51boolean[] objb = boolean_b;52long offset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;53int scale = ArraysSupport.LOG2_ARRAY_BOOLEAN_INDEX_SCALE;54return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);55}5657int testBooleanConstantLength0() { return testBooleanConstantLength(0); }58int testBooleanConstantLength1() { return testBooleanConstantLength(1); }59int testBooleanConstantLength64() { return testBooleanConstantLength(64); }60int testBooleanConstantLength128() { return testBooleanConstantLength(128); }6162/* ==================================================================================== */6364private byte[] byte_a = new byte[128];65private byte[] byte_b = new byte[128];6667int testByteConstantLength(int length) {68byte[] obja = byte_a;69byte[] objb = byte_b;70long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;71int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;72return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);73}7475int testByteConstantLength0() { return testByteConstantLength(0); }76int testByteConstantLength1() { return testByteConstantLength(1); }77int testByteConstantLength64() { return testByteConstantLength(64); }78int testByteConstantLength128() { return testByteConstantLength(128); }7980/* ==================================================================================== */8182private short[] short_a = new short[64];83private short[] short_b = new short[64];8485int testShortConstantLength(int length) {86short[] obja = short_a;87short[] objb = short_b;88long offset = Unsafe.ARRAY_SHORT_BASE_OFFSET;89int scale = ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE;90return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);91}9293int testShortConstantLength0() { return testShortConstantLength(0); }94int testShortConstantLength1() { return testShortConstantLength(1); }95int testShortConstantLength32() { return testShortConstantLength(32); }96int testShortConstantLength64() { return testShortConstantLength(64); }9798/* ==================================================================================== */99100private char[] char_a = new char[64];101private char[] char_b = new char[64];102103int testCharConstantLength(int length) {104char[] obja = char_a;105char[] objb = char_b;106long offset = Unsafe.ARRAY_CHAR_BASE_OFFSET;107int scale = ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE;108return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);109}110111int testCharConstantLength0() { return testCharConstantLength(0); }112int testCharConstantLength1() { return testCharConstantLength(1); }113int testCharConstantLength32() { return testCharConstantLength(32); }114int testCharConstantLength64() { return testCharConstantLength(64); }115116/* ==================================================================================== */117118private int[] int_a = new int[32];119private int[] int_b = new int[32];120121int testIntConstantLength(int length) {122int[] obja = int_a;123int[] objb = int_b;124long offset = Unsafe.ARRAY_INT_BASE_OFFSET;125int scale = ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE;126return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);127}128129int testIntConstantLength0() { return testIntConstantLength(0); }130int testIntConstantLength1() { return testIntConstantLength(1); }131int testIntConstantLength16() { return testIntConstantLength(16); }132int testIntConstantLength32() { return testIntConstantLength(32); }133134/* ==================================================================================== */135136private float[] float_a = new float[32];137private float[] float_b = new float[32];138139int testFloatConstantLength(int length) {140float[] obja = float_a;141float[] objb = float_b;142long offset = Unsafe.ARRAY_FLOAT_BASE_OFFSET;143int scale = ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE;144return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);145}146147int testFloatConstantLength0() { return testFloatConstantLength(0); }148int testFloatConstantLength1() { return testFloatConstantLength(1); }149int testFloatConstantLength16() { return testFloatConstantLength(16); }150int testFloatConstantLength32() { return testFloatConstantLength(32); }151152/* ==================================================================================== */153154private long[] long_a = new long[16];155private long[] long_b = new long[16];156157int testLongConstantLength(int length) {158long[] obja = long_a;159long[] objb = long_b;160long offset = Unsafe.ARRAY_LONG_BASE_OFFSET;161int scale = ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE;162return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);163}164165int testLongConstantLength0() { return testLongConstantLength(0); }166int testLongConstantLength1() { return testLongConstantLength(1); }167int testLongConstantLength8() { return testLongConstantLength(8); }168int testLongConstantLength16() { return testLongConstantLength(16); }169170/* ==================================================================================== */171172private double[] double_a = new double[16];173private double[] double_b = new double[16];174175int testDoubleConstantLength(int length) {176double[] obja = double_a;177double[] objb = double_b;178long offset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET;179int scale = ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE;180return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);181}182183int testDoubleConstantLength0() { return testDoubleConstantLength(0); }184int testDoubleConstantLength1() { return testDoubleConstantLength(1); }185int testDoubleConstantLength8() { return testDoubleConstantLength(8); }186int testDoubleConstantLength16() { return testDoubleConstantLength(16); }187188/* ==================================================================================== */189190static class ClassInitTest {191static final int LENGTH = 64;192static final int RESULT;193static {194byte[] arr1 = new byte[LENGTH];195byte[] arr2 = new byte[LENGTH];196for (int i = 0; i < 20_000; i++) {197test(arr1, arr2);198}199RESULT = test(arr1, arr2);200}201202static int test(byte[] obja, byte[] objb) {203long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;204int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;205return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, LENGTH, scale); // LENGTH is not considered a constant206}207}208209int testConstantBeingInitialized() {210return ClassInitTest.RESULT; // trigger class initialization211}212213/* ==================================================================================== */214215int testLoopUnswitch(int length) {216long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;217int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;218219int acc = 0;220for (int i = 0; i < 32; i++) {221acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);222}223return acc;224}225226int testLoopHoist(int length, int stride) {227long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;228int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;229230int acc = 0;231232for (int i = 0; i < 32; i += stride) {233acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);234}235return acc;236}237238/* ==================================================================================== */239240public static void main(String[] args) {241VectorizedMismatchTest t = new VectorizedMismatchTest();242for (int i = 0; i < 20_000; i++) {243t.testBooleanConstantLength0();244t.testBooleanConstantLength1();245t.testBooleanConstantLength64();246t.testBooleanConstantLength128();247248t.testByteConstantLength0();249t.testByteConstantLength1();250t.testByteConstantLength64();251t.testByteConstantLength128();252253t.testShortConstantLength0();254t.testShortConstantLength1();255t.testShortConstantLength32();256t.testShortConstantLength64();257258t.testCharConstantLength0();259t.testCharConstantLength1();260t.testCharConstantLength32();261t.testCharConstantLength64();262263t.testIntConstantLength0();264t.testIntConstantLength1();265t.testIntConstantLength16();266t.testIntConstantLength32();267268t.testFloatConstantLength0();269t.testFloatConstantLength1();270t.testFloatConstantLength16();271t.testFloatConstantLength32();272273t.testLongConstantLength0();274t.testLongConstantLength1();275t.testLongConstantLength8();276t.testLongConstantLength16();277278t.testDoubleConstantLength0();279t.testDoubleConstantLength1();280t.testDoubleConstantLength8();281t.testDoubleConstantLength16();282283t.testLoopUnswitch(32);284t.testLoopHoist(128, 2);285}286}287}288289290