HandTest.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
February 11, 1987 7:51:13 am PST
by Mark Ross
Last Edited by: Ross April 6, 1987 12:29:38 pm PDT
DIRECTORY
Random USING [ChooseInt, Create, RandomStream],
TamarinBlocks,
TamarinOps USING [FourBitIndex, FiveBitIndex, Word],
TamarinOpsUtils;
HandTest:
CEDAR
PROGRAM
IMPORTS Random, TamarinBlocks, TamarinOpsUtils = BEGIN OPEN TamarinOps, TamarinOpsUtils;
IMPORTS TamarinBlocks, TamarinOpsUtils = BEGIN OPEN TamarinOps, TamarinOpsUtils;
Shifter:
PROC [w0, w1:
INT, dist: FiveBitIndex]
RETURNS [result: INT] ~ {
wordResult: TamarinOps.Word;
bot: TamarinOps.Word ← IntToWord[w0];
top: TamarinOps.Word ← IntToWord[w1];
wordResult ← TamarinBlocks.Shifter[top, bot, dist];
RETURN [WordToInt[wordResult]];
};
Adder:
PROC [euOp:
NAT, w0, w1:
INT]
RETURNS [result:
INT, overFlow, carry, gt:
BOOL] ~{
wordResult: TamarinOps.Word;
d1: TamarinOps.Word ← IntToWord[w0];
d2: TamarinOps.Word ← IntToWord[w1];
[wordResult, overFlow, carry, gt] ← TamarinBlocks.Adder[euOp, d1, d2];
RETURN [WordToInt[wordResult], overFlow, carry, gt];
};
Priority:
PROC [w0:
CARD]
RETURNS [priority:
CARD] ~ {
inword: TamarinOps.Word ← CardToWord[w0];
priority ← WordToCard[TamarinBlocks.PriorityEncoder[inword]];
RETURN [priority];
};
LogicalUnit:
PROC [euOp: FourBitIndex, w0, w1:
CARD]
RETURNS [result:
INT] ~ {
wd0: TamarinOps.Word ← CardToWord[w0];
wd1: TamarinOps.Word ← CardToWord[w1];
wordResult: TamarinOps.Word;
wordResult ← TamarinBlocks.LogicalUnit[euOp, wd0, wd1];
RETURN [WordToInt[wordResult]];
};
Multiplier:
PROC [w0, w1:
CARD, sgnd:
BOOL ←
TRUE]
RETURNS [resultH, resultL: CARD] ~ {
wd0: TamarinOps.Word ← CardToWord[w0];
wd1: TamarinOps.Word ← CardToWord[w1];
resL, resH: TamarinOps.Word;
[resH, resL] ← TamarinBlocks.Multiplier[wd0, wd1, sgnd];
RETURN [WordToCard[resH], WordToCard[resL]];
};
CycleStatRec:
TYPE =
RECORD [
min: NAT,
max: NAT,
avg: REAL];
BadNumRec:
TYPE =
RECORD [
d1: INT,
d2: INT];
RandomMult: PROC [numTests, range0, range1: CARD]
RETURNS [stats: CycleStatRec] ~ {
wd0: TamarinOps.Word;
wd1: TamarinOps.Word;
wordResult: TamarinOps.Word;
overFlow: BOOL;
numCycles: NAT ← 0;
int0, int1: INT;
randStream: Random.RandomStream;
stats.min ← 16;
stats.max ← 0;
stats.avg ← 0;
randStream ← Random.Create[];
FOR i: CARD IN [1..numTests] DO
int0 ← Random.ChooseInt[randStream, 0, range0];
int1 ← Random.ChooseInt[randStream, 0, range1];
wd0 ← IntToWord[int0];
wd1 ← IntToWord[int1];
[wordResult, overFlow, numCycles] ← TamarinBlocks.Multiplier[wd0, wd1];
IF numCycles > stats.max THEN stats.max ← numCycles;
IF numCycles < stats.min THEN stats.min ← numCycles;
stats.avg ← stats.avg + (numCycles - stats.avg)/i;
ENDLOOP;
RETURN [stats];
};
END.