From: Collin Funk Date: Mon, 16 Mar 2026 00:00:38 +0000 (-0700) Subject: stdc_rotate_right: New module. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ffbb1f4fe48aa66b67191bfd6f2da9a2fa1ec39;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 125a021a0b..1600534ee6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2026-03-15 Collin Funk + 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. diff --git a/doc/posix-functions/stdc_rotate_right.texi b/doc/posix-functions/stdc_rotate_right.texi index 9080fc69eb..78c08ce56a 100644 --- a/doc/posix-functions/stdc_rotate_right.texi +++ b/doc/posix-functions/stdc_rotate_right.texi @@ -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 diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index 09bc0d307d..919e472f63 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -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 index 0000000000..6aa5e11797 --- /dev/null +++ b/lib/stdc_rotate_right.c @@ -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 . */ + +#define _GL_STDC_ROTATE_RIGHT_INLINE _GL_EXTERN_INLINE +#include +#include diff --git a/m4/stdbit_h.m4 b/m4/stdbit_h.m4 index 33d0ce4d5d..0ab347767c 100644 --- a/m4/stdbit_h.m4 +++ b/m4/stdbit_h.m4 @@ -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]) diff --git a/modules/stdbit-h b/modules/stdbit-h index 7113d147cd..5bba8b8bad 100644 --- a/modules/stdbit-h +++ b/modules/stdbit-h @@ -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 index 0000000000..5492c59b29 --- /dev/null +++ b/modules/stdc_rotate_right @@ -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: + + +License: +LGPLv2+ + +Maintainer: +all