In case anyone possibly cares, the correct code is this (lots of parens
for clarity)
/* remember that len is our unnormalized return value */
#define SHIFTDIST (((sizeof int) * 8 ) - 1) /* 31 on i386 */
return ((len >> SHIFTDIST) - ((-len) >> SHIFTDIST))
Hideously ugly. Depends on twos-compliment arithmatic and a sign-extending
right-shift. But hey, it's a zero-compare normalize ;-) In assembly, it's
even rather efficient:
# Normalize eax using ebx as a scratch register
movl %eax,%ebx
negl %ebx # b = -a
sarl $31,%eax # a >>= 31
sarl $31,%ebx # b >>= 31
subl %ebx,%eax # a -= b
> But, again, it shouldn't be neccesary to normalize the result anyway so it's
> a moot point.
...so I'll shut up now. Hope someone enjoyed this edition of stupid
bitfield tricks.
-Mitch
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html