Skip to content

Commit

Permalink
lh-u
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Nov 9, 2023
1 parent a7c0190 commit 7c03ba3
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions src/hotspot/cpu/riscv/assembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ class Assembler : public AbstractAssembler {
}

INSN(lb, 0b0000011, 0b000);
INSN(lbu, 0b0000011, 0b100);
INSN(lh, 0b0000011, 0b001);
INSN(lhu, 0b0000011, 0b101);
INSN(lbu, 0b0000011, 0b100); // Zcb
INSN(_lh, 0b0000011, 0b001); // Zcb
INSN(_lhu, 0b0000011, 0b101); // Zcb
INSN(_lw, 0b0000011, 0b010);
INSN(lwu, 0b0000011, 0b110);
INSN(_ld, 0b0000011, 0b011);
Expand Down Expand Up @@ -2460,6 +2460,48 @@ enum Nf {

#undef INSN

template <bool Unsigned>
void c_lh_imp(Register Rd_Rs2, Register Rs1, uint32_t uimm) {
assert_cond(uimm == 0 || uimm == 2);
uint16_t insn = 0;
c_patch((address)&insn, 1, 0, 0b00);
c_patch_compressed_reg((address)&insn, 2, Rd_Rs2);
c_patch((address)&insn, 5, 5, (uimm & nth_bit(1)) >> 1);
c_patch((address)&insn, 6, 6, Unsigned ? 1 : 0);
c_patch_compressed_reg((address)&insn, 7, Rs1);
c_patch((address)&insn, 12, 10, 0b001);
c_patch((address)&insn, 15, 13, 0b100);
emit_int16(insn);
}

template <bool Unsigned>
void lh_imp(Register Rd_Rs2, Register Rs1, const int32_t uimm) {
if (!do_compress() ||
!Rs1->is_compressed_valid() ||
!Rd_Rs2->is_compressed_valid() ||
(uimm != 0 && uimm != 2)) {
_lh(Rd_Rs2, Rs1, uimm);
} else {
c_lh_imp<Unsigned>(Rd_Rs2, Rs1, uimm);
}
}

void c_lh(Register Rd_Rs2, Register Rs1, const int32_t uimm) {
c_lh_imp<false>(Rd_Rs2, Rs1, uimm);
}

void lh(Register Rd_Rs2, Register Rs1, const int32_t uimm) {
lh_imp<false>(Rd_Rs2, Rs1, uimm);
}

void c_lhu(Register Rd_Rs2, Register Rs1, const int32_t uimm) {
c_lh_imp<true>(Rd_Rs2, Rs1, uimm);
}

void lhu(Register Rd_Rs2, Register Rs1, const int32_t uimm) {
lh_imp<true>(Rd_Rs2, Rs1, uimm);
}

#define INSN(NAME, funct3, op) \
void NAME() { \
uint16_t insn = 0; \
Expand Down

0 comments on commit 7c03ba3

Please sign in to comment.