Skip to contentSkip to conversation

disas/riscv: Fix incorrect disassembly for `imm20` operand.

PATCH In review Wei Wu 2 participants 2 messages Jul 7, 2020 – Jul 10, 2020 RISC-V

lore
Share & tools
lore

Wei Wu

author
#0 lore raw

PATCH 1/1 disas/riscv: Fix incorrect disassembly for `imm20` operand.

imm20 operand type is used in LUI/AUIPC and other instructions. The value should not be left shifted 12bits for disassembly output.

---
 disas/riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disas/riscv.c +1 -1
index 278d9be924..a2b6472bd8 100644
@@ -2083,7 +2083,7 @@ static int32_t operand_imm12(rv_inst inst)
 
 static int32_t operand_imm20(rv_inst inst)
 {
-    return (((int64_t)inst << 32) >> 44) << 12;
+    return ((int64_t)inst << 32) >> 44;
 }
 
 static int32_t operand_jimm20(rv_inst inst)
Signature · 1 line
2.17.1
#1 lore raw

disas/riscv.c static int32_t operand_imm12(rv_inst inst) · line 2087

Quoted 5 lines · Wei Wu

static int32_t operand_imm20(rv_inst inst)
{

disas/riscv.c +1 -1
-    return (((int64_t)inst << 32) >> 44) << 12;
+    return ((int64_t)inst << 32) >> 44;
 }

There's no point in casting to int64_t, for one. But it would be better to use sextract32(inst, 12, 20).

r~