lightrec: Fix count_leading_bits
authornotaz <notasas@gmail.com>
Sat, 29 Mar 2025 23:50:22 +0000 (01:50 +0200)
committernotaz <notasas@gmail.com>
Sat, 29 Mar 2025 23:50:22 +0000 (01:50 +0200)
patching here until upstream reacts

deps/lightrec/lightrec.c

index 5f6a871..c8e91b7 100644 (file)
@@ -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)