From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: your ma Date: Fri, 11 Jul 1997 23:17:36 +0100 Organization: None Distribution: world Message-ID: References: <199707101349 DOT AA237002579 AT typhoon DOT rose DOT hp DOT com> <33C68250 DOT 301AAEDC AT execulink DOT com> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 37 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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.