memcpy versus assignment

Chris Torek chris at mimsy.umd.edu
Wed Dec 27 17:13:19 AEST 1989


In article <1657 at uwm.edu> chad at csd4.csd.uwm.edu (D. Chadwick Gibbons) writes:
>On a VAX using gcc, the following code is produced:
>
>; foo = bar;
>	subl3 $76,fp,sp
>	movab -64(fp),r1
>	movab -76(fp),r0
>	movl $12,r2
>	movblk

Your `VAX' GCC is producing Tahoe instructions.  (The Tahoe movblk
instruction corresponds fairly well to movc3 on the VAX.)

As to the original question: if

	#define pointer_t char * /* or void * */
	struct foo src, dst;

	(void) memcpy((pointer_t)&dst, (pointer_t)&src, len);

is faster than

	dst = src;

you have a really stupid compiler, since the assignment could be
treated internally as a call to memcpy.  (In analysing an assignment
statement, compilers could replace the tree

	(assign (name dst) (name src))

with the tree

	(cast void
	      (call (name memcpy)
		    (cast pointer_t (addressof (name dst)))
		    (cast pointer_t (addressof (name src)))
		    (constant (sizeof (structtype foo))))

which is exactly what it would have built for the memcpy line above.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list