Skip to content

Commit

Permalink
Fix signedness handling in comparison instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
nmeum committed Apr 29, 2024
1 parent ed96240 commit ef3ec46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
10 changes: 2 additions & 8 deletions angr_platforms/risc_v/instrs_riscv/i_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ class Instruction_SLTI(I_Instruction):

# TODO: ISA manual mentions sign extension, check if properly implemented
def compute_result(self, src1, imm):
src1.is_signed = True
imm.is_signed = True
val = 1 if src1.signed < imm.signed else 0
return self.constant(val, Type.int_32)
return (src1.signed < imm.signed).ite(1, 0)


class Instruction_SLTIU(I_Instruction):
Expand All @@ -106,10 +103,7 @@ class Instruction_SLTIU(I_Instruction):
name = 'SLTIU'

def compute_result(self, src1, imm):
src1.is_signed = False
imm.is_signed = False
val = 1 if src1 < imm else 0
return self.constant(val, Type.int_32)
return (src1 < imm).ite(1, 0)

class Instruction_LB(I_Instruction):
func3='000'
Expand Down
11 changes: 2 additions & 9 deletions angr_platforms/risc_v/instrs_riscv/r_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ class Instruction_SLT(R_Instruction):
name='SLT'

def compute_result(self, src1, src2):
src1.is_signed = True
src2.is_signed = True
val = 1 if src1 < src2 else 0
return self.constant(val, Type.int_32)

return (src1.signed < src2.signed).ite(1, 0)

class Instruction_SLTU(R_Instruction):
func3 = '011'
Expand All @@ -108,10 +104,7 @@ class Instruction_SLTU(R_Instruction):
name = 'SLTU'

def compute_result(self, src1, src2):
src1.is_signed = False
src1.is_signed = False
val = 1 if src1 < src2 else 0
return self.constant(val, Type.int_32)
return (src1 < src2).ite(1, 0)


class Instruction_MUL(R_Instruction):
Expand Down

0 comments on commit ef3ec46

Please sign in to comment.