]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use the <stdbit.h> names for bit manipulation shims
authorOndřej Surý <ondrej@isc.org>
Wed, 20 Aug 2025 13:08:39 +0000 (15:08 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 26 Aug 2025 13:32:53 +0000 (15:32 +0200)
When <stdbit.h> is unavailable, use the stdc names like stdc_count_zeros
instead of ISC_COUNT_ZERO macros to simplify the code.

lib/dns/qp.c
lib/dns/qp_p.h
lib/dns/rpz.c
lib/isc/histo.c
lib/isc/include/isc/bit.h
lib/isc/include/isc/util.h

index 3f10bd04a4bd8e0dfd35b547526e73f961cefc8c..aa717c1301278a7d2b2a16d6bf5d8b4e7eb63240 100644 (file)
@@ -495,10 +495,10 @@ static dns_qpcell_t
 next_capacity(uint32_t prev_capacity, uint32_t size) {
        /*
         * Request size was floored at 2 because builtin_clz used to be 0.
-        * We keep this behavior because ISC_LEADING_ZEROS(0) = 32.
+        * We keep this behavior because stdc_leading_zeros(0) = 32.
         */
        size = ISC_MAX3(size, prev_capacity, 2U);
-       uint32_t log2 = 32U - ISC_LEADING_ZEROS(size - 1U);
+       uint32_t log2 = 32U - stdc_leading_zeros(size - 1U);
 
        return 1U << ISC_CLAMP(log2, QP_CHUNK_LOG_MIN, QP_CHUNK_LOG_MAX);
 }
index a5dce44d84157a512cc17fadeec0b0e0444a4811..ef9f1e33621626577fc8aec32e74accc076cfeb7 100644 (file)
@@ -753,7 +753,7 @@ static inline dns_qpweight_t
 branch_count_bitmap_before(dns_qpnode_t *n, dns_qpshift_t bit) {
        uint64_t mask = (1ULL << bit) - 1 - TAG_MASK;
        uint64_t bitmap = branch_index(n) & mask;
-       return (dns_qpweight_t)ISC_POPCOUNT(bitmap);
+       return (dns_qpweight_t)stdc_count_zeros(bitmap);
 }
 
 /*
index a2f34528683b622fc40acc2c93df28c9ec37fe20..a59cad006ae6db9d5fd920e1834332c9a2c682fa 100644 (file)
@@ -1095,7 +1095,7 @@ diff_keys(const dns_rpz_cidr_key_t *key1, dns_rpz_prefix_t prefix1,
        for (i = 0; bit < maxbit; i++, bit += DNS_RPZ_CIDR_WORD_BITS) {
                delta = key1->w[i] ^ key2->w[i];
                if (delta != 0) {
-                       bit += ISC_LEADING_ZEROS(delta);
+                       bit += stdc_leading_zeros(delta);
                        break;
                }
        }
index 25febb55c9741e13490e5adadf3a118cba4d08bf..aac7081db6979848d7f7dad642545360405d9ae2 100644 (file)
@@ -181,7 +181,7 @@ static inline uint
 value_to_key(const isc_histo_t *hg, uint64_t value) {
        /* ensure that denormal numbers are all in chunk zero */
        uint64_t chunked = value | CHUNKSIZE(hg);
-       int clz = ISC_LEADING_ZEROS(chunked);
+       int clz = stdc_leading_zeros(chunked);
        /* actually 1 less than the exponent except for denormals */
        uint exponent = 63 - hg->sigbits - clz;
        /* mantissa has leading bit set except for denormals */
index 0a39c29eafb2ca10dd74ee1bec5798cbcc151e15..637a68a2052c22419fcb92f8f114aaf17da6bdd6 100644 (file)
 #include <isc/attributes.h>
 #include <isc/util.h>
 
-#ifndef __has_header
-#define __has_header(x) 0
-#endif
-
 #if __has_header(<stdbit.h>)
 
 #include <stdbit.h>
 
-#define ISC_POPCOUNT(x)              stdc_count_zeros(x)
-#define ISC_LEADING_ZEROS(x)  stdc_leading_zeros(x)
-#define ISC_TRAILING_ZEROS(x) stdc_trailing_zeros(x)
-#define ISC_LEADING_ONES(x)   stdc_leading_ones(x)
-#define ISC_TRAILING_ONES(x)  stdc_trailing_ones(x)
-
 #else /* __has_header(<stdbit.h>) */
 
 #ifdef HAVE_BUILTIN_POPCOUNTG
-#define ISC_POPCOUNT(x) __builtin_popcountg(x)
+#define stdc_count_zeros(x) __builtin_popcountg(x)
 #else /* HAVE_BUILTIN_POPCOUNTG */
-#define ISC_POPCOUNT(x)                             \
+#define stdc_count_zeros(x)                         \
        _Generic((x),                               \
                unsigned int: __builtin_popcount,   \
                unsigned long: __builtin_popcountl, \
@@ -46,9 +36,9 @@
 #endif /* HAVE_BUILTIN_POPCOUNTG */
 
 #ifdef HAVE_BUILTIN_CLZG
-#define ISC_LEADING_ZEROS(x) __builtin_clzg(x, (int)(sizeof(x) * 8))
+#define stdc_leading_zeros(x) __builtin_clzg(x, (int)(sizeof(x) * 8))
 #else /* HAVE_BUILTIN_CLZG */
-#define ISC_LEADING_ZEROS(x)                            \
+#define stdc_leading_zeros(x)                           \
        (((x) == 0) ? (sizeof(x) * 8)                   \
                    : _Generic((x),                     \
                         unsigned int: __builtin_clz,   \
@@ -57,9 +47,9 @@
 #endif /* HAVE_BUILTIN_CLZG */
 
 #ifdef HAVE_BUILTIN_CTZG
-#define ISC_TRAILING_ZEROS(x) __builtin_ctzg(x, (int)sizeof(x) * 8)
+#define stdc_trailing_zeros(x) __builtin_ctzg(x, (int)sizeof(x) * 8)
 #else /* HAVE_BUILTIN_CTZG */
-#define ISC_TRAILING_ZEROS(x)                           \
+#define stdc_trailing_zeros(x)                          \
        (((x) == 0) ? (sizeof(x) * 8)                   \
                    : _Generic((x),                     \
                         unsigned int: __builtin_ctz,   \
@@ -67,8 +57,8 @@
                         unsigned long long: __builtin_ctzll)(x))
 #endif /* HAVE_BUILTIN_CTZG */
 
-#define ISC_LEADING_ONES(x)  ISC_LEADING_ZEROS(~(x))
-#define ISC_TRAILING_ONES(x) ISC_TRAILING_ZEROS(~(x))
+#define stdc_leading_ones(x)  stdc_leading_zeros(~(x))
+#define stdc_trailing_ones(x) stdc_trailing_zeros(~(x))
 
 #endif /* __has_header(<stdbit.h>) */
 
index 971f21dc1ee6aab3cc0ddbe4cf1720580e9ec690..95d93fd33240d8fb0ee77356cd6e7ec991e89496 100644 (file)
 #define __has_feature(x) 0
 #endif /* if !defined(__has_feature) */
 
+#ifndef __has_header
+#define __has_header(x) 0
+#endif
+
 /***
  *** General Macros.
  ***/