#include "randperm.h"
#include <limits.h>
+#include <stdbit.h>
#include <stdint.h>
#include <stdlib.h>
#include "attribute.h"
-#include "count-leading-zeros.h"
#include "hash.h"
#include "xalloc.h"
-/* Return the floor of the log base 2 of N. If N is zero, return -1. */
-
-ATTRIBUTE_CONST static int
-floor_lg (size_t n)
-{
- static_assert (SIZE_WIDTH <= ULLONG_WIDTH);
- return (n == 0 ? -1
- : SIZE_WIDTH <= UINT_WIDTH
- ? UINT_WIDTH - 1 - count_leading_zeros (n)
- : SIZE_WIDTH <= ULONG_WIDTH
- ? ULONG_WIDTH - 1 - count_leading_zeros_l (n)
- : ULLONG_WIDTH - 1 - count_leading_zeros_ll (n));
-}
-
/* Return an upper bound on the number of random bytes needed to
generate the first H elements of a random permutation of N
elements. H must not exceed N. */
{
/* Upper bound on number of bits needed to generate the first number
of the permutation. */
- uintmax_t lg_n = floor_lg (n) + 1;
+ uintmax_t lg_n = stdc_bit_width (n) + 1;
/* Upper bound on number of bits needed to generated the first H elements. */
uintmax_t ar = lg_n * h;
/* Include this file _after_ system headers if possible. */
/* sys/stat.h and minmax.h will already have been included by system.h. */
-#include "count-leading-zeros.h"
+#include <stdbit.h>
#include "stat-size.h"
power of two when the reported blocksize is not a power of two. */
if (S_ISREG (st->st_mode) && blocksize & (blocksize - 1))
{
- int leading_zeros = count_leading_zeros_ll (blocksize);
+ int leading_zeros = stdc_leading_zeros_ull (blocksize);
if (IDX_MAX < ULLONG_MAX || leading_zeros)
{
unsigned long long power = 1ull << (ULLONG_WIDTH - leading_zeros);