Date: Mon, 14 Jul 1997 11:36:40 +0000 From: Bill Currie Subject: Re: odd or even # of 1's (was: no subject) To: Nate Eldredge , djgpp AT delorie DOT com, chirayu AT poboxes DOT com, kuku AT gilberto DOT physik DOT rwth-aachen DOT de Reply-to: billc AT blackmagic DOT tait DOT co DOT nz Message-id: <33CA0F48.2BBA@blackmagic.tait.co.nz> Organization: Tait Electronics NZ MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit References: <199707120535 DOT WAA15640 AT adit DOT ap DOT net> <33C9EBB4 DOT 35D3 AT blackmagic DOT tait DOT co DOT nz> Precedence: bulk Bill Currie wrote: > > Nate Eldredge wrote: > > So the parity flag only shows the parity of the low byte. It would be > > theoretically possible to check each byte of the int with this scheme and > > then combine your results, but it would doubtless be ugly and probably > > slower than the shift method. > > Bummer! Just verified it too. Okay, here's a new one (tested and it works): ----------------------------- int has_odd(unsigned long value) { char result; unsigned long junk; asm( "orl %k1,%k1\n" "setpe %b0\n" "shrl $8,%k1\n" "setpe %b1\n" "xorb %b1,%b0\n" "shrl $8,%k1\n" "setpe %b1\n" "xorb %b1,%b0\n" "shrl $8,%k1\n" "setpe %b1\n" "xorb %b1,%b0\n" :"=&q"(result), "=g"(junk) :"1"(value) ); return result; } int main() { int i; for (i=0; i<123456; i++) { printf("%d - %s\n",i,has_odd(i)?"odd":"even"); } return 0; } -------------------------------------------- Bill -- Leave others their otherness.