Re: Fast computation of parity

From: Mok-Kong Shen (mok-kong.shen_at_t-online.de)
Date: 12/31/03


Date: Wed, 31 Dec 2003 13:13:58 +0100


Mok-Kong Shen wrote:
>
> Alexis Machado wrote:
> >
> > "Mok-Kong Shen" <mok-kong.shen@t-online.de> wrote:
........
> >
> > An alternative :
> >
> > MOV EAX, w
> > MOV EBX, EAX
> > BSWAP EAX
> > XOR EAX, EBX
> > XOR AL, AH
> > SETPO AL /* AL=1 if parity is odd, AL=0 otherwise */
> > AND EAX, 1 /* return EAX ... */
>
> I tried it with VC++. It's slower. (BTW, I don't
> yet know how to run under gcc a group of asm statements
> (grouped by {} and with labels within it as is my code
> above) and should appreciate help.)

I just found with VC++ that a combination of your
first part with my last part of asm seems to be the best:

/* Returns 0 if even parity, else 1 */
/* Ignore compiler warning */
int Parityasm(unsigned int w)
{
__asm
{
  mov eax,w
  mov ebx,eax
  bswap eax
  xor eax,ebx
  xor al,ah
  jp pr
  mov eax,1
  jmp ee
pr:
  mov eax,0
ee:
}
}

M. K. Shen



Relevant Pages

  • Re: Fastcode Int64Div B&V 3.0
    ... fild qword ptr [eax] ... fild qword ptr [edx] ... xor eax, eax ... mov, ...
    (borland.public.delphi.language.basm)
  • Re: howto: MOV EAX, <64bit value> ?
    ... mov eax,valuelow32 ... xor eax,valuehigh32 ... Now eax contains both the low and high 32 bit halves. ... I am not aware of a nice quick algorithm that will compress and store ...
    (comp.lang.asm.x86)
  • Re: Fast computation of parity
    ... >> int Parityasm ... >> mov ebx,eax ... >> xor eax,ebx ... > MOV EBX, EAX ...
    (sci.crypt)
  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)