RFC: MI strlen()

Xin LI delphij at delphij.net
Thu Jan 8 21:01:03 PST 2009

Hash: SHA1

Alfred Perlstein wrote:
> * Xin LI <delphij at delphij.net> [090108 18:27] wrote:
> Hi,
> Here is a new implementation of strlen() which employed the bitmask
> skill in order to achieve better performance on modern hardware.  For
> common case, this would be a 5.2x boost on FreeBSD/amd64.  The code is
> intended for MI use when there is no hand-optimized assembly.
> 	http://people.freebsd.org/~delphij/for_review/strlen.diff
> Note that this version of strlen() has suboptimal performance if there
> are a lot of characters that has their highest bit set (we can change it
> to have uniform performance at the expense of about ~30% performance
> penalty).
> Comments?
>> It's pretty cool, what does valgrind say when you walk past
>> the end of a string, can it figure that out?

I don't have a runnable valgrind at hand so can't say about it :(  This
type of walk past should not cause problem though, as page is always
word aligned and it does not do more speculative read than the old
strlen() implementation (read past a word vs read past a byte against
the page when overrun happen).

- --
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!
Version: GnuPG v2.0.9 (FreeBSD)


More information about the freebsd-arch mailing list