mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 11:16:16 +02:00
maint: prefer stdbit.h to count-leading-zeros.h
<stdbit.h> is in C23 and should be more portable in the long run, now that Gnulib supports it. * bootstrap.conf (gnulib_modules): Remove count-leading-zeros. Add stdc_leading_zeros. * gl/lib/randperm.c, src/ioblksize.h: Include stdbit.h instead of count-leading-zeros.h. * gl/lib/randperm.c (floor_lg): Remove; no longer needed. (randperm_bound): Use stdc_bit_width instead of floor_lg; * gl/modules/randperm (Depends-on): Remove count-leading-zeros. Add stdc_bit_width. * src/ioblksize.h (io_blksize): Use stdc_leading_zeros_ull instead of count_leading_zeros_ll.
This commit is contained in:
@@ -64,7 +64,6 @@ gnulib_modules="
|
|||||||
config-h
|
config-h
|
||||||
configmake
|
configmake
|
||||||
copy-file-range
|
copy-file-range
|
||||||
count-leading-zeros
|
|
||||||
crypto/md5
|
crypto/md5
|
||||||
crypto/sha1
|
crypto/sha1
|
||||||
crypto/sha256
|
crypto/sha256
|
||||||
@@ -247,6 +246,7 @@ gnulib_modules="
|
|||||||
stat-size
|
stat-size
|
||||||
stat-time
|
stat-time
|
||||||
stdbool
|
stdbool
|
||||||
|
stdc_leading_zeros
|
||||||
stdckdint
|
stdckdint
|
||||||
stdlib-safer
|
stdlib-safer
|
||||||
stpcpy
|
stpcpy
|
||||||
|
|||||||
@@ -22,28 +22,14 @@
|
|||||||
#include "randperm.h"
|
#include "randperm.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdbit.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "attribute.h"
|
#include "attribute.h"
|
||||||
#include "count-leading-zeros.h"
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "xalloc.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
|
/* Return an upper bound on the number of random bytes needed to
|
||||||
generate the first H elements of a random permutation of N
|
generate the first H elements of a random permutation of N
|
||||||
elements. H must not exceed N. */
|
elements. H must not exceed N. */
|
||||||
@@ -53,7 +39,7 @@ randperm_bound (size_t h, size_t n)
|
|||||||
{
|
{
|
||||||
/* Upper bound on number of bits needed to generate the first number
|
/* Upper bound on number of bits needed to generate the first number
|
||||||
of the permutation. */
|
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. */
|
/* Upper bound on number of bits needed to generated the first H elements. */
|
||||||
uintmax_t ar = lg_n * h;
|
uintmax_t ar = lg_n * h;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ lib/randperm.h
|
|||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
assert-h
|
assert-h
|
||||||
count-leading-zeros
|
|
||||||
randint
|
randint
|
||||||
|
stdc_bit_width
|
||||||
stdint
|
stdint
|
||||||
xalloc
|
xalloc
|
||||||
hash
|
hash
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
/* Include this file _after_ system headers if possible. */
|
/* Include this file _after_ system headers if possible. */
|
||||||
|
|
||||||
/* sys/stat.h and minmax.h will already have been included by system.h. */
|
/* 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"
|
#include "stat-size.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ io_blksize (struct stat const *st)
|
|||||||
power of two when the reported blocksize is not a power of two. */
|
power of two when the reported blocksize is not a power of two. */
|
||||||
if (S_ISREG (st->st_mode) && blocksize & (blocksize - 1))
|
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)
|
if (IDX_MAX < ULLONG_MAX || leading_zeros)
|
||||||
{
|
{
|
||||||
unsigned long long power = 1ull << (ULLONG_WIDTH - leading_zeros);
|
unsigned long long power = 1ull << (ULLONG_WIDTH - leading_zeros);
|
||||||
|
|||||||
Reference in New Issue
Block a user