[PATCH v2] io: Use gnulib fts implementation (BZ 22944, BZ 20331)

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Mar 6 14:16:33 GMT 2026



On 05/03/26 23:23, Collin Funk wrote:
> Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
> 
>>> size_t val = stdc_rotate_right ((size_t) data, 3);
>>
>>> That is a C2y function right? I don't think we can use it. Looking at
>>> the releases with the relevant commit:
>>
>> See stdlib/stdbit.h - it supports all GCC releases even with hacks for GCC 3.4!
> 
> I can have a look at adding it in Gnulib this weekend (hopefully).
> 
>> (hence my proposal to drop support for such old compilers)
> 
> There was a previous thread about dropping old compiler support [1]. I
> think most wanted to keep it around in headers.
> 
> Collin
> 
> [1] https://inbox.sourceware.org/libc-alpha/87o6pa6ee8.fsf@gmail.com/

I was not aware that C2y now proposed the std::rotr; it does simplify
things a bit.  I think we can do the following for now, and when we
add full N3367 support we can then remove this internal code in favor
of the exported header.

diff --git a/include/stdbit.h b/include/stdbit.h
index ebd9795f28..c66016b0da 100644
--- a/include/stdbit.h
+++ b/include/stdbit.h
@@ -1 +1,54 @@
+#ifndef _STDBIT_H
 #include <stdlib/stdbit.h>
+
+#ifndef _ISOMAC
+# include <stdint.h>
+
+#  if __glibc_has_builtin (___builtin_stdc_rotate_right)
+#   define stdc_rotate_right(__x, __n) \
+  (___builtin_stdc_rotate_right (__x, __n))
+#  else
+#   if __WORDSIZE == 64
+#    define __ROR_UL_GENERIC __ror64
+#   else
+#    define __ROR_UL_GENERIC __ror32
+#   endif
+#   define stdc_rotate_right(__x, __n)         \
+   _Generic((__x),                             \
+      unsigned char: __ror8,                   \
+      unsigned short: __ror16,                 \
+      unsigned int: __ror32,                   \
+      unsigned long: __ROR_UL_GENERIC,         \
+      unsigned long long: __ror64              \
+   )(__x, __n)
+
+static __always_inline uint8_t
+__ror8 (uint8_t __x, unsigned int __n)
+{
+  return (((uint32_t) __x >> __n) | ((uint32_t) __x << (8 - __n)))
+    & UINT8_MAX;
+}
+
+static __always_inline uint16_t
+__ror16 (uint16_t __x, unsigned int __n)
+{
+  return (((uint32_t) __x >> __n) | ((uint32_t) __x << (16 - __n)))
+    & UINT16_MAX;
+}
+
+static __always_inline  unsigned int
+__ror32 (uint32_t __x, unsigned int __n)
+{
+  return ((__x >> __n) | (__x << (32 - __n))) & UINT32_MAX;
+}
+
+static __always_inline  unsigned long
+__ror64 (uint64_t __x, unsigned int __n)
+{
+  return ((__x >> __n) | (__x << (64 - __n))) & UINT64_MAX;
+}
+#  endif
+
+# endif /* _ISOMAC */
+
+#endif  /* _STDBIT_H */
diff --git a/misc/hash.c b/misc/hash.c
index ed97f3e81e..2b480058eb 100644
--- a/misc/hash.c
+++ b/misc/hash.c
@@ -26,11 +26,14 @@
 #ifdef _LIBC
 # define USE_OBSTACK           0
 # define TESTING               0
+# include <stdbit.h>
+# define rotr_sz(__x, __n)     stdc_rotate_right(__x, __n)
+#else
+# include "bitrotate.h"
 #endif

 #include "hash.h"

-#include "bitrotate.h"
 #include "next-prime.h"
 #include "xalloc-oversized.h"


More information about the Libc-alpha mailing list