ER[DGALU];	*RANDOM NUMBER TEST OF P, Q, AND ALU

%TO ASSEMBLE:	MICRO/L LANG DGALU -OR- MICRO/L LANG2 DGALU
TO RUN:		MIDAS RDGALU
		START;G
CURRENT SOURCES ON TENEX <ERF> DIRECTORY.
%

SM[SY10,10];
SM[SLC,0]; TARGET[SLC];	*CONSTANTS FOR P-REGISTER MASK SIMULATION
0V;		1V;		3V;		7V;
17V;		37V;		77V;		177V;
377V;		777V;		1777V;		3777V;
7777V;		17777V;		37777V;		77777V;
177777V;	377777V;	777777V;	1 777777V;
3 777777V;	7 777777V;	17 777777V;	37 777777V;
77 777777V;	177 777777V;	377 777777V;	777 777777V;
1777 777777V;	3777 777777V;	7777 777777V;	17777 777777V;
37777 777777V;	77777 777777V;	177777 777777V;	377777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;
777777 777777V;	777777 777777V;	777777 777777V;	777777 777777V;

*ORIGINAL VALUES FOR RANDOM NO. GENERATOR
*MUST BE AT BOUNDARY OF 8
X0:	7654321V;
X1:	76543210V;
X2:	765432100V;
X3:	7654321000V;
X4:	76543210000V;
X5:	765432100000V;
X6:	654321000007V;
X7:	543210000076V;

@X0:	E1[X0];
@X7:	E1[X7];

SVN[YRAN]; SVN[COUNT]; SVN[RANP]; SVN[STEMP]; SVN[SMDATA]; MC[J,J];

RVN[RDATA]; RVN[RTEMP]; LVN[LDATA]; LVN[MDATA];

IM[ILC,20]; TARGET[ILC];

MCYCLE:	BRKP[1], COUNT←Q, GOTO[NXTNUM];
START:	ARM←NULL, INHINT, DGOTO[NXTNUM];
	IRET, INHINT, COUNT←NULL, CALL[INIRAN];

PQCOMP:	P#Q;
	RETURN[ALU=0];
	BRKP[1], RETURN;

RETN:	RETURN;

*INITIALIZE RANDOM NO. GENERATOR
INIRAN:	Y←@X7;
	RANP←Y, RETURN;

*RETURN RANDOM NO. IN Q (USES Y WHICH MUST NOT BE CLOBBERED), CLOBBERS P
RGEN:	Y←P←RANP;
	Q←@X0;
	P-Q-1, P←SY, DECY;
	Q←SY, GOTO[.+2,ALU>=0];
	A0, Y←@X7, GOTO[.-1];
	Q←P+Q, RANP←Y;
	SY←Q, RETURN;

*SAVE RANDOM NO. GENERATOR STATE IN SM FOR RESTORATION LATER
RMARK:	Y←RANP;
	YRAN←Y;			*SAVE POINTER
	P←@X0;
	Y←@X7;
	Q←Y;
	P-Q, Q←SY, DGOTO[.-1];
	SY10←Q, DECY, RETURN[ALU>=0];

*RESTORE RANDOM NO. GENERATOR STATE
RREST:	Y←YRAN;
	RANP←Y;
	P←@X0;
	Y←@X7;
	Q←Y;
	P-Q, Q←SY10, DGOTO[.-1];
	SY←Q, DECY, RETURN[ALU>=0];

*SUBROUTINE USED BY SMASKT AND AMASKT
SAMT:	MDR←P;
	P←SY, Q←RDATA;
	P←MDR, Q←P AND Q, INCY, GOTO[PQCOMP];

*SUBROUTINE USED BY BAMASKT
BAMT:	INCY, Q←P AND Q, P←MDR, GOTO[PQCOMP];

*DIAGNOSTIC STARTS HERE
NXTNUM:	CALL[RGEN];
	LDATA←Q, CALL[RGEN];
	RDATA←Q, CALL[RGEN];
	SMDATA←MDATA←Q;

