RFC: MI strlen()

Xin LI delphij at delphij.net
Thu Jan 8 20:26:43 PST 2009

Hash: SHA1

Hi, Sean,

Sean C. Farley wrote:
> On Thu, 8 Jan 2009, Xin LI 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?
> I only glanced over it, but I like the idea about having it.
> I see that you investigated this before[1]?  Amusingly, I did something

Yes, but nothing gets committed :-/  I think I had lost that work due to
a hard disk failure.

> similar two years later[2] with a C version of strlen()[3].  :)
> Out of curiosity, is an assert (i.e., CTASSERT) better than an #error?

Hmm...  I did not thought about it, but looking at your code, it seems
that using #error makes it more obvious.

I have put the revised version at:


For those who wants to see the file instead of the diff:


- --
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