Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371135 > unrolled thread

[PATCH V2 01/30] bitops: add parity functions

Started byZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
First post2016-04-05 04:30 +0200
Last post2016-04-06 12:30 +0200
Articles 20 on this page of 59 — 11 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH V2 01/30] bitops: add parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-05 04:30 +0200
    [PATCH V2 02/30] Include generic parity.h in some architectures'  bitops.h Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-05 06:30 +0200
      [PATCH v2 02/30] Include generic parity.h in some architectures' bitops.h zengzhaoxiu@163.com - 2016-04-06 10:50 +0200
    Re: [PATCH V2 01/30] bitops: add parity functions Sam Ravnborg <sam@ravnborg.org> - 2016-04-05 21:10 +0200
      Re: [PATCH V2 01/30] bitops: add parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-06 07:40 +0200
        Re: [PATCH V2 01/30] bitops: add parity functions Sam Ravnborg <sam@ravnborg.org> - 2016-04-06 10:30 +0200
      [PATCH v2 01/30] bitops: add parity functions zengzhaoxiu@163.com - 2016-04-06 10:50 +0200
    [PATCH v2 03/30] Add alpha-specific parity functions zengzhaoxiu@163.com - 2016-04-06 10:50 +0200
    [PATCH v2 05/30] Add ia64-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:00 +0200
    [PATCH v2 07/30] Add powerpc-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:10 +0200
    [PATCH v2 06/30] Add mips-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:10 +0200
      [PATCH v2 06/30] Add mips-specific parity functions zengzhaoxiu@163.com - 2016-04-06 12:30 +0200
    [PATCH v2 04/30] Add blackfin-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:10 +0200
    [PATCH v2 09/30] Add tile-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:10 +0200
      Re: [PATCH v2 09/30] Add tile-specific parity functions Chris Metcalf <cmetcalf@mellanox.com> - 2016-04-06 15:30 +0200
        Re: [PATCH v2 09/30] Add tile-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-07 06:00 +0200
    [PATCH v2 08/30] Add sparc-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:20 +0200
      Re: [PATCH v2 08/30] Add sparc-specific parity functions Sam Ravnborg <sam@ravnborg.org> - 2016-04-06 20:50 +0200
        Re: [PATCH v2 08/30] Add sparc-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-07 06:00 +0200
    [PATCH v2 10/30] Add x86-specific parity functions zengzhaoxiu@163.com - 2016-04-06 11:30 +0200
      Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-06 12:20 +0200
        Re: [PATCH v2 10/30] Add x86-specific parity functions One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-04-06 12:40 +0200
          Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-06 13:00 +0200
            Re: [PATCH v2 10/30] Add x86-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-07 06:00 +0200
              Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-07 11:50 +0200
          Re: [PATCH v2 10/30] Add x86-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-11 04:50 +0200
            Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-15 02:20 +0200
        Re: [PATCH v2 10/30] Add x86-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-07 06:00 +0200
          Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-07 11:50 +0200
      Re: [PATCH v2 10/30] Add x86-specific parity functions Andi Kleen <andi@firstfloor.org> - 2016-04-06 21:50 +0200
        Re: [PATCH v2 10/30] Add x86-specific parity functions Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-07 06:00 +0200
        Re: [PATCH v2 10/30] Add x86-specific parity functions Dmitry Vyukov <dvyukov@google.com> - 2016-04-07 08:40 +0200
          Re: [PATCH v2 10/30] Add x86-specific parity functions Borislav Petkov <bp@suse.de> - 2016-04-07 11:50 +0200
        Re: [PATCH v2 10/30] Add x86-specific parity functions One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2016-04-07 16:20 +0200
    [PATCH v2 11/30] sunrpc: use parity8 zengzhaoxiu@163.com - 2016-04-06 11:40 +0200
    [PATCH v2 12/30] mips: use parity functions in cerr-sb1.c zengzhaoxiu@163.com - 2016-04-06 11:40 +0200
    [PATCH v2 14/30] media: use parity8 in vivid-vbi-gen.c zengzhaoxiu@163.com - 2016-04-06 11:40 +0200
    [PATCH v2 13/30] bch: use parity32 zengzhaoxiu@163.com - 2016-04-06 11:40 +0200
    [PATCH v2 17/30] input: use parity64 in sidewinder zengzhaoxiu@163.com - 2016-04-06 11:50 +0200
    [PATCH v2 16/30] input: use parity32 in grip_mp zengzhaoxiu@163.com - 2016-04-06 11:50 +0200
    [PATCH v2 18/30] input: use parity16 in ams_delta_serio zengzhaoxiu@163.com - 2016-04-06 11:50 +0200
    [PATCH v2 19/30] scsi: use parity32 in isci's phy zengzhaoxiu@163.com - 2016-04-06 11:50 +0200
    [PATCH v2 15/30] media: use parity functions in saa7115 zengzhaoxiu@163.com - 2016-04-06 11:50 +0200
    [PATCH v2 22/30] crypto: use parity functions in qat_hal zengzhaoxiu@163.com - 2016-04-06 12:00 +0200
    [PATCH v2 21/30] mtd: use parity functions in inftlcore zengzhaoxiu@163.com - 2016-04-06 12:00 +0200
    [PATCH v2 20/30] mtd: use parity16 in ssfdc zengzhaoxiu@163.com - 2016-04-06 12:00 +0200
    [PATCH v2 23/30] mtd: use parity16 in sm_ftl zengzhaoxiu@163.com - 2016-04-06 12:10 +0200
    [PATCH v2 26/30] input: use parity8 in sa1111ps2 zengzhaoxiu@163.com - 2016-04-06 12:20 +0200
    [PATCH v2 27/30] iio: use parity32 in adxrs450 zengzhaoxiu@163.com - 2016-04-06 12:20 +0200
      Re: [PATCH v2 27/30] iio: use parity32 in adxrs450 Jonathan Cameron <jic23@kernel.org> - 2016-04-10 16:40 +0200
        Re: [PATCH v2 27/30] iio: use parity32 in adxrs450 Lars-Peter Clausen <lars@metafoo.de> - 2016-04-10 17:10 +0200
          Re: [PATCH v2 27/30] iio: use parity32 in adxrs450 Jonathan Cameron <jic23@kernel.org> - 2016-04-10 17:20 +0200
            Re: [PATCH v2 27/30] iio: use parity32 in adxrs450 Jonathan Cameron <jic23@kernel.org> - 2016-04-10 17:20 +0200
    [PATCH v2 24/30] ethernet: use parity8 in sun/niu.c zengzhaoxiu@163.com - 2016-04-06 12:20 +0200
    [PATCH v2 25/30] input: use parity8 in pcips2 zengzhaoxiu@163.com - 2016-04-06 12:20 +0200
    Re: [PATCH v2 28/30] serial: use parity32 in max3100 Greg KH <gregkh@linuxfoundation.org> - 2016-04-06 12:30 +0200
    [PATCH v2 28/30] serial: use parity32 in max3100 zengzhaoxiu@163.com - 2016-04-06 12:30 +0200
    [PATCH v2 30/30] ethernet: use parity8 in broadcom/tg3.c zengzhaoxiu@163.com - 2016-04-06 12:30 +0200
    [PATCH v2 29/30] input: use parity8 in elantech zengzhaoxiu@163.com - 2016-04-06 12:30 +0200

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#1372364 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-06 12:20 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rkSJ4-2ho-3@gated-at.bofh.it>
In reply to#1372327
On Wed, Apr 06, 2016 at 05:14:45PM +0800, zengzhaoxiu@163.com wrote:
> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> 
> Use alternatives, lifted from arch_hweight
> 
> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> ---
>  arch/x86/include/asm/arch_hweight.h |   5 ++
>  arch/x86/include/asm/arch_parity.h  | 102 ++++++++++++++++++++++++++++++++++++
>  arch/x86/include/asm/bitops.h       |   4 +-
>  arch/x86/lib/Makefile               |   8 +++
>  arch/x86/lib/parity.c               |  32 ++++++++++++
>  5 files changed, 150 insertions(+), 1 deletion(-)
>  create mode 100644 arch/x86/include/asm/arch_parity.h
>  create mode 100644 arch/x86/lib/parity.c

