DIRECTORY Basics, Dragon, DragOpsCross, DragOpsCrossUtils, EUArith, EUUtils, Rope; EUArithImpl: CEDAR PROGRAM IMPORTS Basics, DragOpsCrossUtils, EUUtils EXPORTS EUArith = BEGIN OPEN EUArith, EUUtils; CToW: PROC [c: CARD] RETURNS [Word] ={ w: Word _ DragOpsCrossUtils.CardToWord[c]; RETURN [w]; -- was DragOpsCrossUtils.SwapHalves[w] (EMM) }; WToC: PROC [w: Word] RETURNS [CARD] ={ RETURN [DragOpsCrossUtils.WordToCard[w]]; }; EBFLC: PUBLIC PROC [c: CARD, index: [0..32)] RETURNS [BOOL] = { w: Word _ DragOpsCrossUtils.CardToWord[c]; RETURN[w[index]]}; EByteFLC: PUBLIC PROC [c: CARD, index: [0..4)] RETURNS[CARDINAL] = { b: Byte _ DragOpsCrossUtils.WordToBytes[CToW[c]][index]; RETURN [DragOpsCrossUtils.ByteToCard[b]]}; mask: ARRAY [0..32] OF CARD = [ 0B, 1B, 3B, 7B, 17B, 37B, 77B, 177B, 377B, 777B, 1777B, 3777B, 7777B, 17777B, 37777B, 77777B, 177777B, 377777B, 777777B, 1777777B, 3777777B, 7777777B, 17777777B, 37777777B, 77777777B, 177777777B, 377777777B, 777777777B, 1777777777B, 3777777777B, 7777777777B, 17777777777B, 37777777777B]; LC: PROC [n: Basics.LongNumber] RETURNS[CARD] ~ {RETURN[n.lc]}; LN: PROC [n: CARD] RETURNS[Basics.LongNumber] ~ {RETURN[[lc[n]]]}; WordNot: PUBLIC PROC [c: CARD] RETURNS [CARD] ~ { RETURN [LC[Basics.DoubleNot[LN[c]]]]}; WordAnd: PUBLIC PROC [a, b: CARD] RETURNS [CARD] ~ { RETURN [LC[Basics.DoubleAnd[LN[a], LN[b]]]]}; WordOr: PUBLIC PROC [a, b: CARD] RETURNS [CARD] ~ { RETURN [LC[Basics.DoubleOr[LN[a], LN[b]]]]}; WordXor: PUBLIC PROC [a, b: CARD] RETURNS [CARD] ~ { RETURN [LC[Basics.DoubleXor[LN[a], LN[b]]]]}; MLCtoLC: PROC [source, destination: CARD, ns, nd, w: CARDINAL] RETURNS [c: CARD] ~ { sWord: Word _ CToW[source]; nWord: Word _ CToW[destination]; IF w=0 THEN RETURN [destination]; FOR i: NAT IN [0..w) DO nWord[nd+i] _ sWord[ns+i]; ENDLOOP; RETURN [WToC[nWord]]; }; LispTest: PUBLIC PROC [c: CARD] RETURNS [bogus: BOOL] ~ { bogus _ HighHalf[c]/8192 IN [1..6]; }; LowHalf: PROC [a: CARD] RETURNS [CARD] ~ {RETURN [a MOD 65536]}; HighHalf: PROC [a: CARD] RETURNS [CARD] ~ {RETURN [a / 65536]}; DoubleADD: PUBLIC PROC [a, b: CARD, carry: BOOL] RETURNS [s: CARD, c32: BOOL] = { ls: CARD _ LowHalf[a]+LowHalf[b]+(IF carry THEN 1 ELSE 0); c: CARD _ HighHalf[ls]; -- half-carry hs: CARD _ HighHalf[a]+HighHalf[b]+c; IF c>1 THEN ERROR; c32 _ HighHalf[hs]>0; s _ 65536*LowHalf[hs]+LowHalf[ls]; }; FieldOp: PUBLIC PROC [left, right, fieldDesc: CARD] RETURNS [result: CARD] = { fd: DragOpsCross.FieldDescriptor _ DragOpsCrossUtils.CardToFieldDescriptor[fieldDesc MOD 65536]; shiftout, mask1, mask2, maskWithHole, background: CARD; mask1 _ mask[fd.mask]; -- fd.mask ones on the low-order side mask2 _ mask[fd.shift]; -- fd.shift ones on the low-order side SELECT fd.shift FROM 0 => shiftout _ left; -- no shift 32 => shiftout _ right; -- full shift ENDCASE => { -- Make shiftout with the 32-fd.shift low bits of aluLeft (high) and the fd.shift high bits of aluRight (low) shiftout _ MLCtoLC[left, shiftout, fd.shift, 0, 32-fd.shift]; shiftout _ MLCtoLC[right, shiftout, 0, 32-fd.shift, fd.shift] }; maskWithHole _ IF fd.insert THEN WordXor[mask1, mask2] ELSE mask1; background _ IF fd.insert THEN right ELSE 0; result _ WordOr[ WordAnd[shiftout, maskWithHole], -- central portion WordAnd[background, WordNot[maskWithHole]] -- both sides ]; }; ApplyAluOp: PUBLIC PROC [op: ALUOpcode, a, b: CARD, carryIn: BOOL] RETURNS [res: CARD, c32: BOOL] ~ { SELECT op FROM add => [res, c32] _ DoubleADD[a, b, carryIn]; and => {res _ WordAnd[a, b]; c32 _ carryIn}; or => {res _ WordOr[a, b]; c32 _ carryIn}; xor => {res _ WordXor[a, b]; c32 _ carryIn}; ENDCASE => ERROR; }; OpToCarryOut: PUBLIC PROC [op: Dragon.ALUOps, computedC, prevC: BOOL] RETURNS [nextC: BOOL] ~ { nextC _ SELECT aluOps[op].cOut FROM prev => prevC, zero => FALSE, comp => computedC, ncomp => ~computedC, ENDCASE => ERROR; }; OpToCarryIn: PUBLIC PROC [op: Dragon.ALUOps, c: BOOL] RETURNS [BOOL] ~ { RETURN [SELECT aluOps[op].cIn FROM zero => FALSE, one => TRUE, prev => c, nprev => ~c, ENDCASE => ERROR] }; ALUOperation: PUBLIC PROC [aluOp: Dragon.ALUOps, a, b: CARD, prevC: BOOL] RETURNS [res: CARD, c32, nextC: BOOL] ~ { carryIn: BOOL _ OpToCarryIn[aluOp, prevC]; IF aluOps[aluOp].invertB THEN b _ WordNot[b]; [res, c32] _ ApplyAluOp[aluOps[aluOp].op, a, b, carryIn]; nextC _ OpToCarryOut[aluOp, c32, prevC]; IF aluOps[aluOp].invertB THEN c32 _ NOT c32; }; ExplodeKReg: PUBLIC PROC [k: CARD] RETURNS [a, b, c: CARD, st3AIsC: BOOL, lSrc, rSrc, stSrc: NAT] ~ { n: CARDINAL; a _ EByteFLC[k, 0]; b _ EByteFLC[k, 1]; c _ EByteFLC[k, 2]; n _ EByteFLC[k, 3]; stSrc _ n MOD 4; n _ n/4; rSrc _ n MOD 8; n _ n/8; lSrc _ n MOD 4; n _ n/4; st3AIsC _ n#0; }; END. ’EUArithImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Louis Monier April 1, 1986 2:00:01 pm PST McCreight, April 1, 1986 11:21:51 am PST Last Edited by: Louis Monier September 13, 1986 11:13:06 pm PDT -- Conversion between CARD and Word must always be done through the following procs w _ DragOpsCrossUtils.SwapHalves[w]; (EMM) -- Field extractions: bit 0 is the high-order bit -- Mask generation: mask[i] has "i" ones in the low-order bits region -- Logical operations: order of bits is irrelevant -- Move bits [ns..ns+w) of source CARD into bits [nd..nd+w) of destination CARD -- Arithmetical operations on signed numbers -- Returns a+b+carry and c32, where a and b are considered to be signed numbers -- Returns a-b-carry and c32, implemented as a+(~b)+1+(~carry) DoubleSUB: PROC [a, b: CARD, carry: BOOL] RETURNS [dif: CARD, c32: BOOL] = { [dif, c32] _ DoubleADD[a, WordNot[b], NOT carry]}; -- This proc mimics the hardware; it is also easier to understand -- Assert[(fd.shift < 33) AND (fd.mask < 33)]; -- Behaviour of pieces -- Mimicks the behaviour of the ALU -- Explodes a 32-bit word in ram addresses and control bits; check format with IFU ΚV– "cedar" style˜codešœ™Kšœ Οmœ1™™>š  œžœžœ žœžœžœžœ™LJšœ&žœ ™2—J™Aš  œž œžœžœ žœ˜NJšœUžœ˜`Jšœ2žœ˜7Jšœžœ™/Jšœ‘%˜šžœ ž˜Jšœ‘ ˜#Jšœ‘ ˜'šžœ‘m˜zJšœ=˜=Jšœ>˜>Jšœ˜——Jšœžœ žœžœ˜BJšœ žœ žœžœ˜,šœ˜Jšœ&‘˜8Jšœ+‘ ˜8Jšœ˜—Jšœ˜——K™™š  œž œžœ žœžœžœžœ˜ešžœž˜Kšœžœ˜-Kšœ žœ˜,Kšœ žœ˜*Kšœ žœ˜,Kšžœžœ˜—K˜—š   œž œ'žœžœ žœ˜_šœž œž˜#Kšœ˜Kšœžœ˜Kšœ˜Kšœ˜Kšžœžœ˜—K˜—š   œžœžœžœžœžœ˜Hšžœžœž˜"Kšœžœ˜Kšœžœ˜ Kšœ ˜ Kšœ ˜ Kšžœžœ˜—K˜—J™—™#š  œž œžœ žœžœžœžœ˜sKšœ žœ˜*Kšžœžœ˜-Kšœ žœ,˜9Kšœ(˜(Kšžœžœžœ˜,K˜——™Rš   œžœžœžœžœ˜+Kšœ žœ žœžœ˜:Jšœžœ˜ Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ žœ ˜Jšœ žœ˜Jšœ žœ˜Jšœ˜K˜——K˜K˜Kšžœ˜K˜—…—bZ