Kind of similar to the one I wrote for Haiku: http://cgit.haiku-os.org/haiku/tree/src/system/libroot/posix...
Makes me wonder if having testbyte() inside the loop will be good for branch prediction.
And IIRC repe cmpsb isn't bad for longer strings on new x86. It's the initial setup that adds overhead. Still, you want to make a fast general solution.