3.5.2 Memory Data Transporter

The CAVA instruction set includes some complex instructions. One of the most complex, but also the most useful, is the memcpy instruction. Besides the obvious usage of copying blocks of memory, it is also used in conjunction with the cache locking instruction to move data in and out of cache under programmer control.

The definition of the memcpy instruction matches the definition of the Unix memcpy() function--the source and destination ranges must not overlap, or else the values in the destination address range are undefined. Also matching the Unix memcpy(), count is interpreted as a 32-bit unsigned int. A count of zero does not copy anything, but it may cause an exception if given invalid virtual addresses.

The memcpy instruction can copy large amounts of data, so it can run for a very long time and incur many page faults. Therefore it is essential that the instruction be interruptable, and continues from where it left off instead of starting from the beginning again. This is quite different from the behavior of usual instructions, which is atomic and functional.

The operands of the memcpy instruction, destination address, source address and count, are fixed to be general-purpose registers $1, $2 and $3, respectively. When memcpy is interrupted, it puts values into these registers such that it knows how to continue when it is re-executed. These values would usually, but not necessarily, be the remaining count and the continuing addresses. To forstall implementation-specific software dependencies, at completion the count register will be set to zero and the source and destination will contain the original addresses plus the original count.

The memcpy instruction is also used to transport data in and out of cache under program control, in conjunction with the cache instruction. The paradigm is to declare several buffer variables in the program and to do all the computing using these buffers. An enclosing loop copies streaming data into and out of the buffer variables in the manner of double-buffering. Prior to usage, the buffer variables are locked in cache using the cache instruction. The memcpy instruction detects if source or destination is locked in cache and becomes nonblocking. Completion interlocking is achieved by stalling any loads from the destination address range or stores to the source address range.

An important point is that memcpy has exactly the same program semantics under all circumstances. Only the execution timing change depending on usage. Besides the obviously good quality of making the program give the same answer each and every time, this allows different implementations to impose different restrictions on which cases are optimized, thus changing the cost-performance tradeoffs. For example, an implementation oriented towards embedded DSP application might only support cache locking and non-blocking memcpy of one page-granularity sized buffer with page-aligned address that fits within one way of the cache. On the other hand, an aggressive general-purpose implementation might make all memcpy nonblocking to accelerate ordinary programs.

A companion instruction memzero sets the destination range to zero. This semantics was chosen, instead of matching the Unix memset() function, because (i) this is by far the most common usage of memset(), and (ii) setting to a pre-defined value allows special implementations (e.g. whole cache lines at a time, or within the memory controller). Like memcpy, an implementation may choose to make memzero nonblocking, but it always has serial program semantics.

Besides the locking function described above, the cache instruction can also perform prefetch and eviction of ranges of addresses. Importantly, the cache instruction is defined to be purely advisory, meaning it never changes the state of serial program view of memory or general-purpose registers. Therefore an implementation can choose to ignore it. In contrast, every implementation must perform both memcpy and memzero, although they need not be any faster than doing a sequence of loads and stores.

Memory Block Operations

Mnemonic Format Unit Semantics Description
memcpy kT mu /*memcpy($1, $2, $3)*/ Memory Copy
memzero kT mu /*bzero($1, $2)*/ Memory Zero


Cache Control

Mnemonic Format Unit Semantics Description
cache kT mu /*whatever*/ Cache control