Paul Eggert wrote:
> in the future we may 
> run into platforms that support C2y stdbit.h but lack byteswap.h.

And byteswap.h nowadays assumes that the arch-specific logic is contained
in the compiler (see glibc commit 0d40d0ecba3b1e5b8c3b8da01c708fea3948e193
[1]).

And with patch 0002-stdbit-h-avoid-byteswap.h-namespace-pollution.patch,
you already copied half of the logic from byteswap.in.h to stdbit.in.h.

So, we can just copy the other half of the logic from byteswap.in.h
to stdbit.in.h as well.

You might think that by doing this, Gnulib misses to use the bswap* function
definitions from the system's libc? Actually no, because
  - glibc, musl libc, FreeBSD 14, Cygwin provide these functions inline,
    not in libc,
  - NetBSD has __bswap16, __bswap32, bswap64 in libc, but does not have
    <byteswap.h>.

[1] 
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0d40d0ecba3b1e5b8c3b8da01c708fea3948e193


2026-03-15  Bruno Haible  <[email protected]>

        stdc_memreverse8u: Add tests.
        * tests/test-stdc_memreverse8u.c: New file, based on
        tests/test-byteswap.c.
        * modules/stdc_memreverse8u-tests: New file.

        stdc_memreverse8u: New module.
        * lib/stdbit.in.h (_GL_STDC_MEMREVERSE8U_INLINE): New macro.
        (stdc_memreverse8u8, stdc_memreverse8u16, stdc_memreverse8u32,
        stdc_memreverse8u64): New functions, based on lib/byteswap.in.h.
        * lib/stdc_memreverse8u.c: New file.
        * m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
        GNULIB_STDC_MEMREVERSE8U.
        * modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_MEMREVERSE8U.
        * modules/stdc_memreverse8u: New file.
        * doc/posix-functions/stdc_memreverse8u8.texi: Mention the new module.
        * doc/posix-functions/stdc_memreverse8u16.texi: Likewise.
        * doc/posix-functions/stdc_memreverse8u32.texi: Likewise.
        * doc/posix-functions/stdc_memreverse8u64.texi: Likewise.

From 81546b416c065308fbfdc61947efacc393d4f7f0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 15 Mar 2026 13:01:49 +0100
Subject: [PATCH 1/2] stdc_memreverse8u: New module.

* lib/stdbit.in.h (_GL_STDC_MEMREVERSE8U_INLINE): New macro.
(stdc_memreverse8u8, stdc_memreverse8u16, stdc_memreverse8u32,
stdc_memreverse8u64): New functions, based on lib/byteswap.in.h.
* lib/stdc_memreverse8u.c: New file.
* m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
GNULIB_STDC_MEMREVERSE8U.
* modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_MEMREVERSE8U.
* modules/stdc_memreverse8u: New file.
* doc/posix-functions/stdc_memreverse8u8.texi: Mention the new module.
* doc/posix-functions/stdc_memreverse8u16.texi: Likewise.
* doc/posix-functions/stdc_memreverse8u32.texi: Likewise.
* doc/posix-functions/stdc_memreverse8u64.texi: Likewise.
---
 ChangeLog                                    | 16 ++++
 doc/posix-functions/stdc_memreverse8u16.texi |  9 ++-
 doc/posix-functions/stdc_memreverse8u32.texi |  9 ++-
 doc/posix-functions/stdc_memreverse8u64.texi |  9 ++-
 doc/posix-functions/stdc_memreverse8u8.texi  |  9 ++-
 lib/stdbit.in.h                              | 79 ++++++++++++++++++--
 lib/stdc_memreverse8u.c                      | 19 +++++
 m4/stdbit_h.m4                               |  3 +-
 modules/stdbit-h                             |  1 +
 modules/stdc_memreverse8u                    | 27 +++++++
 10 files changed, 159 insertions(+), 22 deletions(-)
 create mode 100644 lib/stdc_memreverse8u.c
 create mode 100644 modules/stdc_memreverse8u

