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>, Sasha Levin <sasha.levin@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Mason <slash.tmp@free.fr>,
	Maxime Coquelin <maxime.coquelin@st.com>,
	Harvey Harrison <harvey.harrison@gmail.com>,
	Borislav Petkov <bp@alien8.de>,
	Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: Re: [PATCH] bitops: add equivalent of BIT(x) for bitfields
Date: Wed, 07 Dec 2016 10:34:39 +0200	[thread overview]
Message-ID: <87fum0m928.fsf@purkki.adurom.net> (raw)
In-Reply-To: <196dd443-e3c7-2c37-1dd1-bc1d249ea2fb@laposte.net> (Sebastian Frias's message of "Mon, 5 Dec 2016 14:36:07 +0100")

Sebastian Frias <sf84@laposte.net> writes:

> Introduce SETBITFIELD(msb, lsb, value) macro to ease dealing with
> continuous bitfields, just as BIT(x) does for single bits.
>
> SETBITFIELD_ULL(msb, lsb, value) macro is also added.
>
> Signed-off-by: Sebastian Frias <sf84@laposte.net>
> ---
>
> Code protected with "#ifdef __KERNEL__" just as the BIT(x)
> macros.
>
> I would have preferred another name, like BITS(x) but it is
> already used.
>
> Suggestions for other names welcome.
> ---
>  include/linux/bitops.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index a83c822..4659237 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -24,6 +24,20 @@
>  #define GENMASK_ULL(h, l) \
>  	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
>  
> +#ifdef	__KERNEL__
> +/*
> + * Equivalent of BIT(x) but for contiguous bitfields
> + * SETBITFIELD(1, 0,0xff) = 0x00000003
> + * SETBITFIELD(3, 0,0xff) = 0x0000000f
> + * SETBITFIELD(15,8,0xff) = 0x0000ff00
> + * SETBITFIELD(6, 6,   1) = 0x00000040 == BIT(6)
> + */
> +#define SETBITFIELD(msb, lsb, val)     \
> +	(((val) << (lsb)) & (GENMASK((msb), (lsb))))
> +#define SETBITFIELD_ULL(msb, lsb, val) \
> +	(((val) << (lsb)) & (GENMASK_ULL((msb), (lsb))))
> +#endif

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

Adding Jakub to comment more.

-- 
Kalle Valo

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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05 13:36 Sebastian Frias
2016-12-05 15:34 ` Borislav Petkov
2016-12-05 17:02   ` Sebastian Frias
2016-12-05 17:13 ` Linus Torvalds
2016-12-05 17:47   ` Sebastian Frias
2016-12-05 17:48 ` Geert Uytterhoeven
2016-12-06 10:31   ` Sebastian Frias
2016-12-06 10:42     ` Geert Uytterhoeven
2016-12-06 11:03       ` Sebastian Frias
2016-12-06 11:12         ` Geert Uytterhoeven
2016-12-06 14:56           ` Sebastian Frias
2016-12-07  8:34 ` Kalle Valo [this message]

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=87fum0m928.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=maxime.coquelin@st.com \
    --cc=sasha.levin@oracle.com \
    --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®