Re: faster strcpy()

Richard B. Johnson (root@chaos.analogic.com)
Sun, 26 Apr 1998 19:47:55 -0400 (EDT)


On 26 Apr 1998, Michael O'Reilly wrote:
[SNIPPED]
>
> > Simple string copy guaranteed to work (not very efficient).
> >
> > mov esi,offset source ; 4 clocks
> > mov edi,offset destination ; 4 clocks
> > cpy: lodsb ; 6 clocks
> > stosb ; 6 clocks
> > or al,al ; 2 clocks
> > jnz cpy ; 2 to many clocks, depends upon
> > ; the cache.
>
> So this one is ~ 16 * num_of_bytes + const
>
> > Simple strlen, guaranteed to work (not the most efficient).
> >
> > mov esi,offset source ; 4 clocks
> > mov edx,esi ; 2 clocks
> > xor al,al ; 2 clocks
> > len: lodsb ; 6 clocks
> > or al,al ; 2 clocks
> > jnz len ; 2 to many clocks.
> > mov eax,esi ; 2 clocks
> > sub eax,edx ; 2 clocks
> > ; Length in eax
>
> This is 10 * num_of_bytes + const
>
> > Simple memcpy, guaranteed to work (not the most efficient)
> >
> > mov esi,offset source ; 4 clocks
> > mov edi,offset destination ; 4 clocks
> > mov ecx,dword ptr [count] ; 6 clocks
> > shr ecx,1 ; 2 clocks
> > rep movsw ; 6 * number of words
> > adc ecx,ecx ; 2 clocks
> > rep movsb ; 6 * number of bytes
>
>
> This is ~ 1.5 * num_of_bytes + const
>

Bull this is 6 times the number of words as stated, not 1.5 times
anything.

> So this strlen + move is ~11.5 * num_of_bytes whereas the strcopy is
> ~16 * num_of_bytes

Wrong.

>
> Hmmm. I can certainly say I wouldn't hire you on this showing. Making
> such elementry errors is a little odd.
You wouldn't get a chance.

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.92 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu