From 1063efeb2275039a75eb6fe5e423845e28098df2 Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLEY" Date: Tue, 4 Apr 2017 07:35:52 -0400 Subject: build: clang has __builtin_popcount() and __builtin_ffs() Note: Even though gcc(1) will automatically treat ffs() and popcount() as built-in, calling them explicitly as __builtin in the source helps make it easier to find them. (And if no __builtin_ffs use the one in libc.) Change-Id: Ib74d9b221ff03a01df5ad05907024da1a83a7a88 BUG: 1438772 Signed-off-by: Kaleb S. KEITHLEY Reviewed-on: https://review.gluster.org/16993 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Xavier Hernandez --- libglusterfs/src/common-utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'libglusterfs/src/common-utils.c') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index bdf340d8612..56f545f28de 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -4616,7 +4616,7 @@ int gf_bits_count (uint64_t n) { int val = 0; -#ifdef _GNU_SOURCE +#if defined(__GNUC__) || defined(__clang__) val = __builtin_popcountll (n); #else n -= (n >> 1) & 0x5555555555555555ULL; @@ -4633,7 +4633,11 @@ gf_bits_count (uint64_t n) int gf_bits_index (uint64_t n) { - return ffsll(n) - 1; +#if defined(__GNUC__) || defined(__clang__) + return __builtin_ffsll (n) - 1; +#else + return ffsll (n) - 1; +#endif } const char* -- cgit