]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stdc_rotate_left: New module.
authorCollin Funk <collin.funk1@gmail.com>
Sun, 15 Mar 2026 23:48:45 +0000 (16:48 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Mon, 16 Mar 2026 00:06:50 +0000 (17:06 -0700)
* lib/stdbit.in.h (_GL_STDC_ROTATE_LEFT_INLINE, _gl_stdc_rotate_left)
(stdc_rotate_left): New macros.
(stdc_rotate_left_uc, stdc_rotate_left_us, stdc_rotate_left_ui)
(stdc_rotate_left_ul, stdc_rotate_left_ull): New functions.
* lib/stdc_rotate_left.c: New file.
* m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
GNULIB_STDC_ROTATE_LEFT.
* modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_ROTATE_LEFT.
* modules/stdc_rotate_left: New file.
* doc/posix-functions/stdc_rotate_left.texi: Mention the new module.

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

index d9b7a63064213d4970f5a3399f316e026f289e54..11fffd3b5fd00ba4d6c935a396983ca7aeb1537d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2026-03-15  Collin Funk  <collin.funk1@gmail.com>
+
+       stdc_rotate_left: New module.
+       * lib/stdbit.in.h (_GL_STDC_ROTATE_LEFT_INLINE, _gl_stdc_rotate_left)
+       (stdc_rotate_left): New macros.
+       (stdc_rotate_left_uc, stdc_rotate_left_us, stdc_rotate_left_ui)
+       (stdc_rotate_left_ul, stdc_rotate_left_ull): New functions.
+       * lib/stdc_rotate_left.c: New file.
+       * m4/stdbit_h.m4 (gl_STDBIT_H_REQUIRE_DEFAULTS): Initialize
+       GNULIB_STDC_ROTATE_LEFT.
+       * modules/stdbit-h (Makefile.am): Substitute GNULIB_STDC_ROTATE_LEFT.
+       * modules/stdc_rotate_left: New file.
+       * doc/posix-functions/stdc_rotate_left.texi: Mention the new module.
+
 2026-03-15  Bruno Haible  <bruno@clisp.org>
 
        posix_spawn-internal: Move private Gnulib functions to _gl_* namespace.
index 2ce4c22065fad83b32d9ebec0377a92ab30128b4..2e4c89c1b2bab0a007978fb1c5d0ea206ce5bbd6 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.17.
 
-Gnulib module: ---
+Gnulib module: stdc_rotate_left
 
 Portability problems fixed by Gnulib:
 @itemize
index e7d7e7a9eefa31a52f926574ffc48a7aa0e4e95f..09bc0d307da98fe95b20c41f05fc1e21d0c2e626 100644 (file)
@@ -141,6 +141,9 @@ _GL_INLINE_HEADER_BEGIN
 #ifndef _GL_STDC_BIT_CEIL_INLINE
 # define _GL_STDC_BIT_CEIL_INLINE _GL_INLINE
 #endif
+#ifndef _GL_STDC_ROTATE_LEFT_INLINE
+# define _GL_STDC_ROTATE_LEFT_INLINE _GL_INLINE
+#endif
 #ifndef _GL_STDC_MEMREVERSE8_INLINE
 # define _GL_STDC_MEMREVERSE8_INLINE _GL_INLINE
 #endif
@@ -1160,6 +1163,65 @@ stdc_bit_ceil_ull (unsigned long long int n)
 
 #endif /* @HAVE_STDBIT_H@ */
 
+/* ISO C2y § 7.18.17 Rotate Left  */
+
+#if @GNULIB_STDC_ROTATE_LEFT@
+
+# ifdef __has_builtin
+#  if __has_builtin (__builtin_stdc_rotate_left)
+#   define _gl_stdc_rotate_left __builtin_stdc_rotate_left
+#   define stdc_rotate_left __builtin_stdc_rotate_left
+#  endif
+# endif
+
+# ifndef _gl_stdc_rotate_left
+#  define _gl_stdc_rotate_left(v, c)                \
+  (((v) << ((c) & (sizeof (v) * 8 - 1)))            \
+   | ((v) >> (-(c) & (sizeof (v) * 8 - 1))))
+# endif
+
+_GL_STDC_ROTATE_LEFT_INLINE unsigned char
+stdc_rotate_left_uc (unsigned char v, unsigned int c)
+{
+  return _gl_stdc_rotate_left (v, c);
+}
+
+_GL_STDC_ROTATE_LEFT_INLINE unsigned short int
+stdc_rotate_left_us (unsigned short int v, unsigned int c)
+{
+  return _gl_stdc_rotate_left (v, c);
+}
+
+_GL_STDC_ROTATE_LEFT_INLINE unsigned int
+stdc_rotate_left_ui (unsigned int v, unsigned int c)
+{
+  return _gl_stdc_rotate_left (v, c);
+}
+
+_GL_STDC_ROTATE_LEFT_INLINE unsigned long int
+stdc_rotate_left_ul (unsigned long int v, unsigned int c)
+{
+  return _gl_stdc_rotate_left (v, c);
+}
+
+_GL_STDC_ROTATE_LEFT_INLINE unsigned long long int
+stdc_rotate_left_ull (unsigned long long int v, unsigned int c)
+{
+  return _gl_stdc_rotate_left (v, c);
+}
+
+# ifndef stdc_rotate_left
+#  define stdc_rotate_left(v, c)                                        \
+  (_GL_STDBIT_TYPEOF_CAST                                               \
+   (v,                                                                  \
+    (sizeof (v) == 1 ? stdc_rotate_left_uc (v, c)                       \
+     : sizeof (v) == sizeof (unsigned short int) ? stdc_rotate_left_us (v, c) \
+     : sizeof (v) == sizeof 0u ? stdc_rotate_left_ui (v, c)             \
+     : sizeof (v) == sizeof 0ul ? stdc_rotate_left_ul (v, c)            \
+     : stdc_rotate_left_ull (v, c))))
+# endif
+
+#endif
 
 /* ISO C2y § 7.18.19 8-bit Memory Reversal  */
 
diff --git a/lib/stdc_rotate_left.c b/lib/stdc_rotate_left.c
new file mode 100644 (file)
index 0000000..196aa96
--- /dev/null
@@ -0,0 +1,19 @@
+/* stdc_rotate_left_* 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_LEFT_INLINE _GL_EXTERN_INLINE
+#include <config.h>
+#include <stdbit.h>
index a84aa3c8cb6100601cf130c8bef89960527d9a65..33d0ce4d5d4e54495ed76c7c2264b09eed226e0b 100644 (file)
@@ -1,5 +1,5 @@
 # stdbit_h.m4
-# serial 11
+# serial 12
 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_ROTATE_LEFT])
     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 1c1f76e358d83a9335d08ef42933975b2c52a591..7113d147cd89b1d466bfb48c2bbbe0244f0ed965 100644 (file)
@@ -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_ROTATE_LEFT''@/$(GNULIB_STDC_ROTATE_LEFT)/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_left b/modules/stdc_rotate_left
new file mode 100644 (file)
index 0000000..a2e22e7
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+stdc_rotate_left macro, stdc_rotate_left_* functions:
+Perform a left circular shift.
+
+Files:
+lib/stdc_rotate_left.c
+
+Depends-on:
+stdbit-h
+
+configure.ac:
+AC_REQUIRE([gl_STDBIT_H])
+gl_STDBIT_MODULE_INDICATOR([stdc_rotate_left])
+
+Makefile.am:
+if GL_GENERATE_STDBIT_H
+lib_SOURCES += stdc_rotate_left.c
+endif
+
+Include:
+<stdbit.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all