ck_internal: Fix bsf behavior.

ck_pring
Samy Al Bahra 12 years ago
parent f74c0eca62
commit 7355d0ea49

@ -84,15 +84,19 @@ ck_internal_max_32(uint32_t x, uint32_t y)
CK_CC_INLINE static unsigned long CK_CC_INLINE static unsigned long
ck_internal_bsf(unsigned long v) ck_internal_bsf(unsigned long v)
{ {
#if defined(__GNUC__)
return __builtin_ffs(v);
#else
unsigned int i; unsigned int i;
const unsigned int s = sizeof(unsigned long) * 8 - 1; const unsigned int s = sizeof(unsigned long) * 8 - 1;
for (i = 0; i < s; i++) { for (i = 0; i < s; i++) {
if (v & (1UL << (s - i))) if (v & (1UL << (s - i)))
return i; return sizeof(unsigned long) * 8 - i;
} }
return 1; return 1;
#endif /* !__GNUC__ */
} }
CK_CC_INLINE static uint64_t CK_CC_INLINE static uint64_t

Loading…
Cancel
Save