lkml.org 
[lkml]   [1998]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: faster strcpy()
Date
> > > while(*a++=*b++); perhaps?
> >
> > No, that's how it was before. This copies byte at time and is slow.
> > memcpy is fast. If we could use the same technique as memcpy uses
> > to copy strings and at the same time check the terminating 0...
> > I don't see the answer myself, does anybody see?
>
> I don't know c or i386 assembler, but there are string commands. Would
one of
> them do it? I don't have my assembler book handy. Is there a store and
> continue while zero?

No. There's "rep movsX" (where X is b/w/d) for moving data but that one
requires ecx to be initialized to the number of items to copy and
doesn't care much about what it's copying. A "lodsd" and "stosd"
followed by the test routine someone posted here earlier and a
conditional jump seems like the best solution to me (provided that the
gain of copying dwords make up for the time the test routine takes to
execute compared to a "lodsb","stosb","or al,al", "jnz lop" version).

[some time later]
Copying dwords certainly seem to make up for the overhead time of the
test routine. Even when implementing it with a .com file under dos (16
bit seg and _lots_ of penalties when operating on 32 bit data) it's a
few cycles faster per byte copied than the latter version (copying byte
by byte). In a proper implementation, with 32 bit segment, the
difference should be quite a bit bigger.

I don't guarantee that my implementation is bug-free (nothing is). Feel
free to check it out if you like, I've attached it to this mail. No,
it's not optimized.

--
Mikael



[unhandled content-type:application/octet-stream][unhandled content-type:application/octet-stream][unhandled content-type:application/octet-stream][unhandled content-type:application/octet-stream]
\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.022 / U:0.936 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site