From ce337c5863638b49a1f819740038ad42c488e496 Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 2 Mar 2017 23:12:31 +0100 Subject: [PATCH] Replace __builtin_clz() and __builtin_clzll() with some straight forward solution --- src/shared.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shared.c b/src/shared.c index d60f586ff..b73a67b2c 100644 --- a/src/shared.c +++ b/src/shared.c @@ -9,12 +9,20 @@ static inline int get_msb32 (const u32 v) { - return 32 - __builtin_clz (v); + int i; + + for (i = 32; i > 0; i--) if ((v >> (i - 1)) & 1) break; + + return i; } static inline int get_msb64 (const u64 v) { - return 64 - __builtin_clzll (v); + int i; + + for (i = 64; i > 0; i--) if ((v >> (i - 1)) & 1) break; + + return i; } bool overflow_check_u32_add (const u32 a, const u32 b)