8322753: RISC-V: C2 ReverseBytesV

Reviewed-by: fyang
This commit is contained in:
Hamlin Li 2024-05-09 07:05:18 +00:00
parent 2d622152b0
commit 964d60892e
6 changed files with 41 additions and 5 deletions

View File

@ -1887,8 +1887,9 @@ enum Nf {
}
// Vector Bit-manipulation used in Cryptography (Zvkb) Extension
INSN(vbrev8_v, 0b1010111, 0b010, 0b01000, 0b010010);
INSN(vrev8_v, 0b1010111, 0b010, 0b01001, 0b010010);
INSN(vbrev_v, 0b1010111, 0b010, 0b01010, 0b010010); // reverse bits in every element
INSN(vbrev8_v, 0b1010111, 0b010, 0b01000, 0b010010); // reverse bits in every byte of element
INSN(vrev8_v, 0b1010111, 0b010, 0b01001, 0b010010); // reverse bytes in every elememt
#undef INSN

View File

@ -73,6 +73,7 @@ source %{
return false;
}
break;
case Op_ReverseBytesV:
case Op_PopCountVL:
case Op_PopCountVI:
return UseZvbb;
@ -3756,6 +3757,32 @@ instruct vsignum_reg(vReg dst, vReg zero, vReg one, vRegMask_V0 v0) %{
ins_pipe(pipe_slow);
%}
// -------------------------------- Reverse Bytes Vector Operations ------------------------
instruct vreverse_bytes_masked(vReg dst, vReg src, vRegMask_V0 v0) %{
match(Set dst (ReverseBytesV src v0));
format %{ "vreverse_bytes_masked $dst, $src, v0" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
uint vlen = Matcher::vector_length(this);
__ vsetvli_helper(bt, vlen);
__ vrev8_v(as_VectorRegister($dst$$reg), as_VectorRegister($src$$reg), Assembler::v0_t);
%}
ins_pipe(pipe_slow);
%}
instruct vreverse_bytes(vReg dst, vReg src) %{
match(Set dst (ReverseBytesV src));
format %{ "vreverse_bytes $dst, $src" %}
ins_encode %{
BasicType bt = Matcher::vector_element_basic_type(this);
uint vlen = Matcher::vector_length(this);
__ vsetvli_helper(bt, vlen);
__ vrev8_v(as_VectorRegister($dst$$reg), as_VectorRegister($src$$reg));
%}
ins_pipe(pipe_slow);
%}
// ---------------- Convert Half Floating to Floating Vector Operations ----------------
// half precision -> single
@ -3790,7 +3817,7 @@ instruct vconvF2HF(vReg dst, vReg src, vReg vtmp, vRegMask_V0 v0, iRegINoSp tmp)
// ------------------------------ Popcount vector ------------------------------
instruct vpopcount_mask(vReg dst, vReg src, vRegMask_V0 v0) %{
instruct vpopcount_masked(vReg dst, vReg src, vRegMask_V0 v0) %{
match(Set dst (PopCountVI src v0));
match(Set dst (PopCountVL src v0));
ins_cost(VEC_COST);

View File

@ -42,7 +42,8 @@ import jdk.test.lib.Utils;
* @library /test/lib /
* @summary [vectorapi] REVERSE_BYTES for byte type should not emit any instructions
* @requires vm.compiler2.enabled
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.arch == "aarch64"
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.arch == "aarch64" |
* (os.arch == "riscv64" & vm.cpu.features ~= ".*zvbb.*")
* @modules jdk.incubator.vector
*
* @run driver compiler.vectorapi.VectorReverseBytesTest

View File

@ -25,7 +25,8 @@
* @bug 8288112
* @summary Auto-vectorization of ReverseBytes operations.
* @requires vm.compiler2.enabled
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.simpleArch == "AArch64"
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.simpleArch == "AArch64" |
* (os.simpleArch == "riscv64" & vm.cpu.features ~= ".*zvbb.*")
* @library /test/lib /
* @run driver compiler.vectorization.TestReverseBytes
*/

View File

@ -227,6 +227,9 @@ public class BasicCharOpTest extends VectorizationTestRunner {
@Test
@IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true"},
counts = {IRNode.REVERSE_BYTES_VS, ">0"})
@IR(applyIfPlatform = {"riscv64", "true"},
applyIfCPUFeature = {"zvbb", "true"},
counts = {IRNode.REVERSE_BYTES_VS, ">0"})
public char[] reverseBytesWithChar() {
char[] res = new char[SIZE];
for (int i = 0; i < SIZE; i++) {

View File

@ -250,6 +250,9 @@ public class BasicShortOpTest extends VectorizationTestRunner {
@Test
@IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true"},
counts = {IRNode.REVERSE_BYTES_VS, ">0"})
@IR(applyIfPlatform = {"riscv64", "true"},
applyIfCPUFeature = {"zvbb", "true"},
counts = {IRNode.REVERSE_BYTES_VS, ">0"})
public short[] reverseBytesWithShort() {
short[] res = new short[SIZE];
for (int i = 0; i < SIZE; i++) {