Skip to content

Commit f265ddf

Browse files
committed
RISC-V: C2: Support Zvbb Vector And-Not instruction
correct XorL to XorI and add Tests
1 parent 900f9b8 commit f265ddf

File tree

4 files changed

+143
-8
lines changed

4 files changed

+143
-8
lines changed

src/hotspot/cpu/riscv/riscv_v.ad

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ instruct vandnI_regI(vReg dst, vReg src2, iRegIorL2I src1, immI_M1 m1) %{
11851185
predicate(Matcher::vector_element_basic_type(n) == T_INT ||
11861186
Matcher::vector_element_basic_type(n) == T_BYTE ||
11871187
Matcher::vector_element_basic_type(n) == T_SHORT);
1188-
match(Set dst (AndV src2 (Replicate (XorL src1 m1))));
1188+
match(Set dst (AndV src2 (Replicate (XorI src1 m1))));
11891189
format %{ "vandn.vx $dst, $src2, $src1" %}
11901190
ins_encode %{
11911191
BasicType bt = Matcher::vector_element_basic_type(this);

test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1985,16 +1985,18 @@ public class IRNode {
19851985
public static final String VAND_NOT_I = PREFIX + "VAND_NOT_I" + POSTFIX;
19861986
static {
19871987
machOnlyNameRegex(VAND_NOT_I, "vand_notI");
1988+
machOnlyNameRegex(VAND_NOT_I, "vandnI");
19881989
}
19891990

1990-
public static final String VAND_NOT_I_RISCV = PREFIX + "VAND_NOT_I" + POSTFIX;
1991+
public static final String VAND_NOT_L = PREFIX + "VAND_NOT_L" + POSTFIX;
19911992
static {
1992-
machOnlyNameRegex(VAND_NOT_I_RISCV, "vandnI");
1993+
machOnlyNameRegex(VAND_NOT_L, "vand_notL");
1994+
machOnlyNameRegex(VAND_NOT_L, "vandnL");
19931995
}
19941996

1995-
public static final String VAND_NOT_L = PREFIX + "VAND_NOT_L" + POSTFIX;
1997+
public static final String VAND_NOT_I_MASKED = PREFIX + "VAND_NOT_I_MASKED" + POSTFIX;
19961998
static {
1997-
machOnlyNameRegex(VAND_NOT_L, "vand_notL");
1999+
machOnlyNameRegex(VAND_NOT_I_MASKED, "vandnI_masked");
19982000
}
19992001

20002002
public static final String VECTOR_BLEND_B = VECTOR_PREFIX + "VECTOR_BLEND_B" + POSTFIX;

test/hotspot/jtreg/compiler/vectorapi/AllBitsSetVectorMatchRuleTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @key randomness
4343
* @library /test/lib /
4444
* @requires vm.compiler2.enabled
45-
* @requires (vm.cpu.features ~= ".*asimd.*") | (os.simpleArch == "riscv64" & vm.cpu.features ~= ".*zvbb.*")
45+
* @requires vm.cpu.features ~= ".*asimd.*"
4646
* @summary AArch64: [vector] Make all bits set vector sharable for match rules
4747
* @modules jdk.incubator.vector
4848
*
@@ -84,8 +84,7 @@ public class AllBitsSetVectorMatchRuleTest {
8484

8585
@Test
8686
@Warmup(10000)
87-
@IR(counts = { IRNode.VAND_NOT_I, " >= 1" }, applyIf = {"UseZvbb", "0"})
88-
@IR(counts = { IRNode.VAND_NOT_I_RISCV, " >= 1" }, applyIf = {"UseZvbb", "> 0"})
87+
@IR(counts = { IRNode.VAND_NOT_I, " >= 1" })
8988
public static void testAllBitsSetVector() {
9089
IntVector av = IntVector.fromArray(I_SPECIES, ia, 0);
9190
IntVector bv = IntVector.fromArray(I_SPECIES, ib, 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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

Comments
 (0)