diff options
author | Sergey Kandaurov <pluknet@nginx.com> | 2018-06-20 19:34:06 +0300 |
---|---|---|
committer | Sergey Kandaurov <pluknet@nginx.com> | 2018-06-20 19:34:06 +0300 |
commit | 14bc4013941d38740d10681e7d54711f95cb38c4 (patch) | |
tree | 43713a1548b6b3419f7a1e918067532d6abd9184 | |
parent | 50d458796180367b9e2e65884abd538f31b774de (diff) | |
download | unit-14bc4013941d38740d10681e7d54711f95cb38c4.tar.gz unit-14bc4013941d38740d10681e7d54711f95cb38c4.tar.bz2 |
Using own popcount where the compiler builtin is not available.
-rw-r--r-- | auto/clang | 13 | ||||
-rw-r--r-- | src/nxt_clang.h | 21 | ||||
-rw-r--r-- | src/nxt_conf_validation.c | 2 |
3 files changed, 35 insertions, 1 deletions
@@ -101,6 +101,19 @@ nxt_feature_test="int main() { . auto/feature +nxt_feature="GCC __builtin_popcount()" +nxt_feature_name=NXT_HAVE_BUILTIN_POPCOUNT +nxt_feature_run= +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="int main() { + if (__builtin_popcount(5) == 2) + return 0; + return 1; + }" +. auto/feature + + nxt_feature="GCC __attribute__ visibility" nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_VISIBILITY nxt_feature_run= diff --git a/src/nxt_clang.h b/src/nxt_clang.h index 60d12fb2..0622aad3 100644 --- a/src/nxt_clang.h +++ b/src/nxt_clang.h @@ -132,6 +132,27 @@ nxt_prefetch(a) #endif +#if (NXT_HAVE_BUILTIN_POPCOUNT) + +#define nxt_popcount __builtin_popcount + +#else + +nxt_inline int +nxt_popcount(unsigned int x) +{ + int count; + + for (count = 0; x != 0; x >>= 1) { + count += (x & 1); + } + + return count; +} + +#endif + + #ifndef NXT_ALIGNMENT #if (NXT_SOLARIS) diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 7d9c9631..4fb4720f 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -331,7 +331,7 @@ nxt_conf_vldt_type(nxt_conf_validation_t *vldt, nxt_str_t *name, p = buf; - n = __builtin_popcount(type); + n = nxt_popcount(type); if (n > 1) { p = nxt_cpymem(p, "either ", 7); |