[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fab10eb9e70041c0a034f4945a978e00@AcuMS.aculab.com>
Date: Sun, 17 Nov 2024 19:23:20 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Linus Torvalds' <torvalds@...ux-foundation.org>
CC: Vincent Mailhol <mailhol.vincent@...adoo.fr>, Yury Norov
<yury.norov@...il.com>, Rasmus Villemoes <linux@...musvillemoes.dk>, "Luc Van
Oostenryck" <luc.vanoostenryck@...il.com>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "linux-sparse@...r.kernel.org"
<linux-sparse@...r.kernel.org>, Rikard Falkeborn <rikard.falkeborn@...il.com>
Subject: RE: [PATCH v4 1/2] compiler.h: add const_true()
From: Linus Torvalds
> Sent: 17 November 2024 19:10
>
> On Sun, 17 Nov 2024 at 11:05, David Laight <David.Laight@...lab.com> wrote:
> >
> > I think everything can be built on a base if_const_zero(x, if_z, if_nz)
> > #define const_true(x) if_const_zero(!(x), 1, 0)
> > #define is_constexpr(x) if_const_zero((x) * 0, 1, 0)
> > which gives a bit more flexibility.
>
> The is_constexpr() should probably be if_const_zero(0*!(x),1,0) to be
> ok with pointers and with "long long" constants.
>
> And the "1,0" arguments should have a real reason for existing. I'm
> not entirely convinced any other cases make much sense.
I might have used them when trying to get (high >= 0u) through a -W1 build.
(for example in GENMASK()).
Can't quite remember the horrid solution though.
Since 99% will be 1,0 maybe saving the extra expansion is best anyway.
So have is_const_zero(x) and add if_const_zero(x, if_z, if_nz) later.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists