Skip to content

Commit

Permalink
Merge pull request #146 from fennecJ/master
Browse files Browse the repository at this point in the history
Use branchless way to get rv_hi/rv_lo result
  • Loading branch information
jserv authored Aug 5, 2024
2 parents 6615b6c + 51284da commit 13b828d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,12 @@ int rv_extract_bits(int imm, int i_start, int i_end, int d_start, int d_end)

int rv_hi(int val)
{
if ((val & (1 << 11)) != 0)
return val + 4096;
return val;
return val + ((val & (1 << 11)) << 1);
}

int rv_lo(int val)
{
if ((val & (1 << 11)) != 0)
return (val & 0xFFF) - 4096;
return val & 0xFFF;
return (val & 0xFFF) - ((val & (1 << 11)) << 1);
}

int rv_encode_R(rv_op op, rv_reg rd, rv_reg rs1, rv_reg rs2)
Expand Down

0 comments on commit 13b828d

Please sign in to comment.