<> <> <> <> <<>> DIRECTORY BigCardinals, FS, IO, Random, Rope; <> <> <> Mult: CEDAR PROGRAM IMPORTS BigCardinals, FS, IO, Random, Rope EXPORTS = BEGIN <> <> InitializeFile: PROC [vStream: IO.STREAM] ~ { IO.PutF[vStream, "0 0 0 60 1f | xxxxxxxx\n"]; IO.PutF[vStream, "0 0 0 60 1f | xxxxxxxx\n\n"]; }; WriteVector: PROC [vStream: IO.STREAM, d1, d2: CARD, command: NAT] ~ { <> <> resultRope, upperResultRope, lowerResultRope: Rope.ROPE; bigResult: BigCardinals.BigCARD; bigD1, bigD2: BigCardinals.BigCARD; bigD1 _ BigCardinals.BigFromCard[d1]; bigD2 _ BigCardinals.BigFromCard[d2]; bigResult _ BigCardinals.BigMultiply[bigD1, bigD2]; resultRope _ BigCardinals.BigToHexRope[bigResult]; upperResultRope _ IF (Rope.Length[resultRope] > 8) THEN Rope.Substr[resultRope, 0, (Rope.Length[resultRope] - 8)] ELSE "0"; lowerResultRope _ IF (Rope.Length[resultRope] < 9) THEN resultRope ELSE Rope.Substr[resultRope, (Rope.Length[resultRope] - 8), 8]; SELECT command FROM 0 => { -- signed lower mpy <<[resultH, resultL] _ TamarinBlocks.Multiplier[CardToWord[d1], CardToWord[d2]];>> IO.PutF[vStream, "%x %x 0 60 1f | xxxxxxxx\n", IO.card[d1], IO.card[d2]]; FOR i: NAT IN [0..8) DO IO.PutF[vStream, "0 0 1 00 7f | xxxxxxxx\n"]; ENDLOOP; IO.PutF[vStream, "0 0 0 70 0f | "]; IO.PutF[vStream, lowerResultRope]; IO.PutF[vStream, "\n\n"]; }; 1 => { -- Upper signed mpy <<[resultH, resultL] _ TamarinBlocks.Multiplier[CardToWord[d1], CardToWord[d2]];>> IO.PutF[vStream, "%x %x 0 62 1c | xxxxxxxx\n", IO.card[d1], IO.card[d2]]; FOR i: NAT IN [0..8) DO IO.PutF[vStream, "0 0 2 00 7f | xxxxxxxx\n"]; ENDLOOP; IO.PutF[vStream, "0 0 1 00 7f | xxxxxxxx\n"]; IO.PutF[vStream, "0 0 0 70 0f | "]; IO.PutF[vStream, upperResultRope]; IO.PutF[vStream, "\n\n"]; }; <<2 => {>> <<[resultH, resultL] _ TamarinBlocks.Multiplier[CardToWord[d1], CardToWord[d2]];>> <> <> <> <> <> <> < 7fffffffh) THEN upperResult _ upperResult + d2; -- adjust for unsigned >> <> <<};>> ENDCASE => { -- do Lower as default NULL; <<[resultH, resultL] _ TamarinBlocks.Multiplier[CardToWord[d1], CardToWord[d2]];>> <> <> <> <> <> }; }; OpenVectorFile: PROC [fileName: Rope.ROPE] RETURNS [vs: IO.STREAM]~ { RETURN [FS.StreamOpen[fileName, $create]]; }; CloseVectorFile: PROC [vs: IO.STREAM] ~ { IO.PutF[vs, ".\n\n"]; -- Put the end of simulation token IO.Close[vs]; }; GenerateVector: PROC [rs: Random.RandomStream] RETURNS [d1, d2: CARD, mode: NAT] ~ { number: INT; signD1, signD2: BOOL; intd1, intd2: INT; number _ Random.ChooseInt[rs, 0, LAST[INT] - 1]; signD1 _ (number MOD 2) = 0; number _ Random.ChooseInt[rs, 0, LAST[INT] - 1]; intd1 _ IF signD1 THEN number ELSE -number; d1 _ LOOPHOLE[intd1, CARD]; number _ Random.ChooseInt[rs, 0, LAST[INT] - 1]; signD2 _ (number MOD 2) = 0; number _ Random.ChooseInt[rs, 0, LAST[INT] - 1]; intd2 _ IF signD2 THEN number ELSE -number; d2 _ LOOPHOLE[intd2, CARD]; mode _ Random.ChooseInt[rs, 0, LAST[INT] - 1] MOD 2; RETURN [d1, d2, mode]; }; vectorFile: Rope.ROPE _ "BigMpyTestVecs.tioga"; vectorStream: IO.STREAM _ NIL; randomStream: Random.RandomStream; randSeed: NAT; numVectors: NAT; mode: NAT; d1, d2: CARD; randSeed _ 0; numVectors _ 1000; vectorStream _ OpenVectorFile[vectorFile]; randomStream _ Random.Create[LAST[INT], randSeed]; InitializeFile[vectorStream]; FOR i: NAT IN [1..numVectors] DO [d1, d2, mode] _ GenerateVector[randomStream]; <> WriteVector[vectorStream, d1, d2, mode]; ENDLOOP; CloseVectorFile[vectorStream]; END.