Mail Archives: djgpp/1997/07/13/19:39:20
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.
- Raw text -