Page 2 of 2
Re: strcmp() and drivers
Posted: Tue Jun 30, 2009 10:35 am
by piranha
Solar: I have to say, that is disturbingly elegant. And it is tested OK, I was bored.
-JL
Re: strcmp() and drivers
Posted: Tue Jun 30, 2009 11:54 am
by NickJohnson
I think I have a better way, that only requires one possible branch - it may be a bit faster (but it's untested):
Code: Select all
int strcmp(const char *s1, const char *s2)
{
while (~((*s1)^(*s2))&((*s1)&(*s2)))
{
++s1;
++s2;
}
return (*s1 - *s2);
}
It should be equivalent to ( !((s1*) != (*s2)) && (*s1) ), but more bit-twiddling-y. It only works to use ~ instead of ! because you only check common bits between *s1 and *s2, which is what makes it only one branch. I have no idea if four logical instructions and one branch is faster than two branches though.
Re: strcmp() and drivers
Posted: Tue Jun 30, 2009 4:13 pm
by AUsername
Edit:
It works!
Turns out we didn't have /ALIGN:512. D:
But it works!