Thread (40 messages) 40 messages, 11 authors, 2021-11-24

Re: [PATCH 01/17] bitfield: Add non-constant field_{prep,get}() helpers

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2021-11-23 08:36:49
Also in: alsa-devel, linux-aspeed, linux-clk, linux-gpio, linux-iio, linux-media, linux-mmc, linux-omap, linux-pm, linux-renesas-soc, lkml, netdev

Hi Jakub,

On Tue, Nov 23, 2021 at 2:17 AM Jakub Kicinski [off-list ref] wrote:
On Mon, 22 Nov 2021 17:32:43 +0100 Johannes Berg wrote:
quoted
On Mon, 2021-11-22 at 16:53 +0100, Geert Uytterhoeven wrote:
quoted
The existing FIELD_{GET,PREP}() macros are limited to compile-time
constants.  However, it is very common to prepare or extract bitfield
elements where the bitfield mask is not a compile-time constant.
I'm not sure it's really a good idea to add a third API here?
+1
Yeah, a smaller API is better.
quoted
We have the upper-case (constant) versions, and already
{u32,...}_get_bits()/etc.
TBH, I don't like the *_get_bits() API: in general, u32_get_bits() does
the same as FIELD_GET(), but the order of the parameters is different?
(*_replace_bits() seems to be useful, though)

That's why I picked field_{get,prep}().
quoted
Also, you're using __ffs(), which doesn't work for 64-bit on 32-bit
architectures (afaict), so that seems a bit awkward.

Maybe we can make {u32,...}_get_bits() be doing compile-time only checks
if it is indeed a constant? The __field_overflow() usage is already only
done if __builtin_constant_p(v), so I guess we can do the same with
__bad_mask()?
Either that or add decomposition macros. Are compilers still really bad
at passing small structs by value?
Sorry, I don't get what you mean by adding decomposition macros.
Can you please elaborate?
Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help