RBLT:	P←Q←RDATA, CALL[PQCOMP];
	GOTO[.+1];

LBLT:	P←Q←LDATA, CALL[PQCOMP];
	GOTO[.+1];

QLSHT:	Q←RDATA;
	Q LSH 1, DECY, AQ, B←SY;	*DECY, AQ, B←SY FOR NOISE EFFECT
	MDR←Q, P←RDATA, Q←A0;
	PQ LCY [1], Q←MDR, CALL[PQCOMP]; *P/ RDATA LSH 1 VIA PQ LCY [1]
	GOTO[.+1];			*Q/ RDATA LSH 1 VIA Q LSH 1

QRSHT:	Q←RDATA;
	Q RSH 1, DECY, NOT Q, B←SY;
	MDR←Q, P←RDATA, Q←A0;
	PQ RCY [1], Q←MDR, CALL[PQCOMP]; *P/ RDATA RSH 1 VIA PQ RCY [1]
	GOTO[.+1];			*Q/ RDATA RSH 1 VIA Q RSH 1

QRBR1T:	P←(RDATA) RSH [1], Q←(RDATA) RSH 1, CALL[PQCOMP];
	GOTO[.+1];			*P/ RDATA RSH 1 VIA RM RSH 1
					*Q/ RDATA RSH 1 VIA RM RSH 1

SADDT:	P←LDATA, Q←RDATA;
	MDR←P←P+Q;
	P←P-Q, Q←LDATA, CALL[PQCOMP];	*P/ LDATA+RDATA-RDATA
	GOTO[.+1];			*Q/ LDATA

ASUBT:	P←LDATA, Q←RDATA;
	MDR←P←P-Q-1;
	P←P+Q+1, Q←LDATA, CALL[PQCOMP];	*P/ LDATA-RDATA-1+RDATA+1
	GOTO[.+1];			*Q/ LDATA VIA LM

P1TST:	P←LDATA;
	P←P1, Q←P, CALL[PQCOMP];		*P/ LDATA VIA P1
	GOTO[.+1];			*Q/ LDATA VIA ALU
	Q←LDATA, P←P1, CALL[PQCOMP];		*P/ LDATA VIA P1
	GOTO[.+1];			*Q/ LDATA VIA LM

ALUR1T:	P←RDATA, A0, Q←(RDATA) RSH 1;
	P←(P) ARSHC 1, CALL[PQCOMP];		*P/ RDATA RSH 1 VIA ALU RSH 1
	GOTO[.+1];			*Q/ RDATA RSH 1 DIRECT

RBRCT:	Q←RDATA;
	QQ RCY [1], Q←(RDATA) RCY 1, CALL[PQCOMP];
	GOTO[.+1];			*P/ RDATA RCY 1 VIA QQ RCY
					*Q/ RDATA RCY 1 DIRECTY

XMASKT:	Q←RDATA, P←77S;
	X←P AND Q;
	P←LDATA, XMASK, Y←X;
	RTEMP←P, P←SY, Q←LDATA;
	P←P AND Q, Q←RTEMP, CALL[PQCOMP]; *PROBABLY FAILURE OF P←LDATA, XMASK
	GOTO[.+1];			*P/ GOOD VALUE
					*Q/ P←LDATA, XMASK

*ON TESTS BELOW, FAILURE IS PROBABLY ON P←RDATA, SAMASK.  ON FAILURE:
*P/ RESULT OF P←RDATA, SAMASK VIA MDR
*Q/ CORRECT VALUE VIA Q←P AND Q
SMASKT:	Y←NULL, P←RDATA, Q←LDATA, SAMASK[0], CALL[SAMT];
	SET[TT,1];
REPEAT[77,ILC[(P+Q, P←RDATA, Q←LDATA, SAMASK[TT], CALL[SAMT])]
	SET[TT,ADD[TT,1]]];		*P+Q FOR NOISE AFFECT

