4 ms·
Kind of similar to the one I wrote for Haiku: http://cgit.haiku-os.org/haiku/tree/src/system/libroot/posix/string/strlen.cpp http://cgit.haiku-os.org/haiku/tree
by tqh 12y ago
Kind of similar to the one I wrote for Haiku: http://cgit.haiku-os.org/haiku/tree/src/system/libroot/posix/string/strlen.cpp 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.
- halayli 12y agoThe testbyte is only called in the end once a NULL is detected in the word, and will run in parallel.
- tqh 12y agoI was thinking more how branch prediction is handled in the pipeline. Agner Fog states that on Haswell having branches in the same 16 byte block affects performance. Probably not enough to matter though.