Re: Fast computation of parity
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 12/30/03
- Next message: mike3: "Re: Supercomputing and DES key cracking"
- Previous message: Mok-Kong Shen: "Re: Math question [polynomial division]"
- In reply to: Mok-Kong Shen: "Re: Fast computation of parity"
- Next in thread: Alexis Machado: "Re: Fast computation of parity"
- Reply: Alexis Machado: "Re: Fast computation of parity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 30 Dec 2003 16:03:46 -0500 (EST)
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
> > }
>
> I attempted to use the above. However, the compiler
> complained that there is no return value. Could you fix
> that (since I know too little about asm)?
One simple solution would be to add the lines
__asm mov value, eax
return value;
at the end of the function; but there's probably a compiler-
specific solution involving attributes, pragma, or whatever
ScottD's compiler uses. If you can get the compiler to stop
complaining, it *will* work -- so if it's just giving you
a warning, instead of an error, you should be able to ignore
it.
> (BTW, after
> an operation, the parity of the least significant
> byte is given in a parity flag, as far as I know.
> Could one make use of that, or have you already used
> that in the above?) Thanks.
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.)
HTH,
-Arthur
- Next message: mike3: "Re: Supercomputing and DES key cracking"
- Previous message: Mok-Kong Shen: "Re: Math question [polynomial division]"
- In reply to: Mok-Kong Shen: "Re: Fast computation of parity"
- Next in thread: Alexis Machado: "Re: Fast computation of parity"
- Reply: Alexis Machado: "Re: Fast computation of parity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|