mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@codeaurora.org>
To: Sebastian Frias <sf84@laposte.net>
Cc: zijun_hu <zijun_hu@htc.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Mason <slash.tmp@free.fr>,
	Harvey Harrison <harvey.harrison@gmail.com>,
	Borislav Petkov <bp@alien8.de>,
	Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: Re: [PATCH v3] add equivalent of BIT(x) for bitfields
Date: Wed, 07 Dec 2016 10:42:48 +0200	[thread overview]
Message-ID: <87bmwom8on.fsf@purkki.adurom.net> (raw)
In-Reply-To: <daba3c13-0344-7bca-aa05-91ec9c7946ae@laposte.net> (Sebastian Frias's message of "Tue, 6 Dec 2016 11:06:42 +0100")

Sebastian Frias <sf84@laposte.net> writes:

> Introduce GENVALUE(msb, lsb, value) macro to ease dealing with
> continuous bitfields, just as BIT(x) does for single bits.
>
> GENVALUE_ULL(msb, lsb, value) macro is also added.
>
> This is useful mostly for creating values to be packed together
> via OR operations, ex:
>
>    u32 val = 0x11110000;
>    val |= GENVALUE(19, 12, 0x5a);
>
> now 'val = 0x1115a000'
>
>
> Signed-off-by: Sebastian Frias <sf84@laposte.net>
> Link: https://marc.info/?l=linux-kernel&m=148094498711000&w=2
> ---
>
> Change in v2:
> - rename the macro to GENVALUE as proposed by Linus
> - longer comment attempts to show use case for the macro as
> proposed by Borislav
>
> Change in v3:
> - use BUILD_BUG_ON_ZERO() to break if some input parameters
> (essentially 'lsb' but also 'msb') are not constants as
> proposed by Linus.
> Indeed, 'lsb' is used twice so it cannot have side-effects;
> 'msb' is subjected to same constraints for consistency.

(I missed there was v3 already, but I'll repeat what I said in v1.)

Please check FIELD_PREP() from include/linux/bitfield.h, doesn't it
already do the same?

Adding Jakub to comment more.

-- 
Kalle Valo

  reply	other threads:[~2016-12-07  8:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 10:06 Sebastian Frias
2016-12-07  8:42 ` Kalle Valo [this message]
2016-12-07 10:00   ` Sebastian Frias
2016-12-07 11:05     ` Jakub Kicinski
2016-12-07 11:23       ` Sebastian Frias
2016-12-07 12:38         ` Jakub Kicinski
2016-12-07 13:51           ` Sebastian Frias
2016-12-07 14:02             ` Jakub Kicinski
2016-12-07 14:34               ` Sebastian Frias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bmwom8on.fsf@purkki.adurom.net \
    --to=kvalo@codeaurora.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=harvey.harrison@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sf84@laposte.net \
    --cc=slash.tmp@free.fr \
    --cc=torvalds@linux-foundation.org \
    --cc=zijun_hu@htc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®