*ON TESTS BELOW, FAILURE IS PROBABLY ON P←RDATA, AMASK.  ON FAILURE:
*P/ RESULT OF P←RDATA, AMASK VIA MDR
*Q/ CORRECT VALUE VIA Q←P AND Q
AMASKT:	Y←NULL, P←RDATA, Q←LDATA, AMASK[0], CALL[SAMT];
	SET[TT,1];
REPEAT[37,ILC[(P←RDATA, Q←LDATA, AMASK[TT], CALL[SAMT])]
	SET[TT,ADD[TT,1]]];

*ON TESTS BELOW, FAILURE IS PROBABLY ON P←LDATA, BAMASK.  ON FAILURE:
*P/ RESULT OF P←LDATA, BAMASK VIA MDR
*Q/ CORRECT RESULT VIA Q←P AND Q
BAMSKT:	Y←NULL, P←LDATA, Q←RDATA, BAMASK[0]; *Q←RDATA FOR NOISE AFFECT
	MDR←P, Q←LDATA;
	P←SY, CALL[BAMT];
	SET[TT,1];
REPEAT[77,ILC[(P←LDATA, Q←SY, BAMASK[TT])]
	ILC[(MDR←P, P←Q, Q←LDATA, CALL[BAMT])]
	SET[TT,ADD[TT,1]]];

PQCYCT:	P←RDATA, Q←44S, AMASK[6];
	P-Q;
	Y←P, PQ RCY [1], GOTO[.-1,ALU>=0]; *Y←NUMBER .L. 44
	P←RDATA, Q←LDATA;
	PQ RCY [Y], DECY, STEMP←Y;
	MDR←P, P←LDATA, Q←RDATA, DECY, GOTO[.+2,Y<0];
	Q RSH 1, PQ RCY [1], ASHOVF, DECY, GOTO[.,Y>=0];
	P←MDR, CALL[PQCOMP];		*P/ RESULT OF PQ RCY [STEMP]
	GOTO[.+1];			*Q/ SAME RESULT VIA Q RSH 1, ASHOVF

0QCYCT:	P←RDATA, Q←44S, AMASK[6];
	P-Q;
	Y←P, PQ RCY [1], GOTO[.-1,ALU>=0]; *Y←NUMBER .L. 44
	P←RDATA, Q←LDATA;
	0Q RCY [Y], DECY, STEMP←Y, Q←A0;
	MDR←P, P←LDATA, DECY, GOTO[.+2,Y<0];
	Q RSH 1, PQ RCY [1], ASHOVF, DECY, GOTO[.,Y>=0];
	P←MDR, CALL[PQCOMP];		*P/ RESULT OF 0Q RCY [STEMP]
	GOTO[.+1];			*Q/ SAME RESULT VIA Q RSH 1

QQCYCT:	P←RDATA, Q←44S, AMASK[6];
	P-Q;
	Y←P, PQ RCY [1], GOTO[.-1,ALU>=0];
	P←RDATA, Q←LDATA;
	QQ RCY [Y], DECY, STEMP←Y;
	MDR←P, P←Q←LDATA, DECY, GOTO[.+2,Y<0];
	Q RSH 1, PQ RCY [1], ASHOVF, DECY, GOTO[.,Y>=0];
	P←MDR, CALL[PQCOMP];		*P/ RESULT OF QQ RCY [STEMP]
	GOTO[.+1];			*Q/ SAME RESULT VIA Q RSH 1

%THE SLOWEST ALU PATHS ARE P MASKING, NOT(ALU)Q RCY [Y] WITH ARITHMETIC THROUGH ALU AND INPUT CARRY COMPLEMENTING THE PREVIOUS INSTRUCTION.
WORST CASES ARE XMASK AFTER X←SLOW SOURCE, RCY [Y] AFTER Y←FAST SOURCE.
THESE COMBINATIONS ARE TESTED BELOW.

