From 097a465ad24ec44bfc29c5111580f4ee51cf15d8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 18 May 2024 09:33:03 -0700 Subject: [PATCH] Update from Gnulib by running admin/merge-gnulib (cherry picked from commit 08550d058f028e0819ba6a72e9a53c0bc789257e) --- lib/byteswap.c | 21 ++++++++ lib/byteswap.in.h | 101 +++++++++++++++++++++++++++++++------ lib/count-leading-zeros.h | 2 + lib/count-one-bits.h | 3 ++ lib/count-trailing-zeros.h | 2 + lib/gnulib.mk.in | 5 ++ lib/stdlib.in.h | 17 +++++++ lib/strftime.c | 10 ++-- lib/sys_select.in.h | 2 + lib/unistd.in.h | 12 +---- m4/byteswap.m4 | 27 ++++++++-- m4/gnulib-comp.m4 | 1 + m4/stdalign.m4 | 2 +- m4/stdlib_h.m4 | 4 +- 14 files changed, 173 insertions(+), 36 deletions(-) create mode 100644 lib/byteswap.c diff --git a/lib/byteswap.c b/lib/byteswap.c new file mode 100644 index 00000000000..6e3dad74eaa --- /dev/null +++ b/lib/byteswap.c @@ -0,0 +1,21 @@ +/* Inline functions for . + + Copyright 2024 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 . */ + +#include + +#define _GL_BYTESWAP_INLINE _GL_EXTERN_INLINE +#include diff --git a/lib/byteswap.in.h b/lib/byteswap.in.h index 8e49efad05a..4be335d9158 100644 --- a/lib/byteswap.in.h +++ b/lib/byteswap.in.h @@ -16,29 +16,100 @@ along with this program. If not, see . */ #ifndef _GL_BYTESWAP_H -#define _GL_BYTESWAP_H +#define _GL_BYTESWAP_H 1 + +/* This file uses _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + +#include + +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_BYTESWAP_INLINE +# define _GL_BYTESWAP_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP16 true +#elif defined __has_builtin +# if __has_builtin (__builtin_bswap16) +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP16 true +# endif +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP32 true +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP64 true +#elif defined __has_builtin +# if __has_builtin (__builtin_bswap32) +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP32 true +# endif +# if __has_builtin (__builtin_bswap64) +# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP64 true +# endif +#endif /* Given an unsigned 16-bit argument X, return the value corresponding to X with reversed byte order. */ -#define bswap_16(x) ((((x) & 0x00FF) << 8) | \ - (((x) & 0xFF00) >> 8)) +_GL_BYTESWAP_INLINE uint_least16_t +bswap_16 (uint_least16_t x) +{ +#ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP16 + return __builtin_bswap16 (x); +#else + uint_fast16_t mask = 0xff; + return ( (x & mask << 8 * 1) >> 8 * 1 + | (x & mask << 8 * 0) << 8 * 1); +#endif +} /* Given an unsigned 32-bit argument X, return the value corresponding to X with reversed byte order. */ -#define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ - (((x) & 0x0000FF00) << 8) | \ - (((x) & 0x00FF0000) >> 8) | \ - (((x) & 0xFF000000) >> 24)) +_GL_BYTESWAP_INLINE uint_least32_t +bswap_32 (uint_least32_t x) +{ +#ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP32 + return __builtin_bswap32 (x); +#else + uint_fast32_t mask = 0xff; + return ( (x & mask << 8 * 3) >> 8 * 3 + | (x & mask << 8 * 2) >> 8 * 1 + | (x & mask << 8 * 1) << 8 * 1 + | (x & mask << 8 * 0) << 8 * 3); +#endif +} +#ifdef UINT_LEAST64_MAX /* Given an unsigned 64-bit argument X, return the value corresponding to X with reversed byte order. */ -#define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ - (((x) & 0x000000000000FF00ULL) << 40) | \ - (((x) & 0x0000000000FF0000ULL) << 24) | \ - (((x) & 0x00000000FF000000ULL) << 8) | \ - (((x) & 0x000000FF00000000ULL) >> 8) | \ - (((x) & 0x0000FF0000000000ULL) >> 24) | \ - (((x) & 0x00FF000000000000ULL) >> 40) | \ - (((x) & 0xFF00000000000000ULL) >> 56)) +_GL_BYTESWAP_INLINE uint_least64_t +bswap_64 (uint_least64_t x) +{ +# ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP64 + return __builtin_bswap64 (x); +# else + uint_fast64_t mask = 0xff; + return ( (x & mask << 8 * 7) >> 8 * 7 + | (x & mask << 8 * 6) >> 8 * 5 + | (x & mask << 8 * 5) >> 8 * 3 + | (x & mask << 8 * 4) >> 8 * 1 + | (x & mask << 8 * 3) << 8 * 1 + | (x & mask << 8 * 2) << 8 * 3 + | (x & mask << 8 * 1) << 8 * 5 + | (x & mask << 8 * 0) << 8 * 7); +# endif +} +#endif + +#ifdef __cplusplus +} +#endif + +_GL_INLINE_HEADER_END #endif /* _GL_BYTESWAP_H */ diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 545749d6d27..a4b68c21064 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -45,8 +45,10 @@ extern "C" { # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER +extern unsigned char _BitScanReverse (unsigned long *, unsigned long); # pragma intrinsic (_BitScanReverse) # if defined _M_X64 +extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanReverse64) # endif # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index 8d67f8718a4..24bf8cc2327 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -85,9 +85,12 @@ count_one_bits_32 (unsigned int x) # include # else /* Don't pollute the namespace with too many MSVC intrinsics. */ +extern void __cpuid (int[4], int); # pragma intrinsic (__cpuid) +extern unsigned int __popcnt (unsigned int); # pragma intrinsic (__popcnt) # if defined _M_X64 +extern unsigned long long __popcnt64 (unsigned long long); # pragma intrinsic (__popcnt64) # endif # endif diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index ed1e0131147..82de8731ec1 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -45,8 +45,10 @@ extern "C" { # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER +extern unsigned char _BitScanForward (unsigned long *, unsigned long); # pragma intrinsic (_BitScanForward) # if defined _M_X64 +extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long); # pragma intrinsic (_BitScanForward64) # endif # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index a5c009cfb85..d03e193b63c 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -361,6 +361,7 @@ GL_GENERATE_MINI_GMP_H_CONDITION = @GL_GENERATE_MINI_GMP_H_CONDITION@ GL_GENERATE_STDCKDINT_H_CONDITION = @GL_GENERATE_STDCKDINT_H_CONDITION@ GL_GENERATE_STDDEF_H_CONDITION = @GL_GENERATE_STDDEF_H_CONDITION@ GL_GENERATE_STDINT_H_CONDITION = @GL_GENERATE_STDINT_H_CONDITION@ +GL_GNULIB_ABORT_DEBUG = @GL_GNULIB_ABORT_DEBUG@ GL_GNULIB_ACCESS = @GL_GNULIB_ACCESS@ GL_GNULIB_ALIGNED_ALLOC = @GL_GNULIB_ALIGNED_ALLOC@ GL_GNULIB_ALPHASORT = @GL_GNULIB_ALPHASORT@ @@ -1107,6 +1108,7 @@ QCOPY_ACL_LIB = @QCOPY_ACL_LIB@ RALLOC_OBJ = @RALLOC_OBJ@ RANLIB = @RANLIB@ READELF = @READELF@ +REPLACE_ABORT = @REPLACE_ABORT@ REPLACE_ACCESS = @REPLACE_ACCESS@ REPLACE_ALIGNED_ALLOC = @REPLACE_ALIGNED_ALLOC@ REPLACE_CALLOC_FOR_CALLOC_GNU = @REPLACE_CALLOC_FOR_CALLOC_GNU@ @@ -1639,6 +1641,7 @@ ifneq (,$(GL_GENERATE_BYTESWAP_H_CONDITION)) byteswap.h: byteswap.in.h $(top_builddir)/config.status $(gl_V_at)$(SED_HEADER_TO_AT_t) $(srcdir)/byteswap.in.h $(AM_V_at)mv $@-t $@ +libgnu_a_SOURCES += byteswap.c else byteswap.h: $(top_builddir)/config.status rm -f $@ @@ -3322,6 +3325,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ -e 's/@''GNULIB__EXIT''@/$(GL_GNULIB__EXIT)/g' \ + -e 's/@''GNULIB_ABORT_DEBUG''@/$(GL_GNULIB_ABORT_DEBUG)/g' \ -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GL_GNULIB_ALIGNED_ALLOC)/g' \ -e 's/@''GNULIB_ATOLL''@/$(GL_GNULIB_ATOLL)/g' \ -e 's/@''GNULIB_CALLOC_GNU''@/$(GL_GNULIB_CALLOC_GNU)/g' \ @@ -3424,6 +3428,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ < $@-t1 > $@-t2 $(AM_V_at)sed \ -e 's|@''REPLACE__EXIT''@|$(REPLACE__EXIT)|g' \ + -e 's|@''REPLACE_ABORT''@|$(REPLACE_ABORT)|g' \ -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \ -e 's|@''REPLACE_CALLOC_FOR_CALLOC_GNU''@|$(REPLACE_CALLOC_FOR_CALLOC_GNU)|g' \ -e 's|@''REPLACE_CALLOC_FOR_CALLOC_POSIX''@|$(REPLACE_CALLOC_FOR_CALLOC_POSIX)|g' \ diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index e74e7c18d19..1888d3ee314 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -216,6 +216,23 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - " #endif +#if @GNULIB_ABORT_DEBUG@ +# if @REPLACE_ABORT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef abort +# define abort rpl_abort +# endif +_GL_FUNCDECL_RPL (abort, _Noreturn void, (void)); +_GL_CXXALIAS_RPL (abort, void, (void)); +# else +_GL_CXXALIAS_SYS (abort, void, (void)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (abort); +# endif +#endif + + #if @GNULIB_FREE_POSIX@ # if @REPLACE_FREE@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/strftime.c b/lib/strftime.c index 9b205e48023..834f3a79f46 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -143,11 +143,11 @@ extern char *tzname[]; enum pad_style { - ZERO_PAD, /* (default) Pad with 0 unless format says otherwise. */ - ALWAYS_ZERO_PAD, /* '0' Always pad with 0. */ - SIGN_PAD, /* '+' Always output a sign. */ - SPACE_PAD, /* '_' Pad with space. */ - NO_PAD /* '-' Do not pad. */ + ZERO_PAD, /* (default) Pad with 0 unless format says otherwise. */ + ALWAYS_ZERO_PAD, /* '0' Always pad with 0. */ + SIGN_PAD, /* '+' Always output a sign. */ + SPACE_PAD, /* '_' Pad with space. */ + NO_PAD /* '-' Do not pad. */ }; #define TM_YEAR_BASE 1900 diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index de29c77949a..ddf25d1de4c 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -328,7 +328,9 @@ _GL_CXXALIAS_SYS (select, int, (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, timeval *restrict)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (select); +# endif #elif @HAVE_WINSOCK2_H@ # undef select # define select select_used_without_requesting_gnulib_module_select diff --git a/lib/unistd.in.h b/lib/unistd.in.h index fa99d7472f4..7dbed38969b 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1934,11 +1934,7 @@ _GL_CXXALIASWARN (read); # undef read # define read _read # endif -# ifdef __MINGW32__ -_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count)); -# else -_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count)); -# endif +_GL_CXXALIAS_MDA_CAST (read, ssize_t, (int fd, void *buf, unsigned int count)); # else _GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count)); # endif @@ -2402,11 +2398,7 @@ _GL_CXXALIASWARN (write); # undef write # define write _write # endif -# ifdef __MINGW32__ -_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count)); -# else -_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count)); -# endif +_GL_CXXALIAS_MDA_CAST (write, ssize_t, (int fd, const void *buf, unsigned int count)); # else _GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count)); # endif diff --git a/m4/byteswap.m4 b/m4/byteswap.m4 index 0c76fe9312d..3f5ef45cfe6 100644 --- a/m4/byteswap.m4 +++ b/m4/byteswap.m4 @@ -1,5 +1,5 @@ # byteswap.m4 -# serial 5 +# serial 6 dnl Copyright (C) 2005, 2007, 2009-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,9 +10,28 @@ dnl Written by Oskar Liljeblad. AC_DEFUN([gl_BYTESWAP], [ dnl Prerequisites of lib/byteswap.in.h. - AC_CHECK_HEADERS([byteswap.h], [ + AC_CHECK_HEADERS_ONCE([byteswap.h]) + if test $ac_cv_header_byteswap_h = yes; then + AC_CACHE_CHECK([for working bswap_16, bswap_32, bswap_64], + [gl_cv_header_working_byteswap_h], + [gl_cv_header_working_byteswap_h=no + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[int value_16 = bswap_16 (0.0); + int value_32 = bswap_32 (0.0); + int value_64 = bswap_64 (0.0); + return !(value_16 + value_32 + value_64); + ]]) + ], + [gl_cv_header_working_byteswap_h=yes], + [gl_cv_header_working_byteswap_h=no]) + ]) + fi + if test $gl_cv_header_working_byteswap_h = yes; then GL_GENERATE_BYTESWAP_H=false - ], [ + else GL_GENERATE_BYTESWAP_H=true - ]) + fi ]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 37f180a8955..61040987b57 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -1259,6 +1259,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/boot-time-aux.h lib/boot-time.c lib/boot-time.h + lib/byteswap.c lib/byteswap.in.h lib/c++defs.h lib/c-ctype.c diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index 2b4762f3200..1c29d1e4fb9 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -81,7 +81,7 @@ AC_DEFUN([gl_ALIGNASOF], References: ISO C23 (latest free draft - ) + ) sections 6.5.3.4, 6.7.5, 7.15. C++11 (latest free draft ) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index a4662f29955..bb5a6460414 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,5 +1,5 @@ # stdlib_h.m4 -# serial 77 +# serial 78 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -110,6 +110,7 @@ AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS], [ m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS], [ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB__EXIT]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ABORT_DEBUG]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ALIGNED_ALLOC]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATOLL]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CALLOC_GNU]) @@ -218,6 +219,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV]) REPLACE__EXIT=0; AC_SUBST([REPLACE__EXIT]) + REPLACE_ABORT=0; AC_SUBST([REPLACE_ABORT]) REPLACE_ALIGNED_ALLOC=0; AC_SUBST([REPLACE_ALIGNED_ALLOC]) REPLACE_CALLOC_FOR_CALLOC_GNU=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_GNU]) REPLACE_CALLOC_FOR_CALLOC_POSIX=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_POSIX]) -- 2.39.5