Solar: I have to say, that is disturbingly elegant. And it is tested OK, I was bored.
-JL
strcmp() and drivers
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Re: strcmp() and drivers
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: strcmp() and drivers
I think I have a better way, that only requires one possible branch - it may be a bit faster (but it's untested):
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.
Code: Select all
int strcmp(const char *s1, const char *s2)
{
while (~((*s1)^(*s2))&((*s1)&(*s2)))
{
++s1;
++s2;
}
return (*s1 - *s2);
}
Re: strcmp() and drivers
Edit:
It works!
Turns out we didn't have /ALIGN:512. D:
But it works!
It works!
Turns out we didn't have /ALIGN:512. D:
But it works!