Skip to content

Commit

Permalink
RISC-V: Add addi-x0 support for small immediates
Browse files Browse the repository at this point in the history
Currently immediates in the range of -2**11 to 2**11-1 generate a lui 0 call.
This can be optimized to addi x0 directly when setting a register.

Signed-Off-By: Patrick O'Neill <[email protected]>
  • Loading branch information
patrick-rivos authored and rbertran committed Jun 27, 2024
1 parent 300a542 commit 1965787
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions targets/riscv/isa/riscv-common/isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def set_register(
)
instrs.append(addi)

elif value >= -(2**11) and value < (2**11):
addi = self.new_instruction("ADDI_V0")
addi.set_operands([value, self.registers["X0"], register])
instrs.append(addi)

elif value >= -(2**31) and value < (2**31):
LOG.debug("Short path")

Expand Down

0 comments on commit 1965787

Please sign in to comment.