Skip to content

Commit

Permalink
auipc + 12b check
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Apr 11, 2024
1 parent 10b297c commit 31b66c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void MacroAssembler::la(Register Rd, const address addr) {

void MacroAssembler::la(Register Rd, const address addr, int32_t &offset) {
int64_t distance = addr - pc();
if (is_simm32(distance)) {
if (in_range_auipc_12bit(distance)) {
auipc(Rd, (int32_t)distance + 0x800);
offset = ((int32_t)distance << 20) >> 20;
} else {
Expand Down
14 changes: 10 additions & 4 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,12 @@ class MacroAssembler: public Assembler {
int pop_v(unsigned int bitset, Register stack);
#endif // COMPILER2

bool in_range_auipc_12bit(int64_t x) {
int64_t twoG = (2 * G);
int64_t twoK = (2 * K);
return x <= (twoG - twoK) && x >= (-twoG + twoK);
}

public:
void push_reg(Register Rs);
void pop_reg(Register Rd);
Expand Down Expand Up @@ -844,7 +850,7 @@ class MacroAssembler: public Assembler {
void NAME(Register Rd, address dest) { \
assert_cond(dest != nullptr); \
int64_t distance = dest - pc(); \
if (is_simm32(distance)) { \
if (in_range_auipc_12bit(distance)) { \
auipc(Rd, (int32_t)distance + 0x800); \
Assembler::NAME(Rd, Rd, ((int32_t)distance << 20) >> 20); \
} else { \
Expand Down Expand Up @@ -901,7 +907,7 @@ class MacroAssembler: public Assembler {
void NAME(FloatRegister Rd, address dest, Register temp = t0) { \
assert_cond(dest != nullptr); \
int64_t distance = dest - pc(); \
if (is_simm32(distance)) { \
if (in_range_auipc_12bit(distance)) { \
auipc(temp, (int32_t)distance + 0x800); \
Assembler::NAME(Rd, temp, ((int32_t)distance << 20) >> 20); \
} else { \
Expand Down Expand Up @@ -962,7 +968,7 @@ class MacroAssembler: public Assembler {
assert_cond(dest != nullptr); \
assert_different_registers(Rs, temp); \
int64_t distance = dest - pc(); \
if (is_simm32(distance)) { \
if (in_range_auipc_12bit(distance)) { \
auipc(temp, (int32_t)distance + 0x800); \
Assembler::NAME(Rs, temp, ((int32_t)distance << 20) >> 20); \
} else { \
Expand Down Expand Up @@ -1007,7 +1013,7 @@ class MacroAssembler: public Assembler {
void NAME(FloatRegister Rs, address dest, Register temp = t0) { \
assert_cond(dest != nullptr); \
int64_t distance = dest - pc(); \
if (is_simm32(distance)) { \
if (in_range_auipc_12bit(distance)) { \
auipc(temp, (int32_t)distance + 0x800); \
Assembler::NAME(Rs, temp, ((int32_t)distance << 20) >> 20); \
} else { \
Expand Down

0 comments on commit 31b66c0

Please sign in to comment.