[comp.arch] Copying bytes quickly

pardo@june.cs.washington.edu (David Keppel) (07/16/88)

In article <974@garth.UUCP> walter@garth.UUCP (Walter Bays) writes:
>[ while(--count) *dst++ = *src++; ]
>[ bcopy should use an unrolled loop, word copy if ok alignment ]
>[ assert byte allignment ]

Interestingly, the VAX |movc3| and |movc5| instructions will copy
byte-at-a-time until they get to a longword boundary, then copy 4
bytes at a time until they get to less than 4 bytes from the end of
the copy, then copy byte-at-a-time again.  All done in microcode.

>[ smart compilers inline ]

With GNU CC, you can inline assembly code and NOT have to guess
where the registers are going to wind up.  Thus you can write your
own "smart compiler" for a VAX:

<bcopy.h>:

#ifdef vax
#ifdef __GNUC__
#   define bcopy(dest,src,count) {\
	register void *__m_src = (src), *__m_dest = (dest); \
	register unsigned int __m_count = (count); \
	asm volatile \
	    ("bcopy %0,%l,%2", "g"(__m_count):"g"(__m_dest),"=g"(__m_src)); \
    }
#endif
#endif
	
NOTE: I haven't actually tried this.

	;-D on  ( Cheap hacks for speed )  Pardo