From 932709b1bb5721ab3c556ecb60fef9a8c40723ca Mon Sep 17 00:00:00 2001 From: ranvd Date: Wed, 26 Jun 2024 00:45:07 +0800 Subject: [PATCH] Wrap built-in function with wrapper function wrap __builtin_ffs with static inline ffs function. --- common.h | 5 +++++ riscv.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index 2a45682..d379617 100644 --- a/common.h +++ b/common.h @@ -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) ... diff --git a/riscv.c b/riscv.c index a58318d..19bc91d 100644 --- a/riscv.c +++ b/riscv.c @@ -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;