[comp.lang.c] block copy & VAX MOVC

chris@mimsy.UUCP (Chris Torek) (09/07/88)

In article <5654@june.cs.washington.edu> pardo@june.cs.washington.edu
(David Keppel) writes:
>I believe that the VAX "movc" command takes arbitrary pointers and
>does the following:
>
>* If both are word-aligned, do a word copy (I mean a 4-byte word).
>* If both are non-aligned and could be aligned with 1, 2, or 3 bytes
>  of byte-copy at either end, then do a byte copy at either end and do
>  a word copy down the middle.
>* If niether aligned then ??
>
>Unfortunately, my VAX hardware reference is out of town for a couple
>of weeks, so I can't ask him about neither aligned.  Anybody know?

I do not *know*, but I predict that the answer is machine-dependent:
that BI machines use octaword transfers, while SBI machines use
quadword transfers and CMI machines use longword transfers.  I believe
that at least the 780 and faster VAXen have an alignment network, and
that the microcode can use this directly, so that even if the two
addresses cannot become simultaneously aligned, the copy can proceed as
if they were, with intermediate 64-bit results accumulated in a series
of latches behind the alignment network.

Incidentally, the microcode has a harder job than simply aligning:
The formats of the two instructions are

	movc3	count.rw,src.ab,dst.ab
and
	movc5	srclen.rw,src.ab,fill.rb,dstlen.rw,dst.ab

(r = read-reference, a = address-reference; b = byte, w = word; these
tell how the argument is used and what increments and shifts are
applied to postincrement, predecrement, and indexed addressing modes).
In both cases, if the source and destination overlap, the copy is done
in whichever direction is nondestructive.  Alas, since the count
(movc3) and length (movc5) fields are only read as words, one
instruction can move at most 65535 bytes.  To make these work as a
general copy routine one must surround these with loops which also must
determine the appropriate direction; moreover, since the results are
left in specific registers (r0..r5) the loops must be carefully written
so as to hold the source and destination fields in the appropriate
result-registers to avoid unnecessary moves.

(Fortunately, a C compiler has the sizes of structures available
directly, and can generate the proper series of movc3 instructions for
a structure assignment, but in fact the 4BSD PCC cheats and assumes
that no structure contains more than 65535 bytes.  You get a compiler
error if you try to assign one larger than this.  Well, at least it
does not generate bad code....)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris