]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: replace x86 bsf asm in scheduler with portable __builtin_ctz
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:50:27 +0000 (01:50 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:50:27 +0000 (01:50 -0300)
bsf32() used x86-only 'bsf' inline assembly to find the lowest
set bit in the O(1) scheduler bitmap. This would not compile on
ARM/RISC-V/MIPS. Replace with __builtin_ctz() which GCC supports
on all target architectures.

Passes: make, cppcheck, QEMU smoke test.

src/kernel/scheduler.c

index 958eabcbb7d0d1cb19135be6a81f7632c360d765..43a8b03ce8c3f46949e333599df1cc12f352e396 100644 (file)
@@ -38,9 +38,7 @@ static struct runqueue* rq_active  = &rq_active_store;
 static struct runqueue* rq_expired = &rq_expired_store;
 
 static inline uint32_t bsf32(uint32_t v) {
-    uint32_t r;
-    __asm__ volatile("bsf %1, %0" : "=r"(r) : "rm"(v) : "cc");
-    return r;
+    return (uint32_t)__builtin_ctz(v);
 }
 
 static void rq_enqueue(struct runqueue* rq, struct process* p) {