[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdW=JT8NFCPkccHedO45x_Cq7bQ0XfYP0dm7HYc0nuu2dA@mail.gmail.com>
Date: Tue, 6 Dec 2016 12:12:21 +0100
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Sebastian Frias <sf84@...oste.net>
Cc: zijun_hu <zijun_hu@....com>, Sasha Levin <sasha.levin@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Mason <slash.tmp@...e.fr>,
Maxime Coquelin <maxime.coquelin@...com>,
Harvey Harrison <harvey.harrison@...il.com>,
Borislav Petkov <bp@...en8.de>
Subject: Re: [PATCH] bitops: add equivalent of BIT(x) for bitfields
Hi Sebastian,
On Tue, Dec 6, 2016 at 12:03 PM, Sebastian Frias <sf84@...oste.net> wrote:
> On 06/12/16 11:42, Geert Uytterhoeven wrote:
>> On Tue, Dec 6, 2016 at 11:31 AM, Sebastian Frias <sf84@...oste.net> wrote:
>>> On 05/12/16 18:48, Geert Uytterhoeven wrote:
>>>> On Mon, Dec 5, 2016 at 2:36 PM, Sebastian Frias <sf84@...oste.net> wrote:
>>>>> Introduce SETBITFIELD(msb, lsb, value) macro to ease dealing with
>>>>> continuous bitfields, just as BIT(x) does for single bits.
>>>>
>>>> If it's a bitfield, why not calling it that way?
>>>
>>> I don't know if you saw v2 (or v3 for that matter), but the name was changed
>>> to GENVALUE.
>>
>> ... which means "generate a value"??
>>
>
> Yes.
> Although I'm not sure if I understood the essence of your point.
> Are you suggesting that the name should be GENERATE_A_VALUE?
No. I mean that "value" is a way too generic name.
Hence "GENVALUE" may be suitable for a macro local to a driver, but is way
too generic and fuzzy for a global function.
> There's already GENMASK, which "generates a mask".
Yes. And it generates a (bit)mask, which is clear from its name.
But a "value" is just too generic for a global function, and make me think of
a pseudo-random number generator ;-)
>>> Also a small use case was added to the commit message:
>>>
>>> "Introduce GENVALUE(msb, lsb, value) macro..."
>>> "...This is useful mostly for creating values to be packed together
>>> via OR operations, ex:
>>>
>>> u32 val = 0x11110000;
>>> val |= GENVALUE(19, 12, 0x5a);
>>
>> "val |= 0x5a << 12;" looks much more readable to me...
>>
>
> Well, the idea behind this is that one can use it like:
>
> (see https://marc.info/?l=linux-kernel&m=148095872915717&w=2)
>
> ...
> #define TIMEOUT_CLK_UNIT_MHZ BIT(6)
> #define BUS_CLK_FREQ_FOR_SD_CLK(x) GENVALUE(14,7,x)
> ...
> val = 0;
> val |= TIMEOUT_CLK_UNIT_MHZ; /* unit: MHz */
> val |= BUS_CLK_FREQ_FOR_SD_CLK(200); /* SDIO clock: 200MHz */
> ...
>
> which makes it very practical for writing macros for associated HW
> documentation.
Actually I more like the SETBITFIELD name...
>>> now 'val = 0x1115a000'"
>>>
>>>> So what about BITFIELD(start ,size), like arch/tile/kernel/tile-desc_32.c has?
>>>>
>>>>> SETBITFIELD_ULL(msb, lsb, value) macro is also added.
>>>>
>>>> Confused by the need for a "value" parameter...
>>>
>>> "value" is the value to be massaged (shifted, masked) into a [msb:lsb] bitfield.
>>
>> OK. So it inserts a value into a bitfield.
>>
>> Yes, that can be useful. Now let's find a sensible name for this.
>> Perhaps inspired by a PowerPC mnemonic? At least that would be more
>> obvious than "GENVALUE", IMHO...
>
> I'm open to suggestions.
BITFIELD_INSERT()?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-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
Powered by blists - more mailing lists