Re: Fast computation of parity
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 12/30/03
- Next message: David Clinton: "Re: Cipher whitenoise, David Wagner etc."
- Previous message: Michael Wiener: "Re: Delivering on talk"
- In reply to: Alexis Machado: "Re: Fast computation of parity"
- Next in thread: Mok-Kong Shen: "Re: Fast computation of parity"
- Reply: Mok-Kong Shen: "Re: Fast computation of parity"
- Reply: Michael Amling: "Re: Fast computation of parity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 30 Dec 2003 17:44:07 -0500 (EST)
On Tue, 30 Dec 2003, Alexis Machado wrote:
>
> "Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> escreveu...
> > 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
> > > > }
> > 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 ...
A quick test in 'debug' shows that you are right and I am
wrong. So ScottD's function doesn't work after all? Or am I
missing something here?
-a100
0B05:0100 mov ax, 0101
0B05:0103 or ax,ax
0B05:0105
-p
AX=0101 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B05 ES=0B05 SS=0B05 CS=0B05 IP=0103 NV UP EI PL NZ NA PO NC
0B05:0103 09C0 OR AX,AX
-p
AX=0101 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B05 ES=0B05 SS=0B05 CS=0B05 IP=0105 NV UP EI PL NZ NA PO NC
(AX = 0x0101, and the parity flag is 'PO', or 'odd'!)
-Arthur
- Next message: David Clinton: "Re: Cipher whitenoise, David Wagner etc."
- Previous message: Michael Wiener: "Re: Delivering on talk"
- In reply to: Alexis Machado: "Re: Fast computation of parity"
- Next in thread: Mok-Kong Shen: "Re: Fast computation of parity"
- Reply: Mok-Kong Shen: "Re: Fast computation of parity"
- Reply: Michael Amling: "Re: Fast computation of parity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]