Use __builtin_ffs instead of ffs (#554)
authorMartin Storsjö <martin@martin.st>
Sun, 26 Apr 2020 01:59:35 +0000 (04:59 +0300)
committerGitHub <noreply@github.com>
Sun, 26 Apr 2020 01:59:35 +0000 (21:59 -0400)
USE_BUILTIN_FFS is defined to 1 within __GNUC__, and the __builtin_ffs
function is available since GCC 3.x at least, while the ffs function
only exists on some OSes.

This fixes compilation for non-x86 mingw platforms. For x86,
USE_BUILTIN_FFS is explicitly disabled for windows targets - but
if USE_BUILTIN_FFS is enabled based on __GNUC__, it should also use
the builtin which actually is available correspondingly, not dependent
on the target OS.

src/dlmalloc.c

index d63dd36dc9b8bbf98aa319343577789c3ebb2694..1aba657edb51fb8d067985d3a8e707b5cf4adb5c 100644 (file)
@@ -2371,7 +2371,7 @@ static size_t traverse_and_check(mstate m);
 
 #else /* GNUC */
 #if  USE_BUILTIN_FFS
-#define compute_bit2idx(X, I) I = ffs(X)-1
+#define compute_bit2idx(X, I) I = __builtin_ffs(X)-1
 
 #else /* USE_BUILTIN_FFS */
 #define compute_bit2idx(X, I)\