diff --git a/ChangeLog b/ChangeLog
index e14234deef..c365890c4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2026-03-15  Bruno Haible  <[email protected]>
+
+	stdc_memreverse8u: New module.
+	* lib/stdbit.in.h (_GL_STDC_MEMREVERSE8U_INLINE): New macro.
+	(stdc_memreverse8u8, stdc_memreverse8u16, stdc_memreverse8u32,
+	stdc_memreverse8u64): New functions, based on lib/byteswap.in.h.
+	* lib/stdc_memreverse8u.c: New file.
+	* m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
+	GNULIB_STDC_MEMREVERSE8U.
+	* modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_MEMREVERSE8U.
+	* modules/stdc_memreverse8u: New file.
+	* doc/posix-functions/stdc_memreverse8u8.texi: Mention the new module.
+	* doc/posix-functions/stdc_memreverse8u16.texi: Likewise.
+	* doc/posix-functions/stdc_memreverse8u32.texi: Likewise.
+	* doc/posix-functions/stdc_memreverse8u64.texi: Likewise.
+
 2026-03-15  Bruno Haible  <[email protected]>
 
 	hamt: Don't use deprecated module.
diff --git a/doc/posix-functions/stdc_memreverse8u16.texi b/doc/posix-functions/stdc_memreverse8u16.texi
index afb8ee7354..55971df23f 100644
--- a/doc/posix-functions/stdc_memreverse8u16.texi
+++ b/doc/posix-functions/stdc_memreverse8u16.texi
@@ -7,15 +7,16 @@
 @url{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3783.pdf})
 section 7.18.20.
 
-Gnulib module: ---
+Gnulib module: stdc_memreverse8u
+@mindex stdc_memreverse8u
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
diff --git a/doc/posix-functions/stdc_memreverse8u32.texi b/doc/posix-functions/stdc_memreverse8u32.texi
index eaebc8e8ad..9f3723c9f5 100644
--- a/doc/posix-functions/stdc_memreverse8u32.texi
+++ b/doc/posix-functions/stdc_memreverse8u32.texi
@@ -7,15 +7,16 @@
 @url{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3783.pdf})
 section 7.18.20.
 
-Gnulib module: ---
+Gnulib module: stdc_memreverse8u
+@mindex stdc_memreverse8u
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
diff --git a/doc/posix-functions/stdc_memreverse8u64.texi b/doc/posix-functions/stdc_memreverse8u64.texi
index b6121565fa..1a2b3a9b70 100644
--- a/doc/posix-functions/stdc_memreverse8u64.texi
+++ b/doc/posix-functions/stdc_memreverse8u64.texi
@@ -7,15 +7,16 @@
 @url{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3783.pdf})
 section 7.18.20.
 
-Gnulib module: ---
+Gnulib module: stdc_memreverse8u
+@mindex stdc_memreverse8u
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
diff --git a/doc/posix-functions/stdc_memreverse8u8.texi b/doc/posix-functions/stdc_memreverse8u8.texi
index 4e6f5eee0b..9f3e28bc34 100644
--- a/doc/posix-functions/stdc_memreverse8u8.texi
+++ b/doc/posix-functions/stdc_memreverse8u8.texi
@@ -7,15 +7,16 @@
 @url{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3783.pdf})
 section 7.18.20.
 
-Gnulib module: ---
+Gnulib module: stdc_memreverse8u
+@mindex stdc_memreverse8u
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-glibc 2.43, macOS 26, FreeBSD 15.0, NetBSD 10.0, OpenBSD 7.8, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
 @end itemize
diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
index 562796b8e4..3443ed4715 100644
--- a/lib/stdbit.in.h
+++ b/lib/stdbit.in.h
@@ -37,17 +37,20 @@
  #error "Please include config.h first."
 #endif
 
-#if @GNULIB_STDC_LOAD8_ALIGNED@ || @GNULIB_STDC_LOAD8@ || @GNULIB_STDC_STORE8_ALIGNED@ || @GNULIB_STDC_STORE8@
+#if @GNULIB_STDC_MEMREVERSE8U@ || @GNULIB_STDC_LOAD8_ALIGNED@ || @GNULIB_STDC_LOAD8@ || @GNULIB_STDC_STORE8_ALIGNED@ || @GNULIB_STDC_STORE8@
 
