Example of optimized strlen
Bonz
bonzini@gnu.org
Wed Feb 28 02:49:00 GMT 2001
I attach a fast strlen that I wrote and a commented version from glibc's
CVS repository. The comments include cycle counts and highlight
three partial register stalls.
Here are the results for a Pentium (counting clocks for the P6 is
difficult, but take into account that up to 12 clocks are lost for the
partial register stalls on the P6 in the finalization, and that *each*
iteration of the inner loop loses 6 clocks because of the other stall).
I'm not considering cache misses nor branch mispredictions.
my strlen glibc strlen
---------------------------------------------------------------------
startup if aligned 2 2
startup if misaligned (worst case) 7 12
---------------------------------------------------------------------
inner loop n 1.25*n
---------------------------------------------------------------------
finalization (worst case) 9 9
---------------------------------------------------------------------
The startup costs are better in my version, as is the inner loop's
timing.
(My strlen has no support for bounded pointers yet).
Paolo
strlen.S
glibc-strlen.S
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-strlen.S
Type: text/x-c
Size: 3230 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20010228/8fe5e104/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strlen.S
Type: text/x-c
Size: 2105 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20010228/8fe5e104/attachment-0001.bin>
More information about the Libc-alpha
mailing list