ELSE {
-- Unaligned case.
w: WORD ¬ 0; -- source word, aligned with destination
hi: WORD ¬ 0; -- left unshifted source word
lo: WORD; -- right unshifted source word
lSA: BitOff = LOOPHOLE[srcBit-dstBit, CARDINAL] MOD bpw; -- left shift amount
rSA: BitOff = LOOPHOLE[bpw - lSA, CARDINAL] MOD bpw; -- amount to shift source words right to line them up
nsw: CARD = WordsForBits[srcBit + count];
fetchLeftmost: BOOL ~ srcBit >= dstBit;
fetchRightmost: BOOL ~ IF fetchLeftmost THEN (nsw>ndw) ELSE (nsw>=ndw);
FetchNext:
PROC ~
INLINE {
fetches the next aligned source bits, and bumps source pointer
lo ¬ hi;
TRUSTED {hi ¬ src[0]};
src ¬ src-UNITS[WORD];
w ¬ BITLSHIFT[hi, lSA]+BITRSHIFT[lo, rSA]
};
FetchLast:
PROC ~
INLINE {
fetches the last (leftmost) source bits on a line, avoiding a spurious fetch
lo ¬ hi;
IF fetchLeftmost THEN TRUSTED {hi ¬ src[0]} ELSE hi ¬ 0;
w ¬ BITLSHIFT[hi, lSA]+BITRSHIFT[lo, rSA]
};
src ¬ src + nsw*UNITS[WORD] - UNITS[WORD];
IF fetchRightmost THEN FetchNext[];
SELECT ndw
FROM
1 =>
TRUSTED {
bothMask: WORD ~ BITAND[lMask, rMask];
FetchLast[];
dst[0] ¬ MF[dst[0], w, bothMask];
};
2 =>
TRUSTED {
FetchNext[];
dst[1] ¬ MF[dst[1], w, rMask];
FetchLast[];
dst[0] ¬ MF[dst[0], w, lMask];
};
3 =>
TRUSTED {
FetchNext[];
dst[2] ¬ MF[dst[2], w, rMask];
FetchNext[];
dst[1] ¬ w;
FetchLast[];
dst[0] ¬ MF[dst[0], w, lMask];
};
ENDCASE =>
TRUSTED {
nw: CARD ¬ LOOPHOLE[ndw-2, CARD];
FetchNext[];
dst ¬ dst + ndw*UNITS[WORD] - UNITS[WORD];
dst[0] ¬ MF[dst[0], w, rMask];
WHILE nw >= 2
DO
dst ¬ dst-UNITS[WORD]*2;
FetchNext[];
dst[1] ¬ w;
FetchNext[];
dst[0] ¬ w;
nw ¬ nw - 2;
ENDLOOP;
IF nw # 0
THEN {
dst ¬ dst-UNITS[WORD];
FetchNext[];
dst[0] ¬ w;
};
dst ¬ dst-UNITS[WORD];
FetchLast[];
dst[0] ¬ MF[dst[0], w, lMask];
};
};