String copy idiom.

Martin Minow minow at decvax.UUCP
Wed Mar 13 12:02:19 AEST 1985


On a vax, the fastest string copy is probably the non-obvious

	length = strlen(input);
	strncpy(output, input, length);

(Assuming both routines are expanded in-line so you're not
hit by the subroutine call overhead.)  Note the following
VMS Macro code from a routine in the Decus C library.

	.entry	strcpy,^M<r2,r3,r4,r5>
	movl	8(ap),r2	; source string
	locc	#0,#-1,(r2)	; find null at end of source
	subl2	r2,r1		; length of source
	incl	r1		; plus 1 for the null byte
	movc3	r1, at 8(ap), at 4(ap); copy the string
	movl	4(ap),r0	; r0 -> destination
	.end



More information about the Comp.lang.c mailing list