Skip to content

Commit

Permalink
libs/libc/machine/risc-v/arch_elf.c: Minor optimization to _calc_imm
Browse files Browse the repository at this point in the history
Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Feb 8, 2024
1 parent bde9bf8 commit 88a37f4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libs/libc/machine/risc-v/arch_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,24 @@ static void _add_val(uint16_t *addr, uint32_t val)

static void _calc_imm(long offset, long *imm_hi, long *imm_lo)
{
long lo;
long hi = offset / 4096;
long r = offset % 4096;
long hi = offset / 0x1000;
long lo = offset - hi * 0x1000;

if (2047 < r)
if (0x7ff < lo)
{
hi++;
lo -= 0x1000;
}
else if (r < -2048)
else if (lo < -0x800)
{
hi--;
lo += 0x1000;
}

lo = offset - (hi * 4096);

binfo("offset=%ld: hi=%ld lo=%ld\n",
offset, hi, lo);

ASSERT(-2048 <= lo && lo <= 2047);
ASSERT(-0x800 <= lo && lo <= 0x7ff);

*imm_lo = lo;
*imm_hi = hi;
Expand Down

0 comments on commit 88a37f4

Please sign in to comment.