[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251211185319.4daf6e4f@pumpkin>
Date: Thu, 11 Dec 2025 18:53:19 +0000
From: David Laight <david.laight.linux@...il.com>
To: Yury Norov <yury.norov@...il.com>
Cc: Rasmus Villemoes <linux@...musvillemoes.dk>,
linux-kernel@...r.kernel.org, linux-usb@...r.kernel.org, Geert Uytterhoeven
<geert+renesas@...der.be>, Nicolas Frattaroli
<nicolas.frattaroli@...labora.com>
Subject: Re: [PATCH 3/9] bitmap: Use FIELD_PREP() in expansion of
FIELD_PREP_WM16()
On Mon, 8 Dec 2025 19:54:37 -0500
Yury Norov <yury.norov@...il.com> wrote:
> + Nicolas Frattaroli <nicolas.frattaroli@...labora.com>
>
> It's always good to CC an author of the original implementation,
> isn't?
>
> On Mon, Dec 08, 2025 at 10:42:44PM +0000, david.laight.linux@...il.com wrote:
> > From: David Laight <david.laight.linux@...il.com>
> >
> > Instead of directly expanding __BF_FIELD_CHECK() (which really ought
> > not be used outside bitfield) and open-coding the generation of the
> > masked value, just call FIELD_PREP()
>
> That's fair.
>
> > and add an extra check for
> > the mask being at most 16 bits.
>
> Maybe it's time to introduce FIELD_PREP16()?
>
> > Signed-off-by: David Laight <david.laight.linux@...il.com>
> > ---
> > include/linux/hw_bitfield.h | 17 ++++++++---------
> > 1 file changed, 8 insertions(+), 9 deletions(-)
> >
> > diff --git a/include/linux/hw_bitfield.h b/include/linux/hw_bitfield.h
> > index df202e167ce4..d7f21b60449b 100644
> > --- a/include/linux/hw_bitfield.h
> > +++ b/include/linux/hw_bitfield.h
> > @@ -23,15 +23,14 @@
> > * register, a bit in the lower half is only updated if the corresponding bit
> > * in the upper half is high.
> > */
> > -#define FIELD_PREP_WM16(_mask, _val) \
> > - ({ \
> > - typeof(_val) __val = _val; \
> > - typeof(_mask) __mask = _mask; \
> > - __BF_FIELD_CHECK(__mask, ((u16)0U), __val, \
> > - "HWORD_UPDATE: "); \
> > - (((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) | \
> > - ((__mask) << 16); \
> > - })
> > +#define FIELD_PREP_WM16(mask, val) \
> > +({ \
> > + __auto_type _mask = mask; \
>
> Is __auto_type any better than typeof()?
There is likely to be pressure for a global change soon.
6.19 contains '#define auto __auto_type' to match C23.
>
> > + u32 _val = FIELD_PREP(_mask, val); \
> > + BUILD_BUG_ON_MSG(_mask > 0xffffu, \
> > + "FIELD_PREP_WM16: mask too large"); \
>
> Not necessary to split this line.
Only because I removed a level on indentation.
>
> > + _val | (_mask << 16); \
> > +})
>
> Can you share bloat-o-meter and code generation examples?
>
> For the next version please try to keep as much history
> untouched as possible.
Even the minimal changes (not moving the continuation markers) change pretty
much all the lines.
So It really isn't worth trying to keep it.
David
Powered by blists - more mailing lists