Skip to content

Commit 95b74d4

Browse files
author
luxufan
committed
[JITLink] Improve extractBits function
Address the advice proposed at patch D105429 . Use [Low, Low+size) to represent bits. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D107250
1 parent 1c66691 commit 95b74d4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ static Expected<const Edge &> getRISCVPCRelHi20(const Edge &E) {
157157
"No HI20 PCREL relocation type be found for LO12 PCREL relocation type");
158158
}
159159

160-
static uint32_t extractBits(uint64_t Num, unsigned High, unsigned Low) {
161-
return (Num & ((1ULL << (High + 1)) - 1)) >> Low;
160+
static uint32_t extractBits(uint32_t Num, unsigned Low, unsigned Size) {
161+
return (Num & (((1ULL << (Size + 1)) - 1) << Low)) >> Low;
162162
}
163163

164164
class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
@@ -238,8 +238,8 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
238238
int64_t Value = RelHI20->getTarget().getAddress() +
239239
RelHI20->getAddend() - E.getTarget().getAddress();
240240
int64_t Lo = Value & 0xFFF;
241-
uint32_t Imm31_25 = extractBits(Lo, 11, 5) << 25;
242-
uint32_t Imm11_7 = extractBits(Lo, 4, 0) << 7;
241+
uint32_t Imm31_25 = extractBits(Lo, 5, 7) << 25;
242+
uint32_t Imm11_7 = extractBits(Lo, 0, 5) << 7;
243243
uint32_t RawInstr = *(little32_t *)FixupPtr;
244244

245245
*(little32_t *)FixupPtr = (RawInstr & 0x1FFF07F) | Imm31_25 | Imm11_7;

0 commit comments

Comments
 (0)