From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id 539B9385021E; Fri, 24 Jun 2022 05:42:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 539B9385021E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] bitset: avoid pessimized code when bitset size is not constant X-Act-Checkin: newlib-cygwin X-Git-Author: Ryan Libby X-Git-Refname: refs/heads/master X-Git-Oldrev: a6bd733db995ce9269e7654c67d2e57256a8d7c2 X-Git-Newrev: 96c645a0b1e8c136f0d70106b8ab3d0acf621c12 Message-Id: <20220624054214.539B9385021E@sourceware.org> Date: Fri, 24 Jun 2022 05:42:14 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 05:42:14 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D96c645a0b1e= 8c136f0d70106b8ab3d0acf621c12 commit 96c645a0b1e8c136f0d70106b8ab3d0acf621c12 Author: Ryan Libby Date: Tue Dec 3 17:43:57 2019 +0000 bitset: avoid pessimized code when bitset size is not constant =20 We have a couple optimizations for when the bitset is known to be just one word. But with dynamically sized bitsets, it was actually more work to determine the size than just to do the necessary computation. Now, only use the optimization when the size is known to be constant. =20 Reviewed by: markj Discussed with: jeff Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D22639 Diff: --- newlib/libc/sys/rtems/include/sys/bitset.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/newlib/libc/sys/rtems/include/sys/bitset.h b/newlib/libc/sys/r= tems/include/sys/bitset.h index d119c23ca..0334939c9 100644 --- a/newlib/libc/sys/rtems/include/sys/bitset.h +++ b/newlib/libc/sys/rtems/include/sys/bitset.h @@ -37,12 +37,19 @@ #include #include =20 +/* + * Whether expr is both constant and true. Result is itself constant. + * Used to enable optimizations for sets with a known small size. + */ +#define __constexpr_cond(expr) (__builtin_constant_p((expr)) && (expr)) + #define __bitset_mask(_s, n) \ - (1L << ((__bitset_words((_s)) =3D=3D 1) ? \ + (1L << (__constexpr_cond(__bitset_words((_s)) =3D=3D 1) ? \ (__size_t)(n) : ((n) % _BITSET_BITS))) =20 #define __bitset_word(_s, n) \ - ((__bitset_words((_s)) =3D=3D 1) ? 0 : ((n) / _BITSET_BITS)) + (__constexpr_cond(__bitset_words((_s)) =3D=3D 1) ? \ + 0 : ((n) / _BITSET_BITS)) =20 #define BIT_CLR(_s, n, p) \ ((p)->__bits[__bitset_word(_s, n)] &=3D ~__bitset_mask((_s), (n)))