-/* Get int_least8_t, int_least16_t, int_least32_t, int_least64_t,
-   uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t.  */
+/* Get uint8_t, uint16_t, uint32_t, uint64_t,
+   int_least8_t, int_least16_t, int_least32_t, int_least64_t,
+   uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t,
+   uint_fast16_t, uint_fast32_t, uint_fast64_t.  */
 # include <stdint.h>
 
 #endif
 
-#if @GNULIB_STDC_LOAD8_ALIGNED@ || @GNULIB_STDC_STORE8_ALIGNED@
+#if @GNULIB_STDC_MEMREVERSE8U@ || @GNULIB_STDC_LOAD8_ALIGNED@ || @GNULIB_STDC_STORE8_ALIGNED@
 
-/* Get bswap_16, bswap_32, bswap_64, but keep namespace clean on GNU.  */
+/* Determine whether the compiler supports the __builtin_bswap{16,32,64}
+   builtins.  */
 # if defined __GNUC__ && 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
 #  define _GL_STDBIT_HAS_BUILTIN_BSWAP16 1
 # elif defined __has_builtin
@@ -66,6 +69,12 @@
 #   define _GL_STDBIT_HAS_BUILTIN_BSWAP64 1
 #  endif
 # endif
+
+#endif
+
+#if @GNULIB_STDC_LOAD8_ALIGNED@ || @GNULIB_STDC_STORE8_ALIGNED@
+
+/* Get bswap_16, bswap_32, bswap_64, but keep namespace clean on GNU.  */
 # if ! (defined _GL_STDBIT_HAS_BUILTIN_BSWAP16 \
         && defined _GL_STDBIT_HAS_BUILTIN_BSWAP32 \
         && defined _GL_STDBIT_HAS_BUILTIN_BSWAP64)
@@ -147,6 +156,9 @@ _GL_INLINE_HEADER_BEGIN
 #ifndef _GL_STDC_BIT_CEIL_INLINE
 # define _GL_STDC_BIT_CEIL_INLINE _GL_INLINE
 #endif
+#ifndef _GL_STDC_MEMREVERSE8U_INLINE
+# define _GL_STDC_MEMREVERSE8U_INLINE _GL_INLINE
+#endif
 #ifndef _GL_STDC_LOAD8_ALIGNED_INLINE
 # define _GL_STDC_LOAD8_ALIGNED_INLINE _GL_INLINE
 #endif
@@ -1161,6 +1173,63 @@ stdc_bit_ceil_ull (unsigned long long int n)
 #endif /* @HAVE_STDBIT_H@ */
 
 
+/* ISO C2y ?? 7.18.20 Exact-width 8-bit Memory Reversal  */
+
+#if @GNULIB_STDC_MEMREVERSE8U@
+
+_GL_STDC_MEMREVERSE8U_INLINE uint8_t
+stdc_memreverse8u8 (uint8_t value)
+{
+  return value;
+}
+
+_GL_STDC_MEMREVERSE8U_INLINE uint16_t
+stdc_memreverse8u16 (uint16_t value)
+{
+# ifdef _GL_STDBIT_HAS_BUILTIN_BSWAP16
+  return __builtin_bswap16 (value);
+# else
+  uint_fast16_t const mask = 0xFFU;
+  return (  (value & (mask << (8 * 1))) >> (8 * 1)
+          | (value & (mask << (8 * 0))) << (8 * 1));
+# endif
+}
+
+_GL_STDC_MEMREVERSE8U_INLINE uint32_t
+stdc_memreverse8u32 (uint32_t value)
+{
+# ifdef _GL_STDBIT_HAS_BUILTIN_BSWAP32
+  return __builtin_bswap32 (value);
+# else
+  uint_fast32_t const mask = 0xFFU;
+  return (  (value & (mask << (8 * 3))) >> (8 * 3)
+          | (value & (mask << (8 * 2))) >> (8 * 1)
+          | (value & (mask << (8 * 1))) << (8 * 1)
+          | (value & (mask << (8 * 0))) << (8 * 3));
+# endif
+}
+
+_GL_STDC_MEMREVERSE8U_INLINE uint64_t
+stdc_memreverse8u64 (uint64_t value)
+{
+# ifdef _GL_STDBIT_HAS_BUILTIN_BSWAP64
+  return __builtin_bswap64 (value);
+# else
+  uint_fast64_t const mask = 0xFFU;
+  return (  (value & (mask << (8 * 7))) >> (8 * 7)
+          | (value & (mask << (8 * 6))) >> (8 * 5)
+          | (value & (mask << (8 * 5))) >> (8 * 3)
+          | (value & (mask << (8 * 4))) >> (8 * 1)
+          | (value & (mask << (8 * 3))) << (8 * 1)
+          | (value & (mask << (8 * 2))) << (8 * 3)
+          | (value & (mask << (8 * 1))) << (8 * 5)
+          | (value & (mask << (8 * 0))) << (8 * 7));
+# endif
+}
+
+#endif
+
+
 /* ISO C2y ?? 7.18.21 Endian-Aware 8-Bit Load  */
 
 /* On hosts where _GL_STDBIT_OPTIMIZE_VIA_MEMCPY might be useful,
diff --git a/lib/stdc_memreverse8u.c b/lib/stdc_memreverse8u.c
new file mode 100644
index 0000000000..ec83306dff
--- /dev/null
+++ b/lib/stdc_memreverse8u.c
@@ -0,0 +1,19 @@
+/* stdc_memreverse8u* functions.
+   Copyright (C) 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/>.  */
+
+#define _GL_STDC_MEMREVERSE8U_INLINE _GL_EXTERN_INLINE
+#include <config.h>
+#include <stdbit.h>
diff --git a/m4/stdbit_h.m4 b/m4/stdbit_h.m4
index 3f2804ac17..e279697e2c 100644
--- a/m4/stdbit_h.m4
+++ b/m4/stdbit_h.m4
@@ -1,5 +1,5 @@
 # stdbit_h.m4
