Re: Fast computation of parity

From: Alexis Machado (alexis_at_brfree.com.br)
Date: 12/30/03


Date: Tue, 30 Dec 2003 19:49:19 -0300


"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> escreveu na mensagem
news:Pine.LNX.4.58-035.0312301559460.3390@unix46.andrew.cmu.edu...
>
> On Tue, 30 Dec 2003, Mok-Kong Shen wrote:
> >
> > ScottD wrote:
> > >
> > > Here is a non-portable solution for x86:
> > >
> > > int parity (long int value)
> > > {
> > > __asm mov eax, value
> > > __asm or eax, eax
> > > __asm setp al
> > > __asm and eax,1
> > > }
> >
[snip]
> He's used that. The 'setp' instruction sets the value
> of 'eax' (the return value) to 1 if the parity flag is set,
> and 0 if it isn't. Then we just return that value. (The
> 'or eax, eax' instruction just evaluates 'eax' and sets
> the flags accordingly.)

I'm not sure, but the parity flag gives only the parity of the
least significant byte of the result ...

---
Alexis