Skip to contentSkip to conversation

erofs-utils: fix bitops fls_long

PATCH Superseded Hongzhen Luo 2 participants 2 messages Jul 9, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: fix bitops fls_long

The __builtin_clz is for unsigned int, while it is applied to unsigned long. This fixes it by using __builtin_clzl.

---
 include/erofs/defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/erofs/defs.h +1 -1
index e0798c8..310a6ab 100644
@@ -288,7 +288,7 @@ static inline u32 get_unaligned_le64(const void *p)
 
 static inline unsigned int fls_long(unsigned long x)
 {
-	return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
+	return x ? sizeof(x) * 8 - __builtin_clzl(x) : 0;
 }
 
 static inline unsigned long lowbit(unsigned long n)
Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Hongzhen Luo

The __builtin_clz is for unsigned int, while it is applied to unsigned long. This fixes it by using __builtin_clzl.

Does it impact any exist use cases? If yes, we might need to add some words in the commit message.

Quoted 1 line

Thanks,
Gao Xiang