Re: faster strcpy()

Anthony Barbachan (barbacha@trill.cis.fordham.edu)
Sat, 25 Apr 1998 21:32:01 -0400


-----Original Message-----
From: Riley Williams <rhw@bigfoot.com>
To: Chris Wedgwood <chris@cybernet.co.nz>
Cc: Linux Kernel <linux-kernel@vger.rutgers.edu>
Date: Friday, April 24, 1998 6:53 AM
Subject: Re: faster strcpy()

>Hi Chris.
>
> > As to why the above is faster in userland, that seems really odd. I
> > would assume the libc string copy to be something like:
>
> > char *strcpy(char *a,char*b)
> > {
> > char c = b;
> > while(*a++ = *b++);
> > return c;
> > }
>
>That would return the wrong value, but replace the "char c=b" with
>"char c=a" and you have the standard implementation.
>

That would still be wrong. c is a char not a char*

> > Which I can't see how it could be slower than what you are using...
>
>Perhaps GCC isn't optimising it correctly? If my memory of 86
>assembler is correct, it should turn into something like this:
>
> Q> ; strcpy: Takes two parameters, being the target and source
> Q> ; addresses of the strings concerned, and copies all
> Q> ; bytes from the source to the target until a zero
> Q> ; byte has been copied. Assumes a 4-byte return address.
> Q> __strcpy:
> Q> push bp
> Q> push cx
> Q> mov bp,sp
> Q> mov di,[bp+6]
> Q> mov si,[bp+8]
> Q> mov cx,-1
> Q> xor ax,ax
> Q> repne movsb
> Q> mov ax,[bp+6]
> Q> pop cx
> Q> pop bp
> Q> retf
>
>Obviously, I've used 16-bit registers in the above, and I'm also
>writing from memory, not from any reference books, but it shouldn't be
>far out...
>
>Best wishes from Riley.
>
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.rutgers.edu
>

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