From fff9a1d4343499d5069bc6f731a9b2959c2a6f53 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 30 Mar 2025 01:50:22 +0200 Subject: [PATCH] lightrec: Fix count_leading_bits patching here until upstream reacts --- deps/lightrec/lightrec.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/deps/lightrec/lightrec.c b/deps/lightrec/lightrec.c index 5f6a8712..c8e91b71 100644 --- a/deps/lightrec/lightrec.c +++ b/deps/lightrec/lightrec.c @@ -567,22 +567,12 @@ static void lightrec_mtc0(struct lightrec_state *state, u8 reg, u32 data) static u32 count_leading_bits(s32 data) { - u32 cnt = 33; - -#ifdef __has_builtin -#if __has_builtin(__builtin_clrsb) +#if defined(__has_builtin) && __has_builtin(__builtin_clrsb) return 1 + __builtin_clrsb(data); +#else + data ^= data >> 31; + return data ? clz32(data) : 32; #endif -#endif - - data = (data ^ (data >> 31)) << 1; - - do { - cnt -= 1; - data >>= 1; - } while (data); - - return cnt; } static void lightrec_mtc2(struct lightrec_state *state, u8 reg, u32 data) -- 2.39.5