-# serial 9
+# serial 10
 dnl Copyright 2024-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -66,6 +66,7 @@ AC_DEFUN([gl_STDBIT_H_REQUIRE_DEFAULTS]
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_BIT_WIDTH])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_BIT_FLOOR])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_BIT_CEIL])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_MEMREVERSE8U])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_LOAD8_ALIGNED])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_LOAD8])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_STORE8_ALIGNED])
diff --git a/modules/stdbit-h b/modules/stdbit-h
index 9ea678de01..7a02a0df55 100644
--- a/modules/stdbit-h
+++ b/modules/stdbit-h
@@ -46,6 +46,7 @@ stdbit.h: stdbit.in.h $(top_builddir)/config.status
 	  -e 's/@''GNULIB_STDC_BIT_WIDTH''@/$(GNULIB_STDC_BIT_WIDTH)/g' \
 	  -e 's/@''GNULIB_STDC_BIT_FLOOR''@/$(GNULIB_STDC_BIT_FLOOR)/g' \
 	  -e 's/@''GNULIB_STDC_BIT_CEIL''@/$(GNULIB_STDC_BIT_CEIL)/g' \
+	  -e 's/@''GNULIB_STDC_MEMREVERSE8U''@/$(GNULIB_STDC_MEMREVERSE8U)/g' \
 	  -e 's/@''GNULIB_STDC_LOAD8_ALIGNED''@/$(GNULIB_STDC_LOAD8_ALIGNED)/g' \
 	  -e 's/@''GNULIB_STDC_LOAD8''@/$(GNULIB_STDC_LOAD8)/g' \
 	  -e 's/@''GNULIB_STDC_STORE8_ALIGNED''@/$(GNULIB_STDC_STORE8_ALIGNED)/g' \
diff --git a/modules/stdc_memreverse8u b/modules/stdc_memreverse8u
new file mode 100644
index 0000000000..243c29b090
--- /dev/null
+++ b/modules/stdc_memreverse8u
@@ -0,0 +1,27 @@
+Description:
+stdc_memreverse8u* functions: Swap bytes of an unsigned integer value.
+
+Files:
+lib/stdc_memreverse8u.c
+
+Depends-on:
+stdbit-h
+stdint-h
+
+configure.ac:
+AC_REQUIRE([gl_STDBIT_H])
+gl_STDBIT_MODULE_INDICATOR([stdc_memreverse8u])
+
+Makefile.am:
+if GL_GENERATE_STDBIT_H
+lib_SOURCES += stdc_memreverse8u.c
+endif
+
+Include:
+<stdbit.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-- 
2.52.0

