|
| 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.IntVector; |
| 31 | +import jdk.incubator.vector.LongVector; |
| 32 | +import jdk.incubator.vector.VectorMask; |
| 33 | +import jdk.incubator.vector.VectorOperators; |
| 34 | +import jdk.incubator.vector.VectorSpecies; |
| 35 | + |
| 36 | +import jdk.test.lib.Asserts; |
| 37 | +import jdk.test.lib.Utils; |
| 38 | + |
| 39 | +/** |
| 40 | + * @test |
| 41 | + * @bug 8329887 |
| 42 | + * @key randomness |
| 43 | + * @library /test/lib / |
| 44 | + * @requires vm.compiler2.enabled |
| 45 | + * @requires os.arch == "riscv64" & vm.cpu.features ~= ".*zvbb.*" |
| 46 | + * @summary RISCV: [vector] zvbb extension And-Not support Test for match rules |
| 47 | + * @modules jdk.incubator.vector |
| 48 | + * |
| 49 | + * @run driver compiler.vectorapi.VectorAndNotMatchRuleTest |
| 50 | + */ |
| 51 | + |
| 52 | +public class VectorAndNotMatchRuleTest { |
| 53 | + private static final VectorSpecies<Integer> I_SPECIES = IntVector.SPECIES_MAX; |
| 54 | + private static final VectorSpecies<Long> L_SPECIES = LongVector.SPECIES_MAX; |
| 55 | + |
| 56 | + private static int LENGTH = 128; |
| 57 | + private static final Random RD = Utils.getRandomInstance(); |
| 58 | + |
| 59 | + private static int[] ia; |
| 60 | + private static int[] ib; |
| 61 | + private static int[] ir; |
| 62 | + private static boolean[] ma; |
| 63 | + private static boolean[] mb; |
| 64 | + private static boolean[] mc; |
| 65 | + private static boolean[] mr; |
| 66 | + |
| 67 | + static { |
| 68 | + ia = new int[LENGTH]; |
| 69 | + ib = new int[LENGTH]; |
| 70 | + ir = new int[LENGTH]; |
| 71 | + ma = new boolean[LENGTH]; |
| 72 | + mb = new boolean[LENGTH]; |
| 73 | + mc = new boolean[LENGTH]; |
| 74 | + mr = new boolean[LENGTH]; |
| 75 | + |
| 76 | + for (int i = 0; i < LENGTH; i++) { |
| 77 | + ia[i] = RD.nextInt(25); |
| 78 | + ib[i] = RD.nextInt(25); |
| 79 | + ma[i] = RD.nextBoolean(); |
| 80 | + mb[i] = RD.nextBoolean(); |
| 81 | + mc[i] = RD.nextBoolean(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + @Warmup(10000) |
| 87 | + @IR(counts = { IRNode.VAND_NOT_I, " >= 1" }, applyIf = {"UseZvbb", "> 0"}) |
| 88 | + public static void testVectorVAndNotI() { |
| 89 | + IntVector av = IntVector.fromArray(I_SPECIES, ia, 0); |
| 90 | + IntVector bv = IntVector.fromArray(I_SPECIES, ib, 0); |
| 91 | + av.not().lanewise(VectorOperators.AND_NOT, bv).intoArray(ir, 0); |
| 92 | + |
| 93 | + // Verify results |
| 94 | + for (int i = 0; i < I_SPECIES.length(); i++) { |
| 95 | + Asserts.assertEquals((~ia[i]) & (~ib[i]), ir[i]); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + @Warmup(10000) |
| 101 | + @IR(counts = { IRNode.VAND_NOT_L, " >= 1" }, applyIf = {"UseZvbb", "> 0"}) |
| 102 | + public static void testVectorVAndNotL() { |
| 103 | + VectorMask<Long> avm = VectorMask.fromArray(L_SPECIES, ma, 0); |
| 104 | + VectorMask<Long> bvm = VectorMask.fromArray(L_SPECIES, mb, 0); |
| 105 | + VectorMask<Long> cvm = VectorMask.fromArray(L_SPECIES, mc, 0); |
| 106 | + avm.andNot(bvm).andNot(cvm).intoArray(mr, 0); |
| 107 | + |
| 108 | + // Verify results |
| 109 | + for (int i = 0; i < L_SPECIES.length(); i++) { |
| 110 | + Asserts.assertEquals((ma[i] & (!mb[i])) & (!mc[i]), mr[i]); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + @Warmup(10000) |
| 116 | + @IR(counts = { IRNode.VAND_NOT_I_MASKED, " >= 1" }, applyIf = {"UseZvbb", "> 0"} ) |
| 117 | + public static void testVectorVAndNotIMasked() { |
| 118 | + VectorMask<Integer> avm = VectorMask.fromArray(I_SPECIES, ma, 0); |
| 119 | + IntVector av = IntVector.fromArray(I_SPECIES, ia, 0); |
| 120 | + IntVector bv = IntVector.fromArray(I_SPECIES, ib, 0); |
| 121 | + av.not().lanewise(VectorOperators.AND_NOT, bv, avm).intoArray(ir, 0); |
| 122 | + |
| 123 | + // Verify results |
| 124 | + for (int i = 0; i < I_SPECIES.length(); i++) { |
| 125 | + if (ma[i] == true) { |
| 126 | + Asserts.assertEquals((~ia[i]) & (~ib[i]), ir[i]); |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + public static void main(String[] args) { |
| 132 | + TestFramework.runWithFlags("--add-modules=jdk.incubator.vector"); |
| 133 | + } |
| 134 | +} |
0 commit comments