lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87fum0m928.fsf@purkki.adurom.net>
Date:   Wed, 07 Dec 2016 10:34:39 +0200
From:   Kalle Valo <kvalo@...eaurora.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,
        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>,
        Jakub Kicinski <jakub.kicinski@...ronome.com>
Subject: Re: [PATCH] bitops: add equivalent of BIT(x) for bitfields

Sebastian Frias <sf84@...oste.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@...oste.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