Skip to content

Commit fff9a1d

Browse files
committed
lightrec: Fix count_leading_bits
patching here until upstream reacts
1 parent 4e27dfa commit fff9a1d

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

deps/lightrec/lightrec.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -567,22 +567,12 @@ static void lightrec_mtc0(struct lightrec_state *state, u8 reg, u32 data)
567567

568568
static u32 count_leading_bits(s32 data)
569569
{
570-
u32 cnt = 33;
571-
572-
#ifdef __has_builtin
573-
#if __has_builtin(__builtin_clrsb)
570+
#if defined(__has_builtin) && __has_builtin(__builtin_clrsb)
574571
return 1 + __builtin_clrsb(data);
572+
#else
573+
data ^= data >> 31;
574+
return data ? clz32(data) : 32;
575575
#endif
576-
#endif
577-
578-
data = (data ^ (data >> 31)) << 1;
579-
580-
do {
581-
cnt -= 1;
582-
data >>= 1;
583-
} while (data);
584-
585-
return cnt;
586576
}
587577

588578
static void lightrec_mtc2(struct lightrec_state *state, u8 reg, u32 data)

0 commit comments

Comments
 (0)