lkml.org 
[lkml]   [1998]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: faster strcpy()
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

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.060 / U:0.652 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site