From: David Laight <David.Laight@ACULAB.COM>
To: 'Vincent Mailhol' <mailhol.vincent@wanadoo.fr>,
Linus Torvalds <torvalds@linux-foundation.org>,
Yury Norov <yury.norov@gmail.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-sparse@vger.kernel.org" <linux-sparse@vger.kernel.org>,
"Rikard Falkeborn" <rikard.falkeborn@gmail.com>
Subject: RE: [PATCH v4 2/2] linux/bits.h: simplify GENMASK_INPUT_CHECK()
Date: Sun, 17 Nov 2024 17:24:54 +0000 [thread overview]
Message-ID: <8bf9eb4434104a3b960d52bd1d38caea@AcuMS.aculab.com> (raw)
In-Reply-To: <20241113172939.747686-6-mailhol.vincent@wanadoo.fr>
From: Vincent Mailhol
> Sent: 13 November 2024 17:19
>
> In GENMASK_INPUT_CHECK(),
>
> __builtin_choose_expr(__is_constexpr((l) > (h)), (l) > (h), 0)
>
> is the exact expansion of:
>
> const_true((l) > (h))
>
> Apply const_true() to simplify GENMASK_INPUT_CHECK().
Wouldn't statically_true() give better coverage ?
I wouldn't have though that GENMASK() got used anywhere where a constant
integer expression was needed.
More interesting would be to get it to pass a W=1 build for
any place where 'l' is 0u.
David
>
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> ---
> This change passes the unit tests from CONFIG_BITS_TEST, including the
> extra negative tests provided under #ifdef TEST_GENMASK_FAILURES [1].
>
> [1] commit 6d511020e13d ("lib/test_bits.c: add tests of GENMASK")
> Link: https://git.kernel.org/torvalds/c/6d511020e13d
> ---
> include/linux/bits.h | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/bits.h b/include/linux/bits.h
> index 60044b608817..61a75d3f294b 100644
> --- a/include/linux/bits.h
> +++ b/include/linux/bits.h
> @@ -20,9 +20,8 @@
> */
> #if !defined(__ASSEMBLY__)
> #include <linux/build_bug.h>
> -#define GENMASK_INPUT_CHECK(h, l) \
> - (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
> - __is_constexpr((l) > (h)), (l) > (h), 0)))
> +#include <linux/compiler.h>
> +#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
> #else
> /*
> * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
> --
> 2.45.2
>
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-11-17 17:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 17:18 [PATCH v4 0/2] add const_true() to simplify GENMASK_INPUT_CHECK() Vincent Mailhol
2024-11-13 17:18 ` [PATCH v4 1/2] compiler.h: add const_true() Vincent Mailhol
2024-11-13 18:53 ` Yury Norov
2024-12-30 18:32 ` Yury Norov
2024-12-31 4:58 ` Vincent Mailhol
2024-11-17 17:42 ` David Laight
2024-11-17 18:00 ` Linus Torvalds
2024-11-17 19:02 ` Linus Torvalds
2024-11-17 19:05 ` David Laight
2024-11-17 19:09 ` Linus Torvalds
2024-11-17 19:23 ` David Laight
2024-11-17 20:12 ` Linus Torvalds
2024-11-17 22:38 ` David Laight
2024-11-17 22:58 ` Linus Torvalds
2024-11-18 3:22 ` Vincent Mailhol
2024-11-18 9:27 ` David Laight
2024-11-18 17:09 ` Linus Torvalds
2024-11-13 17:18 ` [PATCH v4 2/2] linux/bits.h: simplify GENMASK_INPUT_CHECK() Vincent Mailhol
2024-11-17 17:24 ` David Laight [this message]
2024-11-17 19:45 ` David Laight
2024-11-18 1:14 ` Vincent Mailhol
2024-11-18 1:12 ` Vincent Mailhol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8bf9eb4434104a3b960d52bd1d38caea@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luc.vanoostenryck@gmail.com \
--cc=mailhol.vincent@wanadoo.fr \
--cc=rikard.falkeborn@gmail.com \
--cc=torvalds@linux-foundation.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox