Skip to content

Commit

Permalink
Wrap built-in function with wrapper function
Browse files Browse the repository at this point in the history
wrap __builtin_ffs with static inline ffs function.
  • Loading branch information
ranvd committed Jun 25, 2024
1 parent 54bcc0b commit 932709b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ static inline int ilog2(int x)
return 31 - __builtin_clz(x | 1);
}

static inline int ffs(int x)
{
return __builtin_ffs(x);
}

/* Range check
* For any variable range checking:
* if (x >= minx && x <= maxx) ...
Expand Down
2 changes: 1 addition & 1 deletion riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ void vm_step(hart_t *vm)
vm->current_pc = vm->pc;
if ((vm->sstatus_sie || !vm->s_mode) && (vm->sip & vm->sie)) {
uint32_t applicable = (vm->sip & vm->sie);
uint8_t idx = __builtin_ffs(applicable) - 1;
uint8_t idx = ffs(applicable) - 1;
if (idx == 1) {
emu_state_t *data = PRIV(vm);
data->clint.msip[vm->mhartid] = 0;
Expand Down

0 comments on commit 932709b

Please sign in to comment.