...

> +static __always_inline unsigned int __arch_parity32(unsigned int w)
> +{
> +	unsigned int res;
> +
> +	asm(ALTERNATIVE("call __sw_parity32", POPCNT32 "; and $1, %0", X86_FEATURE_POPCNT)
> +		: "="REG_OUT (res)
> +		: REG_IN (w)
> +		: "cc");

So why all that churn instead of simply doing:

static __always_inline unsigned int __arch_parity32(unsigned int w)
{
	return hweight32(w) & 1;
}

Ditto for the 64-bit version.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1372388 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromOne Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Date2016-04-06 12:40 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rkT2q-2qe-3@gated-at.bofh.it>
In reply to#1372364
On Wed, 6 Apr 2016 12:13:00 +0200
Borislav Petkov <bp@suse.de> wrote:

> On Wed, Apr 06, 2016 at 05:14:45PM +0800, zengzhaoxiu@163.com wrote:
> > From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> > 
> > Use alternatives, lifted from arch_hweight
> > 
> > Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> > ---
> >  arch/x86/include/asm/arch_hweight.h |   5 ++
> >  arch/x86/include/asm/arch_parity.h  | 102 ++++++++++++++++++++++++++++++++++++
> >  arch/x86/include/asm/bitops.h       |   4 +-
> >  arch/x86/lib/Makefile               |   8 +++
> >  arch/x86/lib/parity.c               |  32 ++++++++++++
> >  5 files changed, 150 insertions(+), 1 deletion(-)
> >  create mode 100644 arch/x86/include/asm/arch_parity.h
> >  create mode 100644 arch/x86/lib/parity.c  
> 
> ...
> 
> > +static __always_inline unsigned int __arch_parity32(unsigned int w)
> > +{
> > +	unsigned int res;
> > +
> > +	asm(ALTERNATIVE("call __sw_parity32", POPCNT32 "; and $1, %0", X86_FEATURE_POPCNT)
> > +		: "="REG_OUT (res)
> > +		: REG_IN (w)
> > +		: "cc");  
> 
> So why all that churn instead of simply doing:
> 
> static __always_inline unsigned int __arch_parity32(unsigned int w)
> {
> 	return hweight32(w) & 1;
> }
> 
> Ditto for the 64-bit version.

Even that would still be wrong for the smaller parity values. The CPU
supports 8bit parity directly going back to the 8086 so the
implementation for 8bit and I think 16bit is still wrong.

Alan

[toc] | [prev] | [next] | [standalone]


#1372401 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-06 13:00 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rkTlM-2zs-9@gated-at.bofh.it>
In reply to#1372388
On Wed, Apr 06, 2016 at 11:37:37AM +0100, One Thousand Gnomes wrote:
> Even that would still be wrong for the smaller parity values. The CPU
> supports 8bit parity directly going back to the 8086 so the
> implementation for 8bit and I think 16bit is still wrong.

I was objecting to the unnecessary replication of the hweight/popcnt
glue.

And yes, one could look up the definition of the parity flag on x86 and
then base the implementation of all those smaller ones on that as the
hardware does it for one practically for free there.

:-)

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1373050 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Date2016-04-07 06:00 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rl9gR-6e9-1@gated-at.bofh.it>
In reply to#1372401
在 2016年04月06日 18:53, Borislav Petkov 写道:
> On Wed, Apr 06, 2016 at 11:37:37AM +0100, One Thousand Gnomes wrote:
>> Even that would still be wrong for the smaller parity values. The CPU
>> supports 8bit parity directly going back to the 8086 so the
>> implementation for 8bit and I think 16bit is still wrong.
> I was objecting to the unnecessary replication of the hweight/popcnt
> glue.
>
> And yes, one could look up the definition of the parity flag on x86 and
> then base the implementation of all those smaller ones on that as the
> hardware does it for one practically for free there.
>
> :-)
>

