From: notaz Date: Sat, 29 Mar 2025 23:50:22 +0000 (+0200) Subject: lightrec: Fix count_leading_bits X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fff9a1d4343499d5069bc6f731a9b2959c2a6f53;p=pcsx_rearmed.git lightrec: Fix count_leading_bits patching here until upstream reacts --- 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)