Skip to content

Commit 2f9e70e

Browse files
author
Hamlin Li
committed
8321001: RISC-V: C2 SignumVF
8321002: RISC-V: C2 SignumVD Reviewed-by: fyang
1 parent de95259 commit 2f9e70e

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

src/hotspot/cpu/riscv/assembler_riscv.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ enum VectorMask {
14171417
INSN(vmfeq_vv, 0b1010111, 0b001, 0b011000);
14181418

14191419
// Vector Floating-Point Sign-Injection Instructions
1420+
INSN(vfsgnj_vv, 0b1010111, 0b001, 0b001000);
14201421
INSN(vfsgnjx_vv, 0b1010111, 0b001, 0b001010);
14211422
INSN(vfsgnjn_vv, 0b1010111, 0b001, 0b001001);
14221423

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,19 @@ void C2_MacroAssembler::signum_fp(FloatRegister dst, FloatRegister one, bool is_
16771677
bind(done);
16781678
}
16791679

1680+
void C2_MacroAssembler::signum_fp_v(VectorRegister dst, VectorRegister one, BasicType bt, int vlen) {
1681+
vsetvli_helper(bt, vlen);
1682+
1683+
// check if input is -0, +0, signaling NaN or quiet NaN
1684+
vfclass_v(v0, dst);
1685+
mv(t0, fclass_mask::zero | fclass_mask::nan);
1686+
vand_vx(v0, v0, t0);
1687+
vmseq_vi(v0, v0, 0);
1688+
1689+
// use floating-point 1.0 with a sign of input
1690+
vfsgnj_vv(dst, one, dst, v0_t);
1691+
}
1692+
16801693
void C2_MacroAssembler::compress_bits_v(Register dst, Register src, Register mask, bool is_long) {
16811694
Assembler::SEW sew = is_long ? Assembler::e64 : Assembler::e32;
16821695
// intrinsic is enabled when MaxVectorSize >= 16

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163

164164
void signum_fp(FloatRegister dst, FloatRegister one, bool is_double);
165165

166+
void signum_fp_v(VectorRegister dst, VectorRegister one, BasicType bt, int vlen);
167+
166168
// intrinsic methods implemented by rvv instructions
167169

168170
// compress bits, i.e. j.l.Integer/Long::compress.

src/hotspot/cpu/riscv/riscv_v.ad

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,23 @@ instruct vexpand(vReg dst, vReg src, vRegMask_V0 v0, vReg tmp) %{
36603660
ins_pipe(pipe_slow);
36613661
%}
36623662

3663+
// ------------------------------ Vector signum --------------------------------
3664+
3665+
// Vector Math.signum
3666+
3667+
instruct vsignum_reg(vReg dst, vReg zero, vReg one, vRegMask_V0 v0) %{
3668+
match(Set dst (SignumVF dst (Binary zero one)));
3669+
match(Set dst (SignumVD dst (Binary zero one)));
3670+
effect(TEMP_DEF dst, TEMP v0);
3671+
format %{ "vsignum $dst, $dst\t" %}
3672+
ins_encode %{
3673+
BasicType bt = Matcher::vector_element_basic_type(this);
3674+
__ signum_fp_v(as_VectorRegister($dst$$reg), as_VectorRegister($one$$reg),
3675+
bt, Matcher::vector_length(this));
3676+
%}
3677+
ins_pipe(pipe_slow);
3678+
%}
3679+
36633680
// ------------------------------ Vector Load Gather ---------------------------
36643681

36653682
instruct gather_load(vReg dst, indirect mem, vReg idx) %{

test/hotspot/jtreg/compiler/vectorization/TestSignumVector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
/**
2525
* @test
2626
* @bug 8282711 8290249
27-
* @summary Accelerate Math.signum function for AVX, AVX512 and aarch64 (Neon and SVE)
27+
* @summary Accelerate Math.signum function for AVX, AVX512, aarch64 (Neon and SVE)
28+
* and riscv64 (vector)
2829
* @requires vm.compiler2.enabled
29-
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx.*") | os.arch == "aarch64"
30+
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx.*") | os.arch == "aarch64" |
31+
* (os.arch == "riscv64" & vm.cpu.features ~= ".*v,.*")
3032
* @library /test/lib /
3133
* @run driver compiler.vectorization.TestSignumVector
3234
*/

0 commit comments

Comments
 (0)