>From ee8c16407d902cae5aa150742a0d5aba1d54a1a5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 15 Mar 2026 13:05:20 +0100
Subject: [PATCH 2/2] stdc_memreverse8u: Add tests.

* tests/test-stdc_memreverse8u.c: New file, based on
tests/test-byteswap.c.
* modules/stdc_memreverse8u-tests: New file.
---
 ChangeLog                       |  5 +++
 modules/stdc_memreverse8u-tests | 11 +++++
 tests/test-stdc_memreverse8u.c  | 79 +++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 modules/stdc_memreverse8u-tests
 create mode 100644 tests/test-stdc_memreverse8u.c

diff --git a/ChangeLog b/ChangeLog
index c365890c4c..190494ebc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2026-03-15  Bruno Haible  <[email protected]>
 
+	stdc_memreverse8u: Add tests.
+	* tests/test-stdc_memreverse8u.c: New file, based on
+	tests/test-byteswap.c.
+	* modules/stdc_memreverse8u-tests: New file.
+
 	stdc_memreverse8u: New module.
 	* lib/stdbit.in.h (_GL_STDC_MEMREVERSE8U_INLINE): New macro.
 	(stdc_memreverse8u8, stdc_memreverse8u16, stdc_memreverse8u32,
diff --git a/modules/stdc_memreverse8u-tests b/modules/stdc_memreverse8u-tests
new file mode 100644
index 0000000000..d4c83ebaed
--- /dev/null
+++ b/modules/stdc_memreverse8u-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-stdc_memreverse8u.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-stdc_memreverse8u
+check_PROGRAMS += test-stdc_memreverse8u
diff --git a/tests/test-stdc_memreverse8u.c b/tests/test-stdc_memreverse8u.c
new file mode 100644
index 0000000000..0cfe98bc4b
--- /dev/null
+++ b/tests/test-stdc_memreverse8u.c
@@ -0,0 +1,79 @@
+/* Test of stdc_memreverse8u* functions.
+   Copyright (C) 2007-2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <[email protected]>, 2007.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdbit.h>
+
+#include <stdint.h>
+
+#include "macros.h"
+
+/* Test stdc_memreverse8u* functions with constant values.  */
+static void
+test_memreverse8u_constant (void)
+{
+  ASSERT (stdc_memreverse8u8 (UINT8_C (0x42)) == UINT8_C (0x42));
+  ASSERT (stdc_memreverse8u16 (UINT16_C (0x1234)) == UINT16_C (0x3412));
+  ASSERT (stdc_memreverse8u32 (UINT32_C (0x12345678)) == UINT32_C (0x78563412));
+  ASSERT (stdc_memreverse8u64 (UINT64_C (0x1234567890ABCDEF))
+          == UINT64_C (0xEFCDAB9078563412));
+}
+
+/* Test that the stdc_memreverse8u* functions evaluate their arguments once.  */
+static void
+test_memreverse8u_eval_once (void)
+{
+  uint8_t value_0 = 0;
+  ASSERT (stdc_memreverse8u8 (value_0++) == 0);
+  ASSERT (value_0 == 1);
+
+  uint16_t value_1 = 0;
+  ASSERT (stdc_memreverse8u16 (value_1++) == 0);
+  ASSERT (value_1 == 1);
+
+  uint32_t value_2 = 0;
+  ASSERT (stdc_memreverse8u32 (value_2++) == 0);
+  ASSERT (value_2 == 1);
+
+  uint64_t value_3 = 0;
+  ASSERT (stdc_memreverse8u64 (value_3++) == 0);
+  ASSERT (value_3 == 1);
+}
+
+/* Test that the stdc_memreverse8u* functions accept floating-point
+   arguments.  */
+static void
+test_memreverse8u_double (void)
+{
+  ASSERT (stdc_memreverse8u8 (0.0) == 0);
+  ASSERT (stdc_memreverse8u16 (0.0) == 0);
+  ASSERT (stdc_memreverse8u32 (0.0) == 0);
+  ASSERT (stdc_memreverse8u64 (0.0) == 0);
+}
+
+int
+main (void)
+{
+  test_memreverse8u_constant ();
+  test_memreverse8u_eval_once ();
+  test_memreverse8u_double ();
+
+  return test_exit_status;
+}
-- 
2.52.0

Reply via email to