lib/stdbit.c was present only to define private helper functions. Move them into lib/stdc_leading_zeros.c and lib/stdc_trailing_zeros.c, depending on what they help. The latter now might use the former, since the _gl_stdbit_ctz family calls the _gl_stdbit_clz family when !defined _GL_STDBIT_HAS_BUILTIN_CTZ && !defined _MSC_VER, so stdc_trailing_zeros now depends on stdc_leading_zeros. * lib/stdbit.c: Remove file. * lib/stdbit.in.h (_GL_STDBIT_INLINE): Remove. All uses replaced by _GL_STDC_LEADING_ZEROS_INLINE or _GL_STDC_TRAILING_ZEROS_INLINE. * modules/stdbit-h (Files, lib_SOURCES): Remove lib/stdbit.c. * modules/stdc_trailing_zeros (Depends-on): Add stdc_leading_zeros. --- ChangeLog | 15 ++++++++++++++ lib/stdbit.c | 23 ---------------------- lib/stdbit.in.h | 39 +++++++++++++++++-------------------- modules/stdbit-h | 2 -- modules/stdc_trailing_zeros | 1 + 5 files changed, 34 insertions(+), 46 deletions(-) delete mode 100644 lib/stdbit.c
diff --git a/ChangeLog b/ChangeLog index 1c6ecd528c..b0bfaee0c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2026-03-15 Paul Eggert <[email protected]> + stdbit-h: remove stdbit.c + lib/stdbit.c was present only to define private helper functions. + Move them into lib/stdc_leading_zeros.c and + lib/stdc_trailing_zeros.c, depending on what they help. + The latter now might use the former, since the + _gl_stdbit_ctz family calls the _gl_stdbit_clz family + when !defined _GL_STDBIT_HAS_BUILTIN_CTZ && !defined _MSC_VER, + so stdc_trailing_zeros now depends on stdc_leading_zeros. + * lib/stdbit.c: Remove file. + * lib/stdbit.in.h (_GL_STDBIT_INLINE): Remove. + All uses replaced by _GL_STDC_LEADING_ZEROS_INLINE + or _GL_STDC_TRAILING_ZEROS_INLINE. + * modules/stdbit-h (Files, lib_SOURCES): Remove lib/stdbit.c. + * modules/stdc_trailing_zeros (Depends-on): Add stdc_leading_zeros. + stdbit-h: test without <stdint.h> Improve the <stdbit.h> tests so that they check that <stdbit.h> works even if <stdint.h> is not included. diff --git a/lib/stdbit.c b/lib/stdbit.c deleted file mode 100644 index 1b8b616966..0000000000 --- a/lib/stdbit.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Support C23 bit and byte utilities on non-C23 platforms. - - Copyright 2024-2026 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>. */ - -/* Written by Paul Eggert. */ - -#define _GL_STDBIT_INLINE _GL_EXTERN_INLINE -#include <config.h> - -#include <stdbit.h> diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index ddc7e7e4f4..981c470564 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -104,9 +104,6 @@ _GL_INLINE_HEADER_BEGIN -#ifndef _GL_STDBIT_INLINE -# define _GL_STDBIT_INLINE _GL_INLINE -#endif #ifndef _GL_STDC_LEADING_ZEROS_INLINE # define _GL_STDC_LEADING_ZEROS_INLINE _GL_INLINE #endif @@ -238,17 +235,17 @@ extern "C" { /* Count leading 0 bits of N, even if N is 0. */ #ifdef _GL_STDBIT_HAS_BUILTIN_CLZ -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clz (unsigned int n) { return n ? __builtin_clz (n) : 8 * sizeof n; } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzl (unsigned long int n) { return n ? __builtin_clzl (n) : 8 * sizeof n; } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzll (unsigned long long int n) { return n ? __builtin_clzll (n) : 8 * sizeof n; @@ -264,18 +261,18 @@ extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanReverse64) # endif -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzl (unsigned long int n) { unsigned long int r; return 8 * sizeof n - (_BitScanReverse (&r, n) ? r + 1 : 0); } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clz (unsigned int n) { return _gl_stdbit_clzl (n) - 8 * (sizeof 0ul - sizeof n); } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzll (unsigned long long int n) { # ifdef _M_X64 @@ -289,7 +286,7 @@ _gl_stdbit_clzll (unsigned long long int n) #else /* !_MSC_VER */ -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzll (unsigned long long int n) { int r = 0; @@ -303,12 +300,12 @@ _gl_stdbit_clzll (unsigned long long int n) int a2 = (0x000000000000000f < n) << 2; n >>= a2; r += a2; return (8 * sizeof n - (1 << 2) - r) + ((0x11112234ull >> (n << 2)) & 0xf); } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clz (unsigned int n) { return _gl_stdbit_clzll (n) - 8 * (sizeof 0ull - sizeof 0u); } -_GL_STDBIT_INLINE int +_GL_STDC_LEADING_ZEROS_INLINE int _gl_stdbit_clzl (unsigned long int n) { return _gl_stdbit_clzll (n) - 8 * (sizeof 0ull - sizeof 0ul); @@ -317,17 +314,17 @@ _gl_stdbit_clzl (unsigned long int n) /* Count trailing 0 bits of N, even if N is 0. */ #ifdef _GL_STDBIT_HAS_BUILTIN_CTZ -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctz (unsigned int n) { return n ? __builtin_ctz (n) : 8 * sizeof n; } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzl (unsigned long int n) { return n ? __builtin_ctzl (n) : 8 * sizeof n; } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzll (unsigned long long int n) { return n ? __builtin_ctzll (n) : 8 * sizeof n; @@ -343,18 +340,18 @@ extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanForward64) # endif -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzl (unsigned long int n) { unsigned long int r; return _BitScanForward (&r, n) ? r : 8 * sizeof n; } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctz (unsigned int n) { return _gl_stdbit_ctzl (n | (1ul << (8 * sizeof n - 1) << 1)); } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzll (unsigned long long int n) { # ifdef _M_X64 @@ -368,17 +365,17 @@ _gl_stdbit_ctzll (unsigned long long int n) #else /* !_MSC_VER */ -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctz (unsigned int n) { return 8 * sizeof n - (n ? _gl_stdbit_clz (n & -n) + 1 : 0); } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzl (unsigned long int n) { return 8 * sizeof n - (n ? _gl_stdbit_clzl (n & -n) + 1 : 0); } -_GL_STDBIT_INLINE int +_GL_STDC_TRAILING_ZEROS_INLINE int _gl_stdbit_ctzll (unsigned long long int n) { return 8 * sizeof n - (n ? _gl_stdbit_clzll (n & -n) + 1 : 0); diff --git a/modules/stdbit-h b/modules/stdbit-h index 5bba8b8bad..26d0b26e95 100644 --- a/modules/stdbit-h +++ b/modules/stdbit-h @@ -3,7 +3,6 @@ A <stdbit.h> for platforms that lack it. Files: lib/stdbit.in.h -lib/stdbit.c m4/stdbit_h.m4 Depends-on: @@ -56,7 +55,6 @@ stdbit.h: stdbit.in.h $(top_builddir)/config.status -e 's/@''GNULIB_STDC_STORE8''@/$(GNULIB_STDC_STORE8)/g' \ $(srcdir)/stdbit.in.h > $@-t $(AM_V_at)mv $@-t $@ -lib_SOURCES += stdbit.c else stdbit.h: $(top_builddir)/config.status rm -f $@ diff --git a/modules/stdc_trailing_zeros b/modules/stdc_trailing_zeros index ea4a26eb06..1a067ec662 100644 --- a/modules/stdc_trailing_zeros +++ b/modules/stdc_trailing_zeros @@ -7,6 +7,7 @@ lib/stdc_trailing_zeros.c Depends-on: stdbit-h +stdc_leading_zeros configure.ac: AC_REQUIRE([gl_STDBIT_H]) -- 2.51.0
