Fast strcpy nitpicking

John Gilmore gnu at hoptoad.uucp
Mon Sep 29 15:20:54 AEST 1986


In article <7503 at sun.uucp>, guy at 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 at +,TO at +	| 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 at lll-crg.arpa
		     May the Source be with you!



More information about the Comp.lang.c mailing list