lkml.org 
[lkml]   [2016]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 11/31] Add x86-specific parity functions
On Sun, 27 Mar 2016 14:45:50 +0800
"zhaoxiu.zeng" <zhaoxiu.zeng@gmail.com> wrote:

> From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
>
> Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
> ---
> arch/x86/include/asm/bitops.h | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
> index 7766d1c..d3210c0 100644
> --- a/arch/x86/include/asm/bitops.h
> +++ b/arch/x86/include/asm/bitops.h
> @@ -501,6 +501,18 @@ static __always_inline int fls64(__u64 x)
>
> #include <asm-generic/bitops/const_hweight.h>
>
> +#define __arch_parity32(x) (__arch_hweight32(x) & 1)
> +#define __arch_parity4(x) (__arch_parity32((x) & 0xf))
> +#define __arch_parity8(x) (__arch_parity32((x) & 0xff))
> +#define __arch_parity16(x) (__arch_parity32((x) & 0xffff))
> +#ifdef CONFIG_X86_32
> +#define __arch_parity64(x) (__arch_parity32((unsigned int)((x) >> 32) ^ (unsigned int)(x)))
> +#else
> +#define __arch_parity64(x) (__arch_hweight64(x) & 1)
> +#endif

arch_hweight32() is a subroutine call to a helper on x86 and the rest
appears to make no sense for this CPU. Gcc has its own parity helper and
even if you are not using that the CPU itself has a parity flag for doing
8bit parity so you just use TEST/J[N]P for parity 8 (and the obvious for 4
and 16). For 32bit parity there is __builtin_parity(). For 64bit
__builtin_parityll().

Alan


\
 
 \ /
  Last update: 2016-03-29 14:41    [W:1.895 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site