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);
}
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 */
#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, \
#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, \
#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, \
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>) */