|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +package compiler.vectorapi; |
| 25 | + |
| 26 | +import compiler.lib.ir_framework.*; |
| 27 | + |
| 28 | +import java.util.Random; |
| 29 | + |
| 30 | +import jdk.incubator.vector.ByteVector; |
| 31 | +import jdk.incubator.vector.VectorMask; |
| 32 | +import jdk.incubator.vector.VectorOperators; |
| 33 | +import jdk.incubator.vector.VectorSpecies; |
| 34 | + |
| 35 | +import jdk.test.lib.Asserts; |
| 36 | +import jdk.test.lib.Utils; |
| 37 | + |
| 38 | +/** |
| 39 | + * @test |
| 40 | + * @bug 8290485 |
| 41 | + * @key randomness |
| 42 | + * @library /test/lib / |
| 43 | + * @summary [vectorapi] REVERSE_BYTES for byte type should not emit any instructions |
| 44 | + * @requires vm.compiler2.enabled |
| 45 | + * @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.arch == "aarch64" |
| 46 | + * @modules jdk.incubator.vector |
| 47 | + * |
| 48 | + * @run driver compiler.vectorapi.VectorReverseBytesTest |
| 49 | + */ |
| 50 | + |
| 51 | +public class VectorReverseBytesTest { |
| 52 | + private static final VectorSpecies<Byte> B_SPECIES = ByteVector.SPECIES_MAX; |
| 53 | + |
| 54 | + private static int LENGTH = 1024; |
| 55 | + private static final Random RD = Utils.getRandomInstance(); |
| 56 | + |
| 57 | + private static byte[] input; |
| 58 | + private static byte[] output; |
| 59 | + private static boolean[] m; |
| 60 | + |
| 61 | + static { |
| 62 | + input = new byte[LENGTH]; |
| 63 | + output = new byte[LENGTH]; |
| 64 | + m = new boolean[LENGTH]; |
| 65 | + |
| 66 | + for (int i = 0; i < LENGTH; i++) { |
| 67 | + input[i] = (byte) RD.nextInt(25); |
| 68 | + m[i] = RD.nextBoolean(); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + @IR(failOn = IRNode.REVERSE_BYTES_V) |
| 74 | + public static void testReverseBytesV() { |
| 75 | + for (int i = 0; i < LENGTH; i += B_SPECIES.length()) { |
| 76 | + ByteVector v = ByteVector.fromArray(B_SPECIES, input, i); |
| 77 | + v.lanewise(VectorOperators.REVERSE_BYTES).intoArray(output, i); |
| 78 | + } |
| 79 | + |
| 80 | + // Verify results |
| 81 | + for (int i = 0; i < LENGTH; i++) { |
| 82 | + Asserts.assertEquals(input[i], output[i]); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + @IR(failOn = IRNode.REVERSE_BYTES_V) |
| 88 | + @IR(failOn = IRNode.VECTOR_BLEND) |
| 89 | + public static void testReverseBytesVMasked() { |
| 90 | + VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0); |
| 91 | + for (int i = 0; i < LENGTH; i += B_SPECIES.length()) { |
| 92 | + ByteVector v = ByteVector.fromArray(B_SPECIES, input, i); |
| 93 | + v.lanewise(VectorOperators.REVERSE_BYTES, mask).intoArray(output, i); |
| 94 | + } |
| 95 | + |
| 96 | + // Verify results |
| 97 | + for (int i = 0; i < LENGTH; i++) { |
| 98 | + Asserts.assertEquals(input[i], output[i]); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + public static void main(String[] args) { |
| 103 | + TestFramework.runWithFlags("--add-modules=jdk.incubator.vector"); |
| 104 | + } |
| 105 | +} |
0 commit comments