1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Copyright (c) 2022, Arm Limited. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package compiler.c2.irTests;
import compiler.lib.ir_framework.*;
import java.util.Random;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
/*
* @test
* @bug 8283307
* @key randomness
* @summary Auto-vectorization enhancement for unsigned shift right on signed subword types
* @requires ((os.arch=="amd64" | os.arch=="x86_64") & (vm.opt.UseSSE == "null" | vm.opt.UseSSE > 3)) | os.arch=="aarch64" |
* (os.arch == "riscv64" & vm.cpu.features ~= ".*rvv.*")
* @library /test/lib /
* @run driver compiler.c2.irTests.TestVectorizeURShiftSubword
*/
public class TestVectorizeURShiftSubword {
private static final Random RANDOM = Utils.getRandomInstance();
final private static int NUM = 3000;
private short[] shorta = new short[NUM];
private short[] shortb = new short[NUM];
private byte[] bytea = new byte[NUM];
private byte[] byteb = new byte[NUM];
private static final int[] SPECIALS = {
0, 0x1, 0x8, 0xF, 0x3F, 0x7C, 0x7F, 0x80, 0x81, 0x8F, 0xF3, 0xF8, 0xFF,
0x38FF, 0x3FFF, 0x8F8F, 0x8FFF, 0x7FF3, 0x7FFF, 0xFF33, 0xFFF8, 0xFFFF, 0xFFFFFF,
Integer.MAX_VALUE, Integer.MIN_VALUE
};
public byte urshift(byte input, int amount) {
return (byte) (input >>> amount);
}
public short urshift(short input, int amount) {
return (short) (input >>> amount);
}
public static void main(String[] args) {
TestFramework framework = new TestFramework(TestVectorizeURShiftSubword.class);
framework.setDefaultWarmup(1).addFlags("-XX:CompileCommand=exclude,*.urshift").start();
}
@Test
@IR(counts = {IRNode.LOAD_VECTOR_B, ">0", IRNode.RSHIFT_VB, ">0", IRNode.STORE_VECTOR, ">0"})
public void testByte0() {
for(int i = 0; i < NUM; i++) {
byteb[i] = (byte) (bytea[i] >>> 3);
}
}
@Test
@IR(counts = {IRNode.LOAD_VECTOR_B, ">0", IRNode.RSHIFT_VB, ">0", IRNode.STORE_VECTOR, ">0"})
public void testByte1() {
for(int i = 0; i < NUM; i++) {
byteb[i] = (byte) (bytea[i] >>> 24);
}
}
@Test
@IR(failOn = {IRNode.LOAD_VECTOR_B, IRNode.RSHIFT_VB, IRNode.STORE_VECTOR})
public void testByte2() {
for(int i = 0; i < NUM; i++) {
byteb[i] = (byte) (bytea[i] >>> 25);
}
}
@Test
@IR(counts = {IRNode.LOAD_VECTOR_S, ">0", IRNode.RSHIFT_VS, ">0", IRNode.STORE_VECTOR, ">0"})
public void testShort0() {
for(int i = 0; i < NUM; i++) {
shortb[i] = (short) (shorta[i] >>> 10);
}
}
@Test
@IR(counts = {IRNode.LOAD_VECTOR_S, ">0", IRNode.RSHIFT_VS, ">0", IRNode.STORE_VECTOR, ">0"})
public void testShort1() {
for(int i = 0; i < NUM; i++) {
shortb[i] = (short) (shorta[i] >>> 16);
}
}
@Test
@IR(failOn = {IRNode.LOAD_VECTOR_S, IRNode.RSHIFT_VS, IRNode.STORE_VECTOR})
public void testShort2() {
for(int i = 0; i < NUM; i++) {
shortb[i] = (short) (shorta[i] >>> 17);
}
}
@Test
public void checkTest() {
testByte0();
for (int i = 0; i < bytea.length; i++) {
Asserts.assertEquals(byteb[i], urshift(bytea[i], 3));
}
testByte1();
for (int i = 0; i < bytea.length; i++) {
Asserts.assertEquals(byteb[i], urshift(bytea[i], 24));
}
testByte2();
for (int i = 0; i < bytea.length; i++) {
Asserts.assertEquals(byteb[i], urshift(bytea[i], 25));
}
testShort0();
for (int i = 0; i < shorta.length; i++) {
Asserts.assertEquals(shortb[i], urshift(shorta[i], 10));
}
testShort1();
for (int i = 0; i < shorta.length; i++) {
Asserts.assertEquals(shortb[i], urshift(shorta[i], 16));
}
testShort2();
for (int i = 0; i < shorta.length; i++) {
Asserts.assertEquals(shortb[i], urshift(shorta[i], 17));
}
}
@Run(test = "checkTest")
public void checkTest_runner() {
for (int i = 0; i < SPECIALS.length; i++) {
for (int j = 0; j < shorta.length; j++) {
shorta[j] = (short) SPECIALS[i];
bytea[j] = (byte) SPECIALS[i];
}
checkTest();
}
for (int j = 0; j < shorta.length; j++) {
shorta[j] = (short) RANDOM.nextInt();;
bytea[j] = (byte) RANDOM.nextInt();
}
checkTest();
}
}
|