Article View: net.lang.c
Article #9420Fast strcpy nitpicking
From: John Gilmore
Date: Mon, 29 Sep 1986 05:20
Date: Mon, 29 Sep 1986 05:20
23 lines
1653 bytes
1653 bytes
In article <7503@sun.uucp>, guy@sun.uucp (Guy Harris) writes:
> The following, courtesy of John Gilmore and Vaughan Pratt, is what is
> actually used in the (3.2 version of) "strcpy", etc.:
>
> moveq #-1,d1 | maximum possible (16-bit) count
> hardloop:
> movb FROM@+,TO@+ | copy...
> dbeq d1,hardloop | until we copy a null or the count is -1
> bne hardloop | if not-null, continue copying with count
> | freshly initialized to -1
Gee, Guy, something must have gotten lost in the translation. I never
suggested that you needed a moveq there. It works great no matter what
value happens to be in d1. Unless d1 always has a small value at that point
in the code, you'll hit the end of the string before the dbra expires,
saving an instruction. :-)
PS: My heart really goes out to the poor guy who wrote his own strcpy
and it broke. Gee, he'll have to #define it to the one that came with
the system. Tears are streaming down my face. ;-)
--
John Gilmore {sun,ptsfa,lll-crg,ihnp4}!hoptoad!gnu jgilmore@lll-crg.arpa
May the Source be with you!
Technical Details
Message-ID:
<1149@hoptoad.uucp>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!qantel!ptsfa!hoptoad!gnuReferences:
<101@hcx1.UUCP> <7363@sun.uucp> <696@mips.UUCP> <7447@sun.uucp> <7503@sun.uucp>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!qantel!ptsfa!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: net.lang.c Subject: Fast strcpy nitpicking Message-ID: <1149@hoptoad.uucp> Date: Mon, 29-Sep-86 01:20:54 EDT Article-I.D.: hoptoad.1149 Posted: Mon Sep 29 01:20:54 1986 Date-Received: Tue, 30-Sep-86 13:08:42 EDT References: <101@hcx1.UUCP> <7363@sun.uucp> <696@mips.UUCP> <7447@sun.uucp> <7503@sun.uucp> Organization: Nebula Consultants in San Francisco Lines: 23