Re: Fast computation of parity

From: Alexis Machado (alexis.machado_at_task.com.br)
Date: 12/31/03


Date: Tue, 30 Dec 2003 22:15:58 -0200


"Mok-Kong Shen" <mok-kong.shen@t-online.de> escreveu na mensagem
news:3FF2064E.C352FF6B@t-online.de...
>
> /* returns 0 if even parity, else 1 */
> int Parityasm(unsigned int w)
> { int p;
>
> __asm
> {
> mov eax,w
> mov ebx,eax
> shr ebx,16
> xor eax,ebx
> mov ebx,eax
> shr ebx,8
> xor eax,ebx
> jp pr
> mov p,1
> jmp ee
> pr:
> mov p,0
> ee:
>
> }
>
> return p;
> }

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 ... */

---
Alexis


Relevant Pages