**NOTE:  RCY [Y] IS ILLEGAL AFTER LOADING Y FROM SLOW SOURCE AND RCY [44-Y]
**AFTER ANY LOAD OF Y.
%
SLOWT1:	Y←SMDATA;
	P←RDATA, Q←LDATA;
	NOT(P+Q+1)Q RCY [44-Y];		*F2 = CARRY1
	MDR←P, P←RDATA, Q←LDATA;
	P←P+Q+1;
	P←NOT P;
	PQ RCY [44-Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ RESULT VIA QUICK PATHS
	GOTO[.+1];			*Q/ RESULT VIA SLOW PATHS

SLOWT2:	Q←MDATA;
	P←RDATA, Q←LDATA, XSPLIT←Q;	*X←Y←FAST SOURCE
	NOT(P-Q)Q RCY [Y];		*F2 = CARRY1
	MDR←P, P←LDATA, Q←RDATA;
	P←P-Q-1, Q←LDATA;		*NOT(RDATA-LDATA) = LDATA-RDATA-1
	PQ RCY [Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ RESULT VIA QUICK PATHS
	GOTO[.+1];			*Q/ RESULT VIA SLOW PATHS

SLOWT3:	Q←MDATA;
	P+Q+1, P←LDATA, Q←RDATA, SETSF[J], XSPLIT←Q;
	NOT(P+Q)Q RCY [Y];
	MDR←P, P←LDATA, Q←RDATA;
	P←P+Q;
	P←NOT P;
	PQ RCY [Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ QUICK RESULT
	GOTO[.+1];			*Q/ SLOW RESULT

SLOWT4:	Q←MDATA;
	P←LDATA, Q←RDATA, Y←Q;
	NOT(P-Q)Q RCY [Y];		*F2 = CARRY1
	MDR←P, P←LDATA, Q←RDATA;
	P←P-Q;
	P←NOT P, Q←RDATA;
	PQ RCY [Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ QUICK RESULT
	GOTO[.+1];			*Q/ SLOW RESULT

SLOWT5:	Q←MDATA;
	P←LDATA, Q←RDATA, BSPLIT←Q;
	NOT(P+Q+1)Q RCY [Y];		*F2 = CARRY1
	MDR←P, P←LDATA, Q←RDATA;
	P←P+Q+1;
	P←NOT P, Q←RDATA;
	PQ RCY [Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ QUICK RESULT
	GOTO[.+1];			*Q/ SLOW RESULT

SLOWT6:	Q←MDATA;
	P←LDATA, Q←RDATA, FSPLIT←Q;
	NOT(P-Q-1)Q RCY [Y];
	MDR←P, P←RDATA, Q←LDATA;
	P←P-Q, Q←RDATA;
	PQ RCY [Y], Q←MDR, CALL[PQCOMP,H=0]; *P/ QUICK RESULT
	GOTO[.+1];			*Q/ SLOW RESULT

SLOWT7:	P←RDATA, Q←LDATA, XSPLIT←SMDATA; *X←Y←SLOW BIPOLAR MEM.
	Q←B, B←P+Q+1, NEGY;		*F2 = CARRY1, Q←SLOW ALU
	PQ RCY [Y], XMASK;
	MDR←P, P←RDATA, Q←LDATA;
	Q←P+Q+1;
	PQ RCY [Y], XMASK, Q←MDR, CALL[PQCOMP,H=0];
	GOTO[.+1];			*P/ RESULT VIA QUICK PATHS
					*Q/ RESULT VIA SLOW PATHS

SLOWT8:	XSPLIT←A1, P←Q←LDATA;
	P←RDATA, XSPLIT←Q←B, B←P+Q+1;	*X←Y←SLOW ALU
	QQ RCY [Y], XMASK;			*F2 = CARRY1, F1 = RCYQQ
	MDR←P, P←Q←LDATA;
	P←Q←P+Q+1;
	PQ RCY [Y], XMASK, Q←MDR, CALL[PQCOMP,H=0];
	GOTO[.+1];			*P/ RESULT VIA QUICK PATHS
					*Q/ RESULT VIA SLOW PATHS

	P←COUNT;
	Q←P+1, GOTO[MCYCLE];