TamarinOpsUtils.mesa
Copyright Ó 1984, 1985, 1986, 1987 by Xerox Corporation. All rights reserved.
Borrowed from DragonOpsCrossUtils by
Russ Atkinson (RRA) September 11, 1986 1:39:24 pm PDT
Mark Ross January 28, 1987 2:52:57 pm PST
Last Edited by: Ross February 13, 1987 4:10:41 pm PST
Tamarin unit conversions
BytesToWord:
PROC [fb: FourBytes]
RETURNS [Word] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[fb, Word]];
};
BytesToHalf:
PROC [tb: TwoBytes]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[tb, Half]];
};
WordToBytes:
PROC [w: Word]
RETURNS [FourBytes] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, FourBytes]];
};
HalfToBytes:
PROC [h: Half]
RETURNS [TwoBytes] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[h, TwoBytes]];
};
HalvesToWord:
PROC [th: TwoHalves]
RETURNS [Word] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[th, Word]];
};
WordToHalves:
PROC [w: Word]
RETURNS [TwoHalves] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, TwoHalves]];
};
HighHalf:
PROC [w: Word]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, TwoHalves][0]];
};
LowHalf:
PROC [w: Word]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, TwoHalves][1]];
};
LeftHalf:
PROC [w: Word]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, TwoHalves][0]];
};
RightHalf:
PROC [w: Word]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN[LOOPHOLE[w, TwoHalves][1]];
};
SwapHalves:
PROC [w: Word]
RETURNS [Word] =
TRUSTED
MACHINE
CODE {
PrincOps.zEXCH;
};
TamarinOps/PrincOps conversions
Note: the Tamarin convention is to have the low order half word (16 bits) in the right half of the word (32 bits), while the Dorado convention is to have the low order word (16 bits) in the left half of the doubleword (32 bits).
WordToInt:
PROC [w: Word]
RETURNS [
INT] =
TRUSTED
MACHINE
CODE {
PrincOps.zEXCH;
};
IntToWord:
PROC [int:
INT]
RETURNS [Word] =
TRUSTED
MACHINE
CODE {
PrincOps.zEXCH;
};
WordToCard:
PROC [w: Word]
RETURNS [
CARD] =
TRUSTED
MACHINE
CODE {
PrincOps.zEXCH;
};
HalfToCard:
PROC [h: Half]
RETURNS [
CARDINAL] =
TRUSTED
INLINE {
RETURN [LOOPHOLE[h, CARDINAL]];
};
ByteToCard:
PROC [b: Byte]
RETURNS [[0..255]] =
TRUSTED
INLINE {
RETURN [LOOPHOLE[b]];
};
CardToWord:
PROC [card:
CARD]
RETURNS [Word] =
TRUSTED
MACHINE
CODE {
PrincOps.zEXCH;
};
CardToHalf:
PROC [card:
CARDINAL]
RETURNS [Half] =
TRUSTED
INLINE {
RETURN [LOOPHOLE[card, Half]];
};
CardToByte:
PROC [card: [0..255]]
RETURNS [Byte] =
TRUSTED
INLINE {
RETURN [LOOPHOLE[card, Byte]];
};
Word basic operations
TamAnd:
PROC [a,b: Word]
RETURNS [Word] =
INLINE {
This procedure is a 32-bit AND
RETURN [HalvesToWord[[
HalfAnd[LeftHalf[a], LeftHalf[b]],
HalfAnd[RightHalf[a], RightHalf[b]]
]]];
};
TamOr:
PROC [a,b: Word]
RETURNS [Word] =
INLINE {
This procedure is a 32-bit OR
RETURN [HalvesToWord[[
HalfOr[LeftHalf[a], LeftHalf[b]],
HalfOr[RightHalf[a], RightHalf[b]]
]]];
};
TamXor:
PROC [a,b: Word]
RETURNS [Word] =
INLINE {
This procedure is a 32-bit XOR
RETURN [HalvesToWord[[
HalfXor[LeftHalf[a], LeftHalf[b]],
HalfXor[RightHalf[a], RightHalf[b]]
]]];
};
TamNot:
PROC [w: Word]
RETURNS [Word] =
INLINE {
This procedure is a 32-bit XOR
RETURN [HalvesToWord[[
HalfNot[LeftHalf[w]],
HalfNot[RightHalf[w]]
]]];
};
VanillaAdd:
PROC [a,b: Word]
RETURNS [Word] =
INLINE {
This procedure is just a convenience to add without carry or overflow.
RETURN [IntToWord[WordToInt[a]+WordToInt[b]]];
};
VanillaSub:
PROC [a,b: Word]
RETURNS [Word] =
INLINE {
This procedure is just a convenience to subtract without carry or overflow.
RETURN [IntToWord[WordToInt[a]-WordToInt[b]]];
};
AddDelta:
PROC [delta:
INT, w: Word]
RETURNS [Word] =
TRUSTED MACHINE
CODE {
This procedure is a convenience to use when adding a small delta to a word. It is faster than using VanillaAdd directly.
PrincOps.zEXCH;
PrincOps.zDADD;
PrincOps.zEXCH;
};
Halfword basic operations
HalfNot:
PROC [h: Half]
RETURNS [nh: Half] =
TRUSTED MACHINE
CODE {
This procedure is just a convenience to invert a half word.
PrincOps.zLIN1;
PrincOps.zXOR
};
HalfAnd:
PROC [h0,h1: Half]
RETURNS [h: Half] =
TRUSTED MACHINE
CODE {
This procedure is just a convenience to AND two half words.
PrincOps.zAND;
};
HalfOr:
PROC [h0,h1: Half]
RETURNS [h: Half] =
TRUSTED MACHINE
CODE {
This procedure is just a convenience to OR two half words.
PrincOps.zOR;
};
HalfXor:
PROC [h0,h1: Half]
RETURNS [h: Half] =
TRUSTED MACHINE
CODE {
This procedure is just a convenience to OR two half words.
PrincOps.zXOR;
};
HalfShift:
PROC [h: Half, dist:
INTEGER]
RETURNS [Half] =
TRUSTED MACHINE
CODE {
This procedure is just a half word shift left (if dist >= 0) or right (if dist <= 0).
PrincOps.zSHIFT;
};
Shift utility inlines
DoubleWordShiftRight:
PROC [bot, top: Word, dist: SixBitIndex]
RETURNS [Word] = TRUSTED INLINE {
This procedure shifts two Tamarin words right by dist bits and returns the rightmost word.
bot is the ms word of the two word quantity (top is the ls word).
SELECT dist
FROM
< 16 =>
RETURN [HalvesToWord[[
HalfOr[HalfShift[LeftHalf[top], -dist], HalfShift[RightHalf[bot], 16-dist]],
HalfOr[HalfShift[RightHalf[top], -dist], HalfShift[LeftHalf[top], 16-dist]]]]];
ENDCASE => {
RETURN [HalvesToWord[[
HalfOr[HalfShift[RightHalf[bot], 16-dist], HalfShift[LeftHalf[bot], 32-dist]],
HalfOr[HalfShift[LeftHalf[top], 16-dist], HalfShift[RightHalf[bot], 32-dist]]]]];
};
};
DoubleWordShiftLeft:
PROC
[w0,w1: Word, dist: SixBitIndex]
RETURNS [Word] =
TRUSTED
INLINE {
This procedure shifts two Tamarin words left by dist bits and returns the leftmost word.
SELECT dist
FROM
< 16 =>
RETURN [HalvesToWord[[
HalfOr[HalfShift[LeftHalf[w0], dist], HalfShift[RightHalf[w0], dist-16]],
HalfOr[HalfShift[RightHalf[w0], dist], HalfShift[LeftHalf[w1], dist-16]]]]];
ENDCASE => {
RETURN [HalvesToWord[[
HalfOr[HalfShift[RightHalf[w0], dist-16], HalfShift[LeftHalf[w1], dist-32]],
HalfOr[HalfShift[LeftHalf[w1], dist-16], HalfShift[RightHalf[w1], dist-32]]]]];
};
};
SingleWordShiftLeft:
PROC
[word: Word, dist: SixBitIndex]
RETURNS [Word] =
TRUSTED
INLINE {
This procedure shifts one Tamarin word left by dist bits and returns the shifted word.
SELECT dist
FROM
< 16 =>
RETURN [HalvesToWord[[
HalfOr[HalfShift[LeftHalf[word], dist], HalfShift[RightHalf[word], dist-16]],
HalfShift[RightHalf[word], dist]]]];
ENDCASE => {
RETURN [HalvesToWord[[HalfShift[RightHalf[word], dist-16], ZerosHalf]]];
};
};
SingleWordShiftRight:
PROC
[word: Word, dist: SixBitIndex]
RETURNS [Word] =
TRUSTED
INLINE {
This procedure shifts one Tamarin word right by dist bits and returns the shifted word.
SELECT dist
FROM
< 16 =>
RETURN [HalvesToWord[[
HalfShift[LeftHalf[word], -dist],
HalfOr[HalfShift[LeftHalf[word], 16-dist], HalfShift[RightHalf[word], -dist]]
]]];
ENDCASE => {
RETURN [HalvesToWord[[ZerosHalf, HalfShift[LeftHalf[word], 16-dist]]]];
};
};