Re: 2.1.120pre2: Bug in strnicmp() noted in 2.1.119pre1 is still there!

Mitchell Blank Jr (mitch@execpc.com)
Tue, 1 Sep 1998 19:28:45 -0500


Mitchell Blank Jr wrote:
> > return len<0 ? -1 : len&1;
>
> BTW, this of course won't work at all. There are some cool tricks with
> bitops you can do to remove one of the tests, but this isn't it. It
> was really foolish of me to think I could remember what they were at
> 6:30am. :-(

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