mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-04-28 06:33:36 +00:00
byteswap: Rely on <stdbit.h>.
* lib/byteswap.in.h: Include <stdbit.h>. (_GL_BYTESWAP_HAS_BUILTIN_BSWAP16, _GL_BYTESWAP_HAS_BUILTIN_BSWAP32, _GL_BYTESWAP_HAS_BUILTIN_BSWAP64): Remove macros. (bswap_16): Just call stdc_memreverse8u16. (bswap_32): Just call stdc_memreverse8u32. (bswap_64): Just call stdc_memreverse8u64. * modules/byteswap (Depends-on): Add stdc_memreverse8u. Remove bool.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
||||
2026-03-15 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
byteswap: Rely on <stdbit.h>.
|
||||
* lib/byteswap.in.h: Include <stdbit.h>.
|
||||
(_GL_BYTESWAP_HAS_BUILTIN_BSWAP16, _GL_BYTESWAP_HAS_BUILTIN_BSWAP32,
|
||||
_GL_BYTESWAP_HAS_BUILTIN_BSWAP64): Remove macros.
|
||||
(bswap_16): Just call stdc_memreverse8u16.
|
||||
(bswap_32): Just call stdc_memreverse8u32.
|
||||
(bswap_64): Just call stdc_memreverse8u64.
|
||||
* modules/byteswap (Depends-on): Add stdc_memreverse8u. Remove bool.
|
||||
|
||||
2026-03-15 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
stdc_load8_aligned, stdc_store8_aligned: Don't use <byteswap.h>.
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
# define _GL_BYTESWAP_INLINE _GL_INLINE
|
||||
#endif
|
||||
|
||||
#include <stdbit.h>
|
||||
#include <stdint.h>
|
||||
|
||||
_GL_INLINE_HEADER_BEGIN
|
||||
@@ -37,38 +38,12 @@ _GL_INLINE_HEADER_BEGIN
|
||||
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. */
|
||||
_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
|
||||
return stdc_memreverse8u16 (x);
|
||||
}
|
||||
|
||||
/* Given an unsigned 32-bit argument X, return the value corresponding to
|
||||
@@ -76,15 +51,7 @@ bswap_16 (uint_least16_t x)
|
||||
_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
|
||||
return stdc_memreverse8u32 (x);
|
||||
}
|
||||
|
||||
#ifdef UINT_LEAST64_MAX
|
||||
@@ -93,19 +60,7 @@ bswap_32 (uint_least32_t x)
|
||||
_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
|
||||
return stdc_memreverse8u64 (x);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ m4/byteswap.m4
|
||||
Depends-on:
|
||||
gen-header
|
||||
extern-inline [$GL_GENERATE_BYTESWAP_H]
|
||||
bool [$GL_GENERATE_BYTESWAP_H]
|
||||
stdint-h [$GL_GENERATE_BYTESWAP_H]
|
||||
stdc_memreverse8u [$GL_GENERATE_BYTESWAP_H]
|
||||
|
||||
configure.ac:
|
||||
gl_BYTESWAP
|
||||
|
||||
Reference in New Issue
Block a user