diff --git a/src/c/util/math/popcount.c b/src/c/util/math/popcount.c index e371274c..c0f691bb 100644 --- a/src/c/util/math/popcount.c +++ b/src/c/util/math/popcount.c @@ -3,12 +3,16 @@ #include #include +#if !defined(BUILTIN) && (defined(__GNUC__) || defined(__clang__)) +#define USE_BUILTIN +#endif + int main(int argc, char *argv[]) { ssize_t nread, i; size_t popcount; char buf[PIPE_BUF]; -#if defined(__GNUC__) || defined(__clang__) +#ifndef USE_BUILTIN unsigned int c; #else char c; @@ -18,7 +22,7 @@ int main(int argc, char *argv[]) while ((nread = read(STDIN_FILENO, buf, PIPE_BUF)) > 0) { for (i = 0; i < nread; i++) { c = buf[i]; -#if defined(__GNUC__) || defined(__clang__) +#ifndef USE_BUILTIN popcount += __builtin_popcount(c & 0xff); #else popcount += c & 0x01 + c & 0x02 + c & 0x04 + c & 0x08 + c & 0x10 + c & 0x20 + c &