Mail Archives: djgpp/1997/07/12/20:49:42
Jeff Weeks writes:
>I just stubled upon a funky intruction that might do what you what. I
>couldn't find any use for it myself... but I guess you just did :)
>
>The two instuctions are BSF (bit scan forward) and BSR (bit scan
>reverse). They take two operands and do the following:
There is one big problem with those instructions: they are _slow_. On a
486 they can take from 6 to 42 clocks, depending on how soon a bit is
found. On a Pentium they can range from 7 to 73 clocks, which make them
pretty pointless since you can get similar speeds from a little
shift+test loop.
As I think someone already mentioned, if you are willing to use a bit of
inline asm you can just test the value and then check the parity flag.
For example:
int parity(int val)
{
unsigned char result;
asm (
" orl %1, %1 ; " /* test the input */
" setpb %b0 ; " /* and store the result */
: "=g" (result)
: "r" (val)
: "cc"
);
return result;
}
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.
- Raw text -