Skip to content

Commit e73db5d

Browse files
Yanhong ZhuRealFYang
authored andcommitted
8279346: riscv: Unnecessary sign extension in BigInteger intrinsics
Reviewed-by: fyang
1 parent b396cdd commit e73db5d

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

src/hotspot/cpu/riscv/assembler_riscv_v.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@
2727
#define CPU_RISCV_ASSEMBLER_RISCV_V_HPP
2828

2929
enum SEW {
30-
e8 = 0b000,
31-
e16 = 0b001,
32-
e32 = 0b010,
33-
e64 = 0b011,
34-
e128 = 0b100,
35-
e256 = 0b101,
36-
e512 = 0b110,
37-
e1024 = 0b111,
30+
e8,
31+
e16,
32+
e32,
33+
e64,
34+
RESERVED,
3835
};
3936

4037
enum LMUL {
@@ -57,14 +54,18 @@ enum VTA {
5754
ta, // agnostic
5855
};
5956

60-
static Assembler::SEW elemBytes_to_sew(int esize) {
61-
assert(esize > 0 && esize <= 64 && is_power_of_2(esize), "unsupported element size");
62-
return (Assembler::SEW) log2i_exact(esize);
57+
static Assembler::SEW elembytes_to_sew(int ebytes) {
58+
assert(ebytes > 0 && ebytes <= 8, "unsupported element size");
59+
return (Assembler::SEW) exact_log2(ebytes);
60+
}
61+
62+
static Assembler::SEW elemtype_to_sew(BasicType etype) {
63+
return Assembler::elembytes_to_sew(type2aelembytes(etype));
6364
}
6465

6566
#define patch_vtype(hsb, lsb, vlmul, vsew, vta, vma, vill) \
6667
if (vill == 1) { \
67-
guarantee((vlmul | vsew | vsew | vta | vma == 0), \
68+
guarantee((vlmul | vsew | vta | vma == 0), \
6869
"the other bits in vtype shall be zero"); \
6970
} \
7071
patch((address)&insn, lsb + 2, lsb, vlmul); \

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,6 @@ void MacroAssembler::mul_add(Register out, Register in, Register offset,
30533053
Label L_tail_loop, L_unroll, L_end;
30543054
mv(tmp, out);
30553055
mv(out, zr);
3056-
sign_extend(len, len, 32);
30573056
blez(len, L_end);
30583057
zero_extend(k, k, 32);
30593058
slliw(t0, offset, LogBytesPerInt);
@@ -3411,8 +3410,8 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
34113410
const Register product = xlen;
34123411
const Register x_xstart = zlen; // reuse register
34133412

3414-
sign_extend(idx, ylen, 32); // idx = ylen;
3415-
sign_extend(kdx, zlen, 32); // kdx = xlen+ylen;
3413+
mv(idx, ylen); // idx = ylen;
3414+
mv(kdx, zlen); // kdx = xlen+ylen;
34163415
mv(carry, zr); // carry = 0;
34173416

34183417
Label L_multiply_64_x_64_loop, L_done;
@@ -3436,7 +3435,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
34363435
Label L_second_loop_unaligned;
34373436
bind(L_second_loop_unaligned);
34383437
mv(carry, zr);
3439-
sign_extend(jdx, ylen, 32);
3438+
mv(jdx, ylen);
34403439
subw(xstart, xstart, 1);
34413440
bltz(xstart, L_done);
34423441
sub(sp, sp, 2 * wordSize);
@@ -3515,7 +3514,7 @@ void MacroAssembler::multiply_to_len(Register x, Register xlen, Register y, Regi
35153514

35163515
bind(L_second_loop_aligned);
35173516
mv(carry, zr); // carry = 0;
3518-
sign_extend(jdx, ylen, 32); // j = ystart+1
3517+
mv(jdx, ylen); // j = ystart+1
35193518

35203519
subw(xstart, xstart, 1); // i = xstart-1;
35213520
bltz(xstart, L_done);

src/hotspot/cpu/riscv/riscv_v.ad

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ source_hpp %{
3333
%}
3434

3535
source %{
36-
static Assembler::SEW elemType_to_sew(BasicType bt) {
37-
return Assembler::elemBytes_to_sew(type2aelembytes(bt));
38-
}
3936

4037
static void loadStore(C2_MacroAssembler masm, bool is_store,
4138
VectorRegister reg, BasicType bt, Register base) {
42-
Assembler::SEW sew = elemType_to_sew(bt);
39+
Assembler::SEW sew = Assembler::elemtype_to_sew(bt);
4340
masm.vsetvli(t0, x0, sew);
4441
if (is_store) {
4542
masm.vsex_v(reg, base, sew);
@@ -51,19 +48,19 @@ source %{
5148
bool op_vec_supported(int opcode) {
5249
switch (opcode) {
5350
// No multiply reduction instructions
54-
case Op_MulReductionVD: // fall through
55-
case Op_MulReductionVF: // fall through
56-
case Op_MulReductionVI: // fall through
57-
case Op_MulReductionVL: // fall through
51+
case Op_MulReductionVD:
52+
case Op_MulReductionVF:
53+
case Op_MulReductionVI:
54+
case Op_MulReductionVL:
5855
// Others
59-
case Op_Extract: // fall through
60-
case Op_ExtractB: // fall through
61-
case Op_ExtractC: // fall through
62-
case Op_ExtractD: // fall through
63-
case Op_ExtractF: // fall through
64-
case Op_ExtractI: // fall through
65-
case Op_ExtractL: // fall through
66-
case Op_ExtractS: // fall through
56+
case Op_Extract:
57+
case Op_ExtractB:
58+
case Op_ExtractC:
59+
case Op_ExtractD:
60+
case Op_ExtractF:
61+
case Op_ExtractI:
62+
case Op_ExtractL:
63+
case Op_ExtractS:
6764
case Op_ExtractUB:
6865
// Vector API specific
6966
case Op_AndReductionV:
@@ -370,7 +367,7 @@ instruct vmax(vReg dst, vReg src1, vReg src2) %{
370367
format %{ "vmax.vv $dst, $src1, $src2\t#@vmax" %}
371368
ins_encode %{
372369
BasicType bt = Matcher::vector_element_basic_type(this);
373-
Assembler::SEW sew = elemType_to_sew(bt);
370+
Assembler::SEW sew = Assembler::elemtype_to_sew(bt);
374371
__ vsetvli(t0, x0, sew);
375372
__ vmax_vv(as_VectorRegister($dst$$reg),
376373
as_VectorRegister($src1$$reg), as_VectorRegister($src2$$reg));
@@ -386,7 +383,7 @@ instruct vmin(vReg dst, vReg src1, vReg src2) %{
386383
format %{ "vmin.vv $dst, $src1, $src2\t#@vmin" %}
387384
ins_encode %{
388385
BasicType bt = Matcher::vector_element_basic_type(this);
389-
Assembler::SEW sew = elemType_to_sew(bt);
386+
Assembler::SEW sew = Assembler::elemtype_to_sew(bt);
390387
__ vsetvli(t0, x0, sew);
391388
__ vmin_vv(as_VectorRegister($dst$$reg),
392389
as_VectorRegister($src1$$reg), as_VectorRegister($src2$$reg));

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,7 @@ class StubGenerator: public StubCodeGenerator {
839839

840840
const Register src = x30, dst = x31, vl = x14, cnt = x15, tmp1 = x16, tmp2 = x17;
841841
assert_different_registers(s, d, cnt, vl, tmp, tmp1, tmp2);
842-
Assembler::SEW sew = Assembler::elemBytes_to_sew(granularity);
843-
assert(sew >= Assembler::e8 && sew <= Assembler::e64, "illegal SEW");
842+
Assembler::SEW sew = Assembler::elembytes_to_sew(granularity);
844843
Label loop_forward, loop_backward, done;
845844

846845
__ mv(dst, d);

0 commit comments

Comments
 (0)