mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8330156: RISC-V: Range check auipc + signed 12 imm instruction
Backport-of: 8990864a53
This commit is contained in:
committed by
Vitaly Provodin
parent
f25d8f7df5
commit
e60627e900
@@ -720,7 +720,7 @@ void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Reg
|
||||
|
||||
void MacroAssembler::la(Register Rd, const address dest) {
|
||||
int64_t offset = dest - pc();
|
||||
if (is_simm32(offset)) {
|
||||
if (is_valid_32bit_offset(offset)) {
|
||||
auipc(Rd, (int32_t)offset + 0x800); //0x800, Note:the 11th sign bit
|
||||
addi(Rd, Rd, ((int64_t)offset << 52) >> 52);
|
||||
} else {
|
||||
|
||||
@@ -640,6 +640,14 @@ private:
|
||||
int pop_v(unsigned int bitset, Register stack);
|
||||
#endif // COMPILER2
|
||||
|
||||
// The signed 20-bit upper imm can materialize at most negative 0xF...F80000000, two G.
|
||||
// The following signed 12-bit imm can at max subtract 0x800, two K, from that previously loaded two G.
|
||||
bool is_valid_32bit_offset(int64_t x) {
|
||||
constexpr int64_t twoG = (2 * G);
|
||||
constexpr int64_t twoK = (2 * K);
|
||||
return x < (twoG - twoK) && x >= (-twoG - twoK);
|
||||
}
|
||||
|
||||
public:
|
||||
void push_reg(Register Rs);
|
||||
void pop_reg(Register Rd);
|
||||
@@ -794,7 +802,7 @@ public:
|
||||
void NAME(Register Rd, address dest) { \
|
||||
assert_cond(dest != nullptr); \
|
||||
int64_t distance = dest - pc(); \
|
||||
if (is_simm32(distance)) { \
|
||||
if (is_valid_32bit_offset(distance)) { \
|
||||
auipc(Rd, (int32_t)distance + 0x800); \
|
||||
Assembler::NAME(Rd, Rd, ((int32_t)distance << 20) >> 20); \
|
||||
} else { \
|
||||
@@ -851,7 +859,7 @@ public:
|
||||
void NAME(FloatRegister Rd, address dest, Register temp = t0) { \
|
||||
assert_cond(dest != nullptr); \
|
||||
int64_t distance = dest - pc(); \
|
||||
if (is_simm32(distance)) { \
|
||||
if (is_valid_32bit_offset(distance)) { \
|
||||
auipc(temp, (int32_t)distance + 0x800); \
|
||||
Assembler::NAME(Rd, temp, ((int32_t)distance << 20) >> 20); \
|
||||
} else { \
|
||||
@@ -912,7 +920,7 @@ public:
|
||||
assert_cond(dest != nullptr); \
|
||||
assert_different_registers(Rs, temp); \
|
||||
int64_t distance = dest - pc(); \
|
||||
if (is_simm32(distance)) { \
|
||||
if (is_valid_32bit_offset(distance)) { \
|
||||
auipc(temp, (int32_t)distance + 0x800); \
|
||||
Assembler::NAME(Rs, temp, ((int32_t)distance << 20) >> 20); \
|
||||
} else { \
|
||||
@@ -957,7 +965,7 @@ public:
|
||||
void NAME(FloatRegister Rs, address dest, Register temp = t0) { \
|
||||
assert_cond(dest != nullptr); \
|
||||
int64_t distance = dest - pc(); \
|
||||
if (is_simm32(distance)) { \
|
||||
if (is_valid_32bit_offset(distance)) { \
|
||||
auipc(temp, (int32_t)distance + 0x800); \
|
||||
Assembler::NAME(Rs, temp, ((int32_t)distance << 20) >> 20); \
|
||||
} else { \
|
||||
|
||||
Reference in New Issue
Block a user