[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251129114618.5bbc6c3c@pumpkin>
Date: Sat, 29 Nov 2025 11:46:18 +0000
From: david laight <david.laight@...box.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Rasmus Villemoes <ravi@...vas.dk>, "Yury Norov (NVIDIA)"
<yury.norov@...il.com>, Linus Walleij <linus.walleij@...aro.org>, Nicolas
Frattaroli <nicolas.frattaroli@...labora.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 00/21] lib: add alternatives for GENMASK()
On Wed, 26 Nov 2025 11:44:59 -0800
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Wed, 26 Nov 2025 at 01:07, Rasmus Villemoes <ravi@...vas.dk> wrote:
> >
> > There is, however, an alternative that resembles the syntax in data
> > sheets even more closely:
> >
> > #define BITS(low_high) GENMASK((0 ? low_high), (1 ? low_high))
>
> Oh, me likey. That's a much better idea than my crazy syntax.
>
> Linus
>
I've had a couple of further thoughts...
1) GENMASK() could just swap the two arguments if they are constant and
in the wrong order, so GENMASK(2, 4) and GENMASK(4, 2) are equivalent.
Easily done without too much bloat in a statement expression.
2) It a lot of cases the result from GENMASK() is only ever passed to FIELD_XXX().
The latter really don't want the mask - they want the two bit numbers.
(In particular the low bit number.)
So you could change the headers to have (eg):
#define REGISTER_BITS_FOR_XXX (5:7)
Then the expected calling 'convention' would be FIELD_XXX((lo:hi), val).
All done with:
#define _BIT_LO(lo_hi) (1 ? lo_hi)
#define _BIT_HI(lo_hi) (0 ? lo_hi)
#define FIELD_XXX(lo_hi, ...) ({
u32 _lo = _BIT_LO lo_hi;
u32 _hi = _BIT_HI lo_hi;
...
Any attempted use without the 'magic macros' will be a nice syntax error.
David
Powered by blists - more mailing lists