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] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 29 Jan 2010 11:32:00 +0100
From:	John Kacur <jkacur@...hat.com>
To:	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc:	eranian@...gle.com, fweisbec@...il.com, paulus@...ba.org,
	mingo@...e.hu, davem@...emloft.net, robert.richter@....com,
	linux-kernel@...r.kernel.org,
	Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH 07/10] bitops: Provide compile time HWEIGHT{8,16,32,64}

On Fri, Jan 22, 2010 at 4:50 PM, Peter Zijlstra <a.p.zijlstra@...llo.nl> wrote:
> Provide compile time versions of hweight.
>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
> LKML-Reference: <new-submission>
> ---
>  include/linux/bitops.h |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> Index: linux-2.6/include/linux/bitops.h
> ===================================================================
> --- linux-2.6.orig/include/linux/bitops.h
> +++ linux-2.6/include/linux/bitops.h
> @@ -45,6 +45,20 @@ static inline unsigned long hweight_long
>        return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
>  }

I like it. Maybe provide a comment that this provides the Hamming weight, it
took me a second to realize what this was.

>
> +#define HWEIGHT8(w)                    \
> +      (        (!!((w) & (1ULL << 0))) +       \
> +       (!!((w) & (1ULL << 1))) +       \
> +       (!!((w) & (1ULL << 2))) +       \
> +       (!!((w) & (1ULL << 3))) +       \
> +       (!!((w) & (1ULL << 4))) +       \
> +       (!!((w) & (1ULL << 5))) +       \
> +       (!!((w) & (1ULL << 6))) +       \
> +       (!!((w) & (1ULL << 7))) )
> +
> +#define HWEIGHT16(w) (HWEIGHT8(w)  + HWEIGHT8(w >> 8))
> +#define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16(w >> 16))
> +#define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32(w >> 32))
> +
>  /**
>  * rol32 - rotate a 32-bit value left
>  * @word: value to rotate
>
> --
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