GenMulDivFPTest.mesa
Copyright c 1984 by Xerox Corporation. All rights reserved.
Last edited by Curry, August 26, 1984 11:52:32 am PDT
To create quad file:
quad -chx GenMulDivFPTest.quad ← GenBasics GenMulDivFPTest
DIRECTORY
Basics,
IO,
DragOpsCross,
DragOpsCrossUtils,
HandCoding,
HandCodingSupport,
HandCodingPseudos;
GenMulDivFPTest: CEDAR PROGRAM
IMPORTS Basics, DragOpsCrossUtils, HandCoding, HandCodingPseudos, IO
= BEGIN OPEN
DOC: DragOpsCross,
DOCU: DragOpsCrossUtils,
HC: HandCoding,
HCP: HandCodingPseudos;
Floating point function codes
fpModeNibble0: HC.Lit8 = 300B;
fpModeNibble1: HC.Lit8 = 320B;
fpU32ToD32Ex: HC.Lit8 = 64 + 48;
fpU64ToD64Ex: HC.Lit8 = 64 + 49;
fpD32ToW32:  HC.Lit8 = 64 + 50;
ffppD64ToW64: HC.Lit8 = 64 + 51;
fpU32ToD32:  HC.Lit8 = 64 + 52;
fpU64ToD64:  HC.Lit8 = 64 + 53;
fpF32ToI32:  HC.Lit8 = 64 + 56;
fpF64ToI32:  HC.Lit8 = 64 + 57;
fpI32ToF32:  HC.Lit8 = 64 + 58;
fpI32ToF64:  HC.Lit8 = 64 + 59;
fpF32ToF64:  HC.Lit8 = 64 + 60;
fpF64ToF32:  HC.Lit8 = 64 + 61;
fpSubF32:  HC.Lit8 = 64 + 0;
fpSubF64:  HC.Lit8 = 64 + 1;
fpAbsSubF32: HC.Lit8 = 64 + 2;
fpAbsSubF64: HC.Lit8 = 64 + 3;
fpNegF32:  HC.Lit8 = 64 + 8;
fpNegF64:  HC.Lit8 = 64 + 9;
fpNegAbsF32: HC.Lit8 = 64 + 12;
fpNegAbsF64: HC.Lit8 = 64 + 13;
fpAddF32:  HC.Lit8 = 64 + 16;
fpAddF64:  HC.Lit8 = 64 + 17;
fpAbsAddF32: HC.Lit8 = 64 + 18;
fpAbsAddF64: HC.Lit8 = 64 + 19;
fpAddAbsF32: HC.Lit8 = 64 + 20;
fpAddAbsF64: HC.Lit8 = 64 + 21;
fpPassF32:  HC.Lit8 = 64 + 24;
fpPassF64:  HC.Lit8 = 64 + 25;
fpPassAbsF32: HC.Lit8 = 64 + 28;
fpPassAbsF64: HC.Lit8 = 64 + 29;
fpCompF32:  HC.Lit8 = 64 + 32;
fpCompF64:  HC.Lit8 = 64 + 33;
fpCompNegF32: HC.Lit8 = 64 + 34;
fpCompNegF64: HC.Lit8 = 64 + 35;
fpCompAbsF32: HC.Lit8 = 64 + 36;
fpCompAbsF64: HC.Lit8 = 64 + 37;
fpCompF32Zero: HC.Lit8 = 64 + 40;
fpCompF64Zero: HC.Lit8 = 64 + 41;
fpMultF32:  HC.Lit8 ← FPMulCode[double: FALSE];
fpMultF64:  HC.Lit8 ← FPMulCode[double: TRUE];
FPMulCode: PROC[
double:  BOOLFALSE,
bMagnitude: BOOLFALSE,
aMagnitude: BOOLFALSE,
bWrapped: BOOLFALSE,
aWrapped: BOOLFALSE,
comp:   BOOLFALSE ]
RETURNS[lit: HC.Lit8] = {
lit ← 128;
IF comp   THEN lit ← lit + 32;
IF aWrapped  THEN lit ← lit + 16;
IF bWrapped  THEN lit ← lit + 8;
IF aMagnitude THEN lit ← lit + 4;
IF bMagnitude THEN lit ← lit + 2;
IF double   THEN lit ← lit + 1 };
LdCard: PROC[val: DOCU.CARD] = {HC.drLIQB[DOCU.CardToWord [val]]};
CkCard: PROC[val: DOCU.CARD] = {LdCard[val]; Check[]};
Check: PROC = {
checkLabel: HCP.Label = HCP.GenLabel[];
labelRope: IO.ROPEIO.PutFR["MulDivFPTest.Check%03g", IO.card[checkIndex]];
HC.drRJEBJ[popLeft: FALSE, right: HC.popSrc, dist: HCP.UseLabel8[checkLabel]];
HCP.Halt[checkIndex];
HCP.SetLabel[checkLabel];
HCP.MakeLabelGlobal[labelRope, checkLabel];
checkIndex ← checkIndex + 1 };
CkDiv: PROC[divisor, quotient, remainder: DOCU.CARD] = {
dividendHi, dividendLo, delta: DOCU.CARD;
[dividendHi, dividendLo] ← MulCard [divisor, quotient];
delta ← 37777777777B-dividendLo;
IF delta < remainder
THEN {dividendLo ← remainder-delta-1; dividendHi𡤍ividendHi+1}
ELSE {dividendLo ← remainder+dividendLo};
LdCard[dividendHi];
LdCard[dividendLo];
LdCard[divisor];
HC.drUDIV[];
CkCard[remainder];  HC.drDIS[];
CkCard[quotient];  HC.drDIS[] };
CkMul: PROC[type: {unsigned, signed}, v1, v2: DOCU.CARD] = {
m, l: DOCU.CARD;
[m, l] ← MulInt[v1, v2];
LdCard[v1];
LdCard[v2];
HC.drSMUL[];
CkCard[l]; HC.drDIS[];  -- Check LSW
CkCard[m]; HC.drDIS[] }; -- Check MSW
MulCard: PROC[v1, v2: DOCU.CARD] RETURNS[m, l: DOCU.CARD] = {
a, b, lsw, Ab, aB, msw, acc: Basics.LongNumber;
a.lc   ← v1;
b.lc   ← v2;
lsw.lc   ← Basics.LongMult[a.lowbits, b.lowbits];
Ab.lc   ← Basics.LongMult[a.highbits, b.lowbits];
aB.lc   ← Basics.LongMult[a.lowbits, b.highbits];
msw.lc  ← Basics.LongMult[a.highbits, b.highbits];
acc.lc   ← LONG[Ab.lowbits] +LONG[aB.lowbits] +LONG[lsw.highbits];
lsw.highbits ← acc.lowbits;
msw.lc  ← msw.lc +LONG[Ab.highbits] +LONG[aB.highbits] +LONG[acc.highbits];
RETURN[msw.lc, lsw.lc] };
MulInt: PROC[v1, v2: DOCU.CARD] RETURNS[m, l: DOCU.CARD] = {
negResult: BOOL;
a, b: Basics.LongNumber;
a.lc ← v1;
b.lc ← v2;
negResult ← (a.li < 0) # (b.li < 0);
IF a.lc IN (20000000000B..37777777777B] THEN a.li ← -a.li;
IF b.lc IN (20000000000B..37777777777B] THEN b.li ← -b.li;
[a.lc, b.lc] ← MulCard[a.lc, b.lc];
IF negResult THEN {
IF a.lc # 20000000000B THEN a.li ← -a.li;
IF b.lc # 20000000000B THEN b.li ← -b.li;
a.li ← a.li -(IF b.lc=0 THEN 0 ELSE 1) };
RETURN[a.lc, b.lc] };
Abs: PROC[int: DOCU.CARD] RETURNS[abs: DOCU.CARD] = {
a: Basics.LongNumber; a.lc ← int;
IF int IN (20000000000B..37777777777B] THEN a.li ← -a.li;
RETURN[a.lc] };
checkIndex: CARDINAL ← 0;
All: PROC = {
startLabel: HCP.Label = HCP.GenLabelHere[];
endLabel:  HCP.Label = HCP.GenLabel[];
card: ARRAY [0..10) OF DOCU.CARD = [
0B, 1B, 1415926535, 7777777776B, 17777777777B,
20000000000B, 20000000001B, 3141592653, 37777777776B, 37777777777B ];
Initialize FP
HC.drFP[fpModeNibble0]; -- C0
HC.drFP[fpModeNibble1]; -- D0
HC.drLC6[];      -- -1
HC.drSHL[DragOpsCrossUtils.FieldDescriptorToCard[[insert: FALSE, mask: 32, shift: 16]]];
HCP.StoreProcessorReg[ifuFPMaskFlags];
CkDiv[12431251407B, 20000000000B, 27320163115B];
CkDiv[1415926535,  2147483648,  3141592653];
CkDiv[20000000001B, 37777777776B, 0];
CkDiv[20000000001B, 37777777776B, 0];
CkDiv[20000000001B, 37777777776B, 1];
CkDiv[20000000001B, 37777777776B, 2];
CkDiv[20000000001B, 37777777776B, 0];
CkDiv[20000000001B, 37777777776B, 37777777776B];
FOR d: CARDINAL IN [1..10) DO
FOR q: CARDINAL IN [0..10) DO
FOR r: CARDINAL IN [0..10) DO
divisor, quotient, remainder: Basics.LongNumber;
divisor.lc  ← card[d];
quotient.lc ← card[q];
remainder.lc ← card[r];
IF remainder.lc < divisor.lc THEN
CkDiv[card[d], card[q], card[r]];
IF Abs[remainder.lc] >= Abs[divisor.lc] THEN LOOP;
IF (divisor.li<0) = (remainder.li<0)
THEN CkDiv[card[d], card[q], card[r]];
IF ((divisor.li<0) # (quotient.li<0)) = (remainder.li<0)
THEN CkDiv[card[d], card[q], card[r]];
ENDLOOP
ENDLOOP;
ENDLOOP;
LdCard[123];    -- 7B
HC.drFP[fpI32ToF32]; -- 42F60000 40005B/173000B
LdCard[321];    -- 141
HC.drFP[fpI32ToF32]; -- 43A08000 40007B/120200B
HC.drFP[fpAddF32]; -- 43DE0000 40007B/157000B
HC.drFP[fpF32ToI32];
CkCard[123+321];
LdCard[123];    -- 7B
HC.drFP[fpI32ToF32]; -- 42F60000 40005B/173000B
LdCard[321];    -- 141
HC.drFP[fpI32ToF32]; -- 43A08000 40007B/120200B
HC.drFP[fpMultF32]; -- 43DE0000 40007B/157000B
HC.drFP[fpF32ToI32];
CkCard[123*321];
FOR i: CARDINAL IN [0..8) DO
FOR j: CARDINAL IN [0..8) DO
CkUMul [card[i], card[j]];
CkMul [card[i], card[j]]
ENDLOOP
ENDLOOP;
LdCard[963];
HC.drDIV[];
HC.drDIS[];
LdCard[123];
HC.drFP[fpI32ToF32];
LdCard[321];
HC.drFP[fpI32ToF32];
HC.drFP[fpSubF32];
HC.drFP[fpNegF32];
HC.drFP[fpF32ToI32];
LdCard[123];
HC.drFP[fpI32ToF32];
LdCard[321];
HC.drFP[fpI32ToF32];
HC.drFP[fpSubF32];
HC.drFP[fpF32ToI32];
LdCard[41];
HC.drFP[fpI32ToF32];
LdCard[963];
HC.drFP[fpI32ToF32];
HC.drFP[fpMultF32];
HC.drFP[fpF32ToI32];
LdCard[41];
HC.drFP[fpI32ToF64];
LdCard[963];
HC.drFP[fpI32ToF64];
HC.drFP[fpMultF64];
HC.drFP[fpF64ToI32];
LdCard[prod];
HC.drFP[fpI32ToF32];
HC.drFP[fpCompF32];
LdCard[41];
HC.drFP[fpI32ToF64];
LdCard[963];
HC.drFP[fpI32ToF64];
HC.drFP[fpMultF64];
LdCard[prod];
HC.drFP[fpI32ToF64];
HC.drFP[fpCompF64];
LdCard[41];
HC.drFP[fpI32ToF64];
HC.drFP[fpF64ToF32];
HC.drFP[fpF32ToF64];
HC.drFP[fpF64ToI32];
LdCard[M41];
HC.drFP[fpI32ToF64];
HC.drFP[fpF64ToF32];
HC.drFP[fpF32ToF64];
HC.drFP[fpF64ToI32];
HCP.LoadProcessorReg[ifuFPModeAlu];
HCP.LoadProcessorReg[ifuFPModeMult];
HCP.LoadProcessorReg[ifuFPMaskFlags];
HCP.SetLabel[endLabel];
HCP.MakeLabelGlobal["MulDivFPTest.End", endLabel];
HCP.Halt[255];
};
END.