SETcc (SETPO etc.) added since 80386, is this a problem?

[toc] | [prev] | [next] | [standalone]


#1373222 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-07 11:50 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rleJB-1Ne-33@gated-at.bofh.it>
In reply to#1373050
On Thu, Apr 07, 2016 at 11:55:51AM +0800, Zeng Zhaoxiu wrote:
> SETcc (SETPO etc.) added since 80386, is this a problem?

Sounds to me you didn't make the effort to look up the definition of the
Parity Flag...

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1375430 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Date2016-04-11 04:50 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rmA5k-71S-3@gated-at.bofh.it>
In reply to#1372388
在 2016年04月06日 18:37, One Thousand Gnomes 写道:
> Even that would still be wrong for the smaller parity values. The CPU
> supports 8bit parity directly going back to the 8086 so the
> implementation for 8bit and I think 16bit is still wrong.
>
> Alan

I don't know where the errors. X86 is new to me.

The definition of the parity flag on x86 from Wikipedia:

In x86 processors, the parity flag reflects the parity only of the least significant
byte of the result, and is set if the number of set bits of ones is even. According to
80386 Intel manual, the parity flag is changed in the x86 processor family by the
following instructions:
     All arithmetic instructions;
     Compare instruction (equivalent to a subtract instruction without storing the result);
     Logical instructions - XOR, AND, OR;
     the TEST instruction (equivalent to the AND instruction without storing the result).
     the POPF instruction

[toc] | [prev] | [next] | [standalone]


#1379381 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-15 02:20 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rnZEl-2in-5@gated-at.bofh.it>
In reply to#1375430
On Mon, Apr 11, 2016 at 10:43:32AM +0800, Zeng Zhaoxiu wrote:
> I don't know where the errors. X86 is new to me.

Ok, let me try again by pasting here the relevant text from the manual:

"Parity Flag (PF). Bit 2. Hardware sets the parity flag to 1 if there
is an even number of 1 bits in the least-significant byte of the last
result of certain operations. Otherwise (i.e., for an odd number of 1
bits), hardware clears the flag to 0. Software can read the flag to
implement parity checking."

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1373051 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Date2016-04-07 06:00 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rl9gR-6e9-3@gated-at.bofh.it>
In reply to#1372364
在 2016年04月06日 18:13, Borislav Petkov 写道:
> On Wed, Apr 06, 2016 at 05:14:45PM +0800, zengzhaoxiu@163.com wrote:
>> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>>
>> Use alternatives, lifted from arch_hweight
>>
>> Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>> ---
>>   arch/x86/include/asm/arch_hweight.h |   5 ++
>>   arch/x86/include/asm/arch_parity.h  | 102 ++++++++++++++++++++++++++++++++++++
>>   arch/x86/include/asm/bitops.h       |   4 +-
>>   arch/x86/lib/Makefile               |   8 +++
>>   arch/x86/lib/parity.c               |  32 ++++++++++++
>>   5 files changed, 150 insertions(+), 1 deletion(-)
>>   create mode 100644 arch/x86/include/asm/arch_parity.h
>>   create mode 100644 arch/x86/lib/parity.c
> ...
>
>> +static __always_inline unsigned int __arch_parity32(unsigned int w)
>> +{
>> +	unsigned int res;
>> +
>> +	asm(ALTERNATIVE("call __sw_parity32", POPCNT32 "; and $1, %0", X86_FEATURE_POPCNT)
>> +		: "="REG_OUT (res)
>> +		: REG_IN (w)
>> +		: "cc");
> So why all that churn instead of simply doing:
>
> static __always_inline unsigned int __arch_parity32(unsigned int w)
> {
> 	return hweight32(w) & 1;
> }
>
> Ditto for the 64-bit version.
>

__sw_parity32 is faster than __sw_hweight32.
I don't know how many CPUs do not support the popc, if they are outdated,
use __arch_hweight32 is the easiest way.

[toc] | [prev] | [next] | [standalone]


#1373215 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-07 11:50 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rleJA-1Ne-19@gated-at.bofh.it>
In reply to#1373051
On Thu, Apr 07, 2016 at 11:55:22AM +0800, Zeng Zhaoxiu wrote:
> __sw_parity32 is faster than __sw_hweight32.
> I don't know how many CPUs do not support the popc, if they are outdated,
> use __arch_hweight32 is the easiest way.

I don't really understand what you're trying to tell me here. And it's
not like I didn't try.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1372785 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromAndi Kleen <andi@firstfloor.org>
Date2016-04-06 21:50 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rl1CG-rk-21@gated-at.bofh.it>
In reply to#1372327
zengzhaoxiu@163.com writes:

> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>
> Use alternatives, lifted from arch_hweight

Is there actually anything performance critical in the kernel that uses
parity?

FWIW the arch hweight custom calling convention is a problem for LTO
because it needs different special flags, so I usually have to disable
it. Likely other reasonable usages, such as automatic source code
analysis, and other tool chain based usages have similar problems.

As far as I can tell both for hweight and likely for parity it is
badly overengineering and normal calling conventions would work as well,
and cause much less problems.

So if parity is really worth adding here (which I find doubtful,
but you may have numbers), please add it without these magic
calling hacks.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only

[toc] | [prev] | [next] | [standalone]


#1373052 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Date2016-04-07 06:00 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rl9gR-6e9-9@gated-at.bofh.it>
In reply to#1372785
在 2016年04月07日 03:45, Andi Kleen 写道:
> zengzhaoxiu@163.com writes:
>
>> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>>
>> Use alternatives, lifted from arch_hweight
> Is there actually anything performance critical in the kernel that uses
> parity?
>
> FWIW the arch hweight custom calling convention is a problem for LTO
> because it needs different special flags, so I usually have to disable
> it. Likely other reasonable usages, such as automatic source code
> analysis, and other tool chain based usages have similar problems.
>
> As far as I can tell both for hweight and likely for parity it is
> badly overengineering and normal calling conventions would work as well,
> and cause much less problems.
>
> So if parity is really worth adding here (which I find doubtful,
> but you may have numbers), please add it without these magic
> calling hacks.
>
> -Andi
>

Thanks. I will instead use __arch_hweight.

[toc] | [prev] | [next] | [standalone]


#1373106 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromDmitry Vyukov <dvyukov@google.com>
Date2016-04-07 08:40 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rlbLI-8en-3@gated-at.bofh.it>
In reply to#1372785
On Wed, Apr 6, 2016 at 9:45 PM, Andi Kleen <andi@firstfloor.org> wrote:
> zengzhaoxiu@163.com writes:
>
>> From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
>>
>> Use alternatives, lifted from arch_hweight
>
> Is there actually anything performance critical in the kernel that uses
> parity?
>
> FWIW the arch hweight custom calling convention is a problem for LTO
> because it needs different special flags, so I usually have to disable
> it. Likely other reasonable usages, such as automatic source code
> analysis, and other tool chain based usages have similar problems.
>
> As far as I can tell both for hweight and likely for parity it is
> badly overengineering and normal calling conventions would work as well,
> and cause much less problems.
>
> So if parity is really worth adding here (which I find doubtful,
> but you may have numbers), please add it without these magic
> calling hacks.


Hweight custom calling convention caused crashes with KCOV coverage.
We had to disable instrumentation of the file.

[toc] | [prev] | [next] | [standalone]


#1373216 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromBorislav Petkov <bp@suse.de>
Date2016-04-07 11:50 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rleJB-1Ne-21@gated-at.bofh.it>
In reply to#1373106
On Thu, Apr 07, 2016 at 08:31:09AM +0200, Dmitry Vyukov wrote:
> Hweight custom calling convention caused crashes with KCOV coverage.
> We had to disable instrumentation of the file.

I guess we can do something like this:

       if (likely(static_cpu_has(X86_FEATURE_POPCNT)))
               asm volatile(POPCNT32
                            : "="REG_OUT (res)
                            : REG_IN (w));
       else
               res = __sw_hweight32(w);

and get rid of the custom calling convention.

Along with some numbers showing that the change doesn't cause any
noticeable slowdown...

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1373420 — Re: [PATCH v2 10/30] Add x86-specific parity functions

FromOne Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Date2016-04-07 16:20 +0200
SubjectRe: [PATCH v2 10/30] Add x86-specific parity functions
Message-ID<rliWT-568-31@gated-at.bofh.it>
In reply to#1372785
On Wed, 06 Apr 2016 12:45:27 -0700
Andi Kleen <andi@firstfloor.org> wrote:

> zengzhaoxiu@163.com writes:
> 
> > From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
> >
> > Use alternatives, lifted from arch_hweight  
> 
> Is there actually anything performance critical in the kernel that uses
> parity?

On very low end devices some of the flash, but the implementation here is
ironically pretty much worst-case for such x86 devices 8)

Alan

[toc] | [prev] | [next] | [standalone]


#1372331 — [PATCH v2 11/30] sunrpc: use parity8

Fromzengzhaoxiu@163.com
Date2016-04-06 11:40 +0200
Subject[PATCH v2 11/30] sunrpc: use parity8
Message-ID<rkS6m-1Kx-9@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 net/sunrpc/auth_gss/gss_krb5_keys.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/sunrpc/auth_gss/gss_krb5_keys.c b/net/sunrpc/auth_gss/gss_krb5_keys.c
index 8701331..c41b389 100644
--- a/net/sunrpc/auth_gss/gss_krb5_keys.c
+++ b/net/sunrpc/auth_gss/gss_krb5_keys.c
@@ -243,16 +243,12 @@ err_return:
 	return ret;
 }
 
-#define smask(step) ((1<<step)-1)
-#define pstep(x, step) (((x)&smask(step))^(((x)>>step)&smask(step)))
-#define parity_char(x) pstep(pstep(pstep((x), 4), 2), 1)
-
 static void mit_des_fixup_key_parity(u8 key[8])
 {
 	int i;
 	for (i = 0; i < 8; i++) {
 		key[i] &= 0xfe;
-		key[i] |= 1^parity_char(key[i]);
+		key[i] |= !parity8(key[i]);
 	}
 }
 
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1372333 — [PATCH v2 12/30] mips: use parity functions in cerr-sb1.c

Fromzengzhaoxiu@163.com
Date2016-04-06 11:40 +0200
Subject[PATCH v2 12/30] mips: use parity functions in cerr-sb1.c
Message-ID<rkS6m-1Kx-13@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 arch/mips/mm/cerr-sb1.c | 67 +++++++++++++------------------------------------
 1 file changed, 17 insertions(+), 50 deletions(-)

diff --git a/arch/mips/mm/cerr-sb1.c b/arch/mips/mm/cerr-sb1.c
index ee5c1ff..2e7d660 100644
--- a/arch/mips/mm/cerr-sb1.c
+++ b/arch/mips/mm/cerr-sb1.c
@@ -264,27 +264,6 @@ asmlinkage void sb1_cache_error(void)
 #endif
 }
 
-
-/* Parity lookup table. */
-static const uint8_t parity[256] = {
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
-	0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0
-};
-
 /* Masks to select bits for Hamming parity, mask_72_64[i] for bit[i] */
 static const uint64_t mask_72_64[8] = {
 	0x0738C808099264FFULL,
@@ -298,34 +277,28 @@ static const uint64_t mask_72_64[8] = {
 };
 
 /* Calculate the parity on a range of bits */
-static char range_parity(uint64_t dword, int max, int min)
+static inline char range_parity(uint64_t dword, int max, int min)
 {
-	char parity = 0;
-	int i;
-	dword >>= min;
-	for (i=max-min; i>=0; i--) {
-		if (dword & 0x1)
-			parity = !parity;
-		dword >>= 1;
+	int n = max - min + 1;
+	if (__builtin_constant_p(n)) {
+		if (n <= 8)
+			return parity8((unsigned int)(dword >> min) & ((1U << n) - 1));
+		if (n <= 16)
+			return parity16((unsigned int)(dword >> min) & ((1U << n) - 1));
+		if (n <= 32)
+			return parity32((unsigned int)(dword >> min) & ((1U << n) - 1));
 	}
-	return parity;
+	return parity64((dword >> min) & ((1ULL << n) - 1));
 }
 
 /* Calculate the 4-bit even byte-parity for an instruction */
-static unsigned char inst_parity(uint32_t word)
+static inline unsigned char inst_parity(uint32_t word)
 {
-	int i, j;
-	char parity = 0;
-	for (j=0; j<4; j++) {
-		char byte_parity = 0;
-		for (i=0; i<8; i++) {
-			if (word & 0x80000000)
-				byte_parity = !byte_parity;
-			word <<= 1;
-		}
-		parity <<= 1;
-		parity |= byte_parity;
-	}
+	char parity;
+	parity  = parity8(word >> 24) << 3;
+	parity |= parity8(word >> 16) << 2;
+	parity |= parity8(word >> 8) << 1;
+	parity |= parity8(word);
 	return parity;
 }
 
@@ -436,7 +409,6 @@ static uint32_t extract_ic(unsigned short addr, int data)
 static uint8_t dc_ecc(uint64_t dword)
 {
 	uint64_t t;
-	uint32_t w;
 	uint8_t	 p;
 	int	 i;
 
@@ -445,12 +417,7 @@ static uint8_t dc_ecc(uint64_t dword)
 	{
 		p <<= 1;
 		t = dword & mask_72_64[i];
-		w = (uint32_t)(t >> 32);
-		p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
-		      ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
-		w = (uint32_t)(t & 0xFFFFFFFF);
-		p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
-		      ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
+		p |= parity64(t);
 	}
 	return p;
 }
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1372334 — [PATCH v2 14/30] media: use parity8 in vivid-vbi-gen.c

Fromzengzhaoxiu@163.com
Date2016-04-06 11:40 +0200
Subject[PATCH v2 14/30] media: use parity8 in vivid-vbi-gen.c
Message-ID<rkS6m-1Kx-11@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 drivers/media/platform/vivid/vivid-vbi-gen.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/vivid/vivid-vbi-gen.c b/drivers/media/platform/vivid/vivid-vbi-gen.c
index a2159de..d5ba0fc 100644
--- a/drivers/media/platform/vivid/vivid-vbi-gen.c
+++ b/drivers/media/platform/vivid/vivid-vbi-gen.c
@@ -175,14 +175,9 @@ static const u8 vivid_cc_sequence2[30] = {
 	0x14, 0x2f,	/* End of Caption */
 };
 
-static u8 calc_parity(u8 val)
+static inline u8 calc_parity(u8 val)
 {
-	unsigned i;
-	unsigned tot = 0;
-
-	for (i = 0; i < 7; i++)
-		tot += (val & (1 << i)) ? 1 : 0;
-	return val | ((tot & 1) ? 0 : 0x80);
+	return (!parity8(val) << 7) | val;
 }
 
 static void vivid_vbi_gen_set_time_of_day(u8 *packet)
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1372335 — [PATCH v2 13/30] bch: use parity32

Fromzengzhaoxiu@163.com
Date2016-04-06 11:40 +0200
Subject[PATCH v2 13/30] bch: use parity32
Message-ID<rkS6m-1Kx-19@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 lib/bch.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/lib/bch.c b/lib/bch.c
index bc89dfe4..6c6e8d4 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -278,18 +278,6 @@ static inline int deg(unsigned int poly)
 	return fls(poly)-1;
 }
 
-static inline int parity(unsigned int x)
-{
-	/*
-	 * public domain code snippet, lifted from
-	 * http://www-graphics.stanford.edu/~seander/bithacks.html
-	 */
-	x ^= x >> 1;
-	x ^= x >> 2;
-	x = (x & 0x11111111U) * 0x11111111U;
-	return (x >> 28) & 1;
-}
-
 /* Galois field basic operations: multiply, divide, inverse, etc. */
 
 static inline unsigned int gf_mul(struct bch_control *bch, unsigned int a,
@@ -494,7 +482,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows,
 		tmp = 0;
 		for (r = m-1; r >= 0; r--) {
 			mask = rows[r] & (tmp|1);
-			tmp |= parity(mask) << (m-r);
+			tmp |= parity32(mask) << (m-r);
 		}
 		sol[p] = tmp >> 1;
 	}
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1372337 — [PATCH v2 17/30] input: use parity64 in sidewinder

Fromzengzhaoxiu@163.com
Date2016-04-06 11:50 +0200
Subject[PATCH v2 17/30] input: use parity64 in sidewinder
Message-ID<rkSg1-1O6-3@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 drivers/input/joystick/sidewinder.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 4a95b22..7ea486e 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -259,22 +259,6 @@ static void sw_init_digital(struct gameport *gameport)
 }
 
 /*
- * sw_parity() computes parity of __u64
- */
-
-static int sw_parity(__u64 t)
-{
-	int x = t ^ (t >> 32);
-
-	x ^= x >> 16;
-	x ^= x >> 8;
-	x ^= x >> 4;
-	x ^= x >> 2;
-	x ^= x >> 1;
-	return x & 1;
-}
-
-/*
  * sw_ccheck() checks synchronization bits and computes checksum of nibbles.
  */
 
@@ -334,7 +318,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
 			for (i = 0; i < sw->number; i ++) {
 
-				if (sw_parity(GB(i*15,15)))
+				if (parity64(GB(i*15,15)))
 					return -1;
 
 				input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
@@ -351,7 +335,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 		case SW_ID_PP:
 		case SW_ID_FFP:
 
-			if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8)
+			if (!parity64(GB(0,48)) || (hat = GB(42,4)) > 8)
 				return -1;
 
 			dev = sw->dev[0];
@@ -372,7 +356,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
 		case SW_ID_FSP:
 
-			if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8)
+			if (!parity64(GB(0,43)) || (hat = GB(28,4)) > 8)
 				return -1;
 
 			dev = sw->dev[0];
@@ -397,7 +381,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
 		case SW_ID_FFW:
 
-			if (!sw_parity(GB(0,33)))
+			if (!parity64(GB(0,33)))
 				return -1;
 
 			dev = sw->dev[0];
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1372341 — [PATCH v2 16/30] input: use parity32 in grip_mp

Fromzengzhaoxiu@163.com
Date2016-04-06 11:50 +0200
Subject[PATCH v2 16/30] input: use parity32 in grip_mp
Message-ID<rkSg1-1O6-9@gated-at.bofh.it>
In reply to#1371135
From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 drivers/input/joystick/grip_mp.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 573191d..3e29eb1 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -112,20 +112,6 @@ static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5
 static int register_slot(int i, struct grip_mp *grip);
 
 /*
- * Returns whether an odd or even number of bits are on in pkt.
- */
-
-static int bit_parity(u32 pkt)
-{
-	int x = pkt ^ (pkt >> 16);
-	x ^= x >> 8;
-	x ^= x >> 4;
-	x ^= x >> 2;
-	x ^= x >> 1;
-	return x & 1;
-}
-
-/*
  * Poll gameport; return true if all bits set in 'onbits' are on and
  * all bits set in 'offbits' are off.
  */
@@ -235,7 +221,7 @@ static int mp_io(struct gameport* gameport, int sendflags, int sendcode, u32 *pa
 		pkt = (pkt >> 2) | 0xf0000000;
 	}
 
-	if (bit_parity(pkt) == 1)
+	if (parity32(pkt))
 		return IO_RESET;
 
 	/* Acknowledge packet receipt */
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | linux.kernel


csiph-web