Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1399183
| From | Martin Kepplinger <martink@posteo.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [patch V4 01/31] bitops: add parity functions |
| Date | 2016-05-11 16:40 +0200 |
| Message-ID | <rxDsS-1yk-17@gated-at.bofh.it> (permalink) |
| References | <rxxGP-4ls-49@gated-at.bofh.it> <rxyjx-58a-25@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Am 2016-05-11 um 10:47 schrieb zengzhaoxiu@163.com:
> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>
> Add generic parity functions, adapted from
> "https://graphics.stanford.edu/~seander/bithacks.html#ParityParallel".
>
> The function parityN returns whether an odd or even number of bits are on
> in a N-bit word.
>
> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> ---
This won't be up to me, but I'd appreciate to see all 31 patches
together without having to look for them; I guess I'm not alone.
thanks
martin
> include/asm-generic/bitops.h | 1 +
> include/asm-generic/bitops/arch_parity.h | 39 +++++++++++++++++++++++++++++++
> include/asm-generic/bitops/const_parity.h | 36 ++++++++++++++++++++++++++++
> include/asm-generic/bitops/parity.h | 7 ++++++
> include/asm-generic/bitops/popc-parity.h | 32 +++++++++++++++++++++++++
> include/linux/bitops.h | 10 ++++++++
> 6 files changed, 125 insertions(+)
> create mode 100644 include/asm-generic/bitops/arch_parity.h
> create mode 100644 include/asm-generic/bitops/const_parity.h
> create mode 100644 include/asm-generic/bitops/parity.h
> create mode 100644 include/asm-generic/bitops/popc-parity.h
>
> diff --git a/include/asm-generic/bitops.h b/include/asm-generic/bitops.h
> index dcdcacf..d85722f 100644
> --- a/include/asm-generic/bitops.h
> +++ b/include/asm-generic/bitops.h
> @@ -27,6 +27,7 @@
> #include <asm-generic/bitops/sched.h>
> #include <asm-generic/bitops/ffs.h>
> #include <asm-generic/bitops/hweight.h>
> +#include <asm-generic/bitops/parity.h>
> #include <asm-generic/bitops/lock.h>
>
> #include <asm-generic/bitops/atomic.h>
> diff --git a/include/asm-generic/bitops/arch_parity.h b/include/asm-generic/bitops/arch_parity.h
> new file mode 100644
> index 0000000..813e152
> --- /dev/null
> +++ b/include/asm-generic/bitops/arch_parity.h
> @@ -0,0 +1,39 @@
> +#ifndef _ASM_GENERIC_BITOPS_ARCH_PARITY_H_
> +#define _ASM_GENERIC_BITOPS_ARCH_PARITY_H_
> +
> +#include <asm/types.h>
> +
> +/*
> + * Refrence to 'https://graphics.stanford.edu/~seander/bithacks.html#ParityParallel'.
> + */
> +
> +static inline unsigned int __arch_parity4(unsigned int w)
> +{
> + w &= 0xf;
> + return ((PARITY_MAGIC) >> w) & 1;
> +}
> +
> +static inline unsigned int __arch_parity8(unsigned int w)
> +{
> + w ^= w >> 4;
> + return __arch_parity4(w);
> +}
> +
> +static inline unsigned int __arch_parity16(unsigned int w)
> +{
> + w ^= w >> 8;
> + return __arch_parity8(w);
> +}
> +
> +static inline unsigned int __arch_parity32(unsigned int w)
> +{
> + w ^= w >> 16;
> + return __arch_parity16(w);
> +}
> +
> +static inline unsigned int __arch_parity64(__u64 w)
> +{
> + return __arch_parity32((unsigned int)(w >> 32) ^ (unsigned int)w);
> +}
> +
> +#endif /* _ASM_GENERIC_BITOPS_ARCH_PARITY_H_ */
> diff --git a/include/asm-generic/bitops/const_parity.h b/include/asm-generic/bitops/const_parity.h
> new file mode 100644
> index 0000000..3970546
> --- /dev/null
> +++ b/include/asm-generic/bitops/const_parity.h
> @@ -0,0 +1,36 @@
> +#ifndef _ASM_GENERIC_BITOPS_CONST_PARITY_H_
> +#define _ASM_GENERIC_BITOPS_CONST_PARITY_H_
> +
> +/*
> + * Compile time versions of __arch_parityN()
> + */
> +#define __const_parity4(w) (((PARITY_MAGIC) >> ((w) & 0xf)) & 1)
> +#define __const_parity8(w) (__const_parity4((w) ^ ((w) >> 4)))
> +#define __const_parity16(w) (__const_parity8((w) ^ ((w) >> 8)))
> +#define __const_parity32(w) (__const_parity16((w) ^ ((w) >> 16)))
> +#define __const_parity64(w) (__const_parity32((w) ^ ((w) >> 32)))
> +
> +/*
> + * Generic interface.
> + */
> +#define parity4(w) (__builtin_constant_p(w) ? __const_parity4(w) : __arch_parity4(w))
> +#define parity8(w) (__builtin_constant_p(w) ? __const_parity8(w) : __arch_parity8(w))
> +#define parity16(w) (__builtin_constant_p(w) ? __const_parity16(w) : __arch_parity16(w))
> +#define parity32(w) (__builtin_constant_p(w) ? __const_parity32(w) : __arch_parity32(w))
> +#define parity64(w) (__builtin_constant_p(w) ? __const_parity64(w) : __arch_parity64(w))
> +
> +/*
> + * Interface for known constant arguments
> + */
> +#define PARITY4(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_parity4(w))
> +#define PARITY8(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_parity8(w))
> +#define PARITY16(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_parity16(w))
> +#define PARITY32(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_parity32(w))
> +#define PARITY64(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_parity64(w))
> +
> +/*
> + * Type invariant interface to the compile time constant parity functions.
> + */
> +#define PARITY(w) PARITY64((u64)(w))
> +
> +#endif /* _ASM_GENERIC_BITOPS_CONST_PARITY_H_ */
> diff --git a/include/asm-generic/bitops/parity.h b/include/asm-generic/bitops/parity.h
> new file mode 100644
> index 0000000..a91dce7
> --- /dev/null
> +++ b/include/asm-generic/bitops/parity.h
> @@ -0,0 +1,7 @@
> +#ifndef _ASM_GENERIC_BITOPS_PARITY_H_
> +#define _ASM_GENERIC_BITOPS_PARITY_H_
> +
> +#include <asm-generic/bitops/arch_parity.h>
> +#include <asm-generic/bitops/const_parity.h>
> +
> +#endif /* _ASM_GENERIC_BITOPS_PARITY_H_ */
> diff --git a/include/asm-generic/bitops/popc-parity.h b/include/asm-generic/bitops/popc-parity.h
> new file mode 100644
> index 0000000..bf05999
> --- /dev/null
> +++ b/include/asm-generic/bitops/popc-parity.h
> @@ -0,0 +1,32 @@
> +#ifndef _ASM_GENERIC_BITOPS_POPC_PARITY_H_
> +#define _ASM_GENERIC_BITOPS_POPC_PARITY_H_
> +
> +#include <asm/types.h>
> +
> +static inline unsigned int __arch_parity32(unsigned int w)
> +{
> + return __builtin_popcount(w) & 1;
> +}
> +
> +static inline unsigned int __arch_parity16(unsigned int w)
> +{
> + return __arch_parity32(w & 0xffff);
> +}
> +
> +static inline unsigned int __arch_parity8(unsigned int w)
> +{
> + return __arch_parity32(w & 0xff);
> +}
> +
> +static inline unsigned int __arch_parity4(unsigned int w)
> +{
> + return __arch_parity32(w & 0xf);
> +}
> +
> +static inline unsigned int __arch_parity64(__u64 w)
> +{
> + return (unsigned int)__builtin_popcountll(w) & 1;
> +}
> +
> +#endif
> +
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index defeaac..c3ea19e 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -30,6 +30,11 @@ extern unsigned int __sw_hweight32(unsigned int w);
> extern unsigned long __sw_hweight64(__u64 w);
>
> /*
> + * a miniature 16-bit parity-table of 4-bits number
> + */
> +#define PARITY_MAGIC 0x6996
> +
> +/*
> * Include this here because some architectures need generic_ffs/fls in
> * scope
> */
> @@ -80,6 +85,11 @@ static __always_inline unsigned long hweight_long(unsigned long w)
> return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
> }
>
> +static __always_inline unsigned int parity_long(unsigned long w)
> +{
> + return sizeof(w) == 4 ? parity32(w) : parity64(w);
> +}
> +
> /**
> * rol64 - rotate a 64-bit value left
> * @word: value to rotate
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[patch V4 00/31] bitops: add parity functions zengzhaoxiu@163.com - 2016-05-11 10:30 +0200
[patch V4 01/31] bitops: add parity functions zengzhaoxiu@163.com - 2016-05-11 11:10 +0200
Re: [patch V4 01/31] bitops: add parity functions Martin Kepplinger <martink@posteo.de> - 2016-05-11 16:40 +0200
[patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
Re: [patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h Jesper Nilsson <jesper.nilsson@axis.com> - 2016-05-11 12:10 +0200
Re: [patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h Catalin Marinas <catalin.marinas@arm.com> - 2016-05-11 12:50 +0200
Re: [patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-05-11 16:00 +0200
Re: [patch V4 02/31] bitops: Include generic parity.h in some architectures' bitops.h Mark Salter <msalter@redhat.com> - 2016-05-11 17:30 +0200
[patch V4 09/31] bitops: Add x86-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
Re: [patch V4 09/31] bitops: Add x86-specific parity functions Peter Zijlstra <peterz@infradead.org> - 2016-05-11 11:40 +0200
Re: [patch V4 09/31] bitops: Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-05-11 12:00 +0200
[patch V4 06/31] bitops: Tile and MIPS (if has usable __builtin_popcount) use popcount parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 12/31] lib: bch: use parity32 zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 03/31] bitops: Add alpha-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 05/31] bitops: Add ia-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 11/31] mips: use parity functions in cerr-sb1.c zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 08/31] bitops: Add sparc-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
Re: [patch V4 08/31] bitops: Add sparc-specific parity functions David Miller <davem@davemloft.net> - 2016-05-12 02:00 +0200
[patch V4 10/31] sunrpc: use parity8 zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 07/31] bitops: Add powerpc-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 04/31] bitops: Add blackfin-specific parity functions zengzhaoxiu@163.com - 2016-05-11 11:20 +0200
[patch V4 28/31] input: use parity8 in elantech zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 19/31] mtd: use parity16 in ssfdc zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 23/31] ethernet: use parity8 in sun/niu.c zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
Re: [patch V4 23/31] ethernet: use parity8 in sun/niu.c David Miller <davem@davemloft.net> - 2016-05-12 02:10 +0200
[patch V4 20/31] mtd: use parity functions in inftlcore zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 14/31] media: use parity functions in saa7115 zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 31/31] edac: use parity8 in amd64_edac.c zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 29/31] ethernet: use parity8 in broadcom/tg3.c zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
Re: [patch V4 29/31] ethernet: use parity8 in broadcom/tg3.c David Miller <davem@davemloft.net> - 2016-05-12 02:00 +0200
[patch V4 18/31] scsi: use parity32 in isci's phy zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 21/31] crypto: use parity functions in qat_hal zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 15/31] input: use parity32 in grip_mp zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 30/31] crypto: use parity_long is sahara.c zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 22/31] mtd: use parity16 in sm_ftl zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 25/31] input: use parity8 in sa1111ps2 zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 16/31] input: use parity64 in sidewinder zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 27/31] serial: use parity32 in max3100 zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 24/31] input: use parity8 in pcips2 zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 26/31] iio: use parity32 in adxrs450 zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 17/31] input: use parity16 in ams_delta_serio zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
[patch V4 13/31] media: use parity8 in vivid-vbi-gen.c zengzhaoxiu@163.com - 2016-05-11 11:30 +0200
csiph-web