]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stdc_rotate_right: New module.
authorCollin Funk <collin.funk1@gmail.com>
Mon, 16 Mar 2026 00:00:38 +0000 (17:00 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Mon, 16 Mar 2026 00:07:32 +0000 (17:07 -0700)
* lib/stdbit.in.h (_GL_STDC_ROTATE_RIGHT_INLINE, _gl_stdc_rotate_right)
(stdc_rotate_right): New macros.
(stdc_rotate_right_uc, stdc_rotate_right_us, stdc_rotate_right_ui)
(stdc_rotate_right_ul, stdc_rotate_right_ull): New functions.
* lib/stdc_rotate_right.c: New file.
* m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
GNULIB_STDC_ROTATE_RIGHT.
* modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_ROTATE_RIGHT.
* modules/stdc_rotate_right: New file.
* doc/posix-functions/stdc_rotate_right.texi: Mention the new module.

ChangeLog
doc/posix-functions/stdc_rotate_right.texi
lib/stdbit.in.h
lib/stdc_rotate_right.c [new file with mode: 0644]
m4/stdbit_h.m4
modules/stdbit-h
modules/stdc_rotate_right [new file with mode: 0644]

index 125a021a0b46c4c87bd50273fc292e49ecd11f47..1600534ee68ab344b0a898c9d555059c63f2eaf6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2026-03-15  Collin Funk  <collin.funk1@gmail.com>
 
+       stdc_rotate_right: New module.
+       * lib/stdbit.in.h (_GL_STDC_ROTATE_RIGHT_INLINE, _gl_stdc_rotate_right)
+       (stdc_rotate_right): New macros.
+       (stdc_rotate_right_uc, stdc_rotate_right_us, stdc_rotate_right_ui)
+       (stdc_rotate_right_ul, stdc_rotate_right_ull): New functions.
+       * lib/stdc_rotate_right.c: New file.
+       * m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
+       GNULIB_STDC_ROTATE_RIGHT.
+       * modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_ROTATE_RIGHT.
+       * modules/stdc_rotate_right: New file.
+       * doc/posix-functions/stdc_rotate_right.texi: Mention the new module.
+
        stdc_rotate_left: Add tests.
        * modules/stdc_rotate_left-tests: New file.
        * tests/test-stdc_rotate_left.c: Likewise.
index 9080fc69eb342bf2616870d08364e7a2f3026f17..78c08ce56ab3d8e16ea5e0822cb36baa9bcfd981 100644 (file)
@@ -12,7 +12,7 @@ ISO C2y (draft
 @url{https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3783.pdf})
 section 7.18.18.
 
-Gnulib module: ---
+Gnulib module: stdc_rotate_right
 
 Portability problems fixed by Gnulib:
 @itemize
index 09bc0d307da98fe95b20c41f05fc1e21d0c2e626..919e472f63ba62bd55262fe93aaae8c8d547a843 100644 (file)
@@ -144,6 +144,9 @@ _GL_INLINE_HEADER_BEGIN
 #ifndef _GL_STDC_ROTATE_LEFT_INLINE
 # define _GL_STDC_ROTATE_LEFT_INLINE _GL_INLINE
 #endif
+#ifndef _GL_STDC_ROTATE_RIGHT_INLINE
+# define _GL_STDC_ROTATE_RIGHT_INLINE _GL_INLINE
+#endif
 #ifndef _GL_STDC_MEMREVERSE8_INLINE
 # define _GL_STDC_MEMREVERSE8_INLINE _GL_INLINE
 #endif
@@ -1223,6 +1226,66 @@ stdc_rotate_left_ull (unsigned long long int v, unsigned int c)
 
 #endif
 
+/* ISO C2y § 7.18.18 Rotate Right  */
+
+#if @GNULIB_STDC_ROTATE_RIGHT@
+
+# ifdef __has_builtin
+#  if __has_builtin (__builtin_stdc_rotate_right)
+#   define _gl_stdc_rotate_right __builtin_stdc_rotate_right
+#   define stdc_rotate_right __builtin_stdc_rotate_right
+#  endif
+# endif
+
+# ifndef _gl_stdc_rotate_right
+#  define _gl_stdc_rotate_right(v, c)               \
+  (((v) >> ((c) & (sizeof (v) * 8 - 1)))            \
+   | ((v) << (-(c) & (sizeof (v) * 8 - 1))))
+# endif
+
+_GL_STDC_ROTATE_RIGHT_INLINE unsigned char
+stdc_rotate_right_uc (unsigned char v, unsigned int c)
+{
+  return _gl_stdc_rotate_right (v, c);
+}
+
+_GL_STDC_ROTATE_RIGHT_INLINE unsigned short int
+stdc_rotate_right_us (unsigned short int v, unsigned int c)
+{
+  return _gl_stdc_rotate_right (v, c);
+}
+
+_GL_STDC_ROTATE_RIGHT_INLINE unsigned int
+stdc_rotate_right_ui (unsigned int v, unsigned int c)
+{
+  return _gl_stdc_rotate_right (v, c);
+}
+
+_GL_STDC_ROTATE_RIGHT_INLINE unsigned long int
+stdc_rotate_right_ul (unsigned long int v, unsigned int c)
+{
+  return _gl_stdc_rotate_right (v, c);
+}
+
+_GL_STDC_ROTATE_RIGHT_INLINE unsigned long long int
+stdc_rotate_right_ull (unsigned long long int v, unsigned int c)
+{
+  return _gl_stdc_rotate_right (v, c);
+}
+
+# ifndef stdc_rotate_right
+#  define stdc_rotate_right(v, c)                                       \
+  (_GL_STDBIT_TYPEOF_CAST                                               \
+   (v,                                                                  \
+    (sizeof (v) == 1 ? stdc_rotate_right_uc (v, c)                      \
+     : sizeof (v) == sizeof (unsigned short int) ? stdc_rotate_right_us (v, c) \
+     : sizeof (v) == sizeof 0u ? stdc_rotate_right_ui (v, c)            \
+     : sizeof (v) == sizeof 0ul ? stdc_rotate_right_ul (v, c)           \
+     : stdc_rotate_right_ull (v, c))))
+# endif
+
+#endif
+
 /* ISO C2y § 7.18.19 8-bit Memory Reversal  */
 
 #if @GNULIB_STDC_MEMREVERSE8@
diff --git a/lib/stdc_rotate_right.c b/lib/stdc_rotate_right.c
new file mode 100644 (file)
index 0000000..6aa5e11
--- /dev/null
@@ -0,0 +1,19 @@
+/* stdc_rotate_right_* 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_ROTATE_RIGHT_INLINE _GL_EXTERN_INLINE
+#include <config.h>
+#include <stdbit.h>
index 33d0ce4d5d4e54495ed76c7c2264b09eed226e0b..0ab347767c7ea6c51581857ee561e388c9f9119a 100644 (file)
@@ -1,5 +1,5 @@
 # stdbit_h.m4
-# serial 12
+# serial 13
 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,
@@ -67,6 +67,7 @@ AC_DEFUN([gl_STDBIT_H_REQUIRE_DEFAULTS],
     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_ROTATE_LEFT])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_ROTATE_RIGHT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_MEMREVERSE8])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_MEMREVERSE8U])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDC_LOAD8_ALIGNED])
index 7113d147cd89b1d466bfb48c2bbbe0244f0ed965..5bba8b8bad6e56dc2f52c3bd48a8376106403455 100644 (file)
@@ -47,6 +47,7 @@ stdbit.h: stdbit.in.h $(top_builddir)/config.status
          -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_ROTATE_LEFT''@/$(GNULIB_STDC_ROTATE_LEFT)/g' \
+         -e 's/@''GNULIB_STDC_ROTATE_RIGHT''@/$(GNULIB_STDC_ROTATE_RIGHT)/g' \
          -e 's/@''GNULIB_STDC_MEMREVERSE8''@/$(GNULIB_STDC_MEMREVERSE8)/g' \
          -e 's/@''GNULIB_STDC_MEMREVERSE8U''@/$(GNULIB_STDC_MEMREVERSE8U)/g' \
          -e 's/@''GNULIB_STDC_LOAD8_ALIGNED''@/$(GNULIB_STDC_LOAD8_ALIGNED)/g' \
diff --git a/modules/stdc_rotate_right b/modules/stdc_rotate_right
new file mode 100644 (file)
index 0000000..5492c59
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+stdc_rotate_right macro, stdc_rotate_right_* functions:
+Perform a right circular shift.
+
+Files:
+lib/stdc_rotate_right.c
+
+Depends-on:
+stdbit-h
+
+configure.ac:
+AC_REQUIRE([gl_STDBIT_H])
+gl_STDBIT_MODULE_INDICATOR([stdc_rotate_right])
+
+Makefile.am:
+if GL_GENERATE_STDBIT_H
+lib_SOURCES += stdc_rotate_right.c
+endif
+
+Include:
+<stdbit.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all