/ FLOATING POINT MATH PACKAGE
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974,1977 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE
/AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
/CORPORATION.  DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS MANUAL.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED TO THE PURCHASER
/UNDER A LICENSE FOR USE ON A SINGLE COMPUTER SYSTEM AND CAN BE COPIED
/(WITH INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR USE IN SUCH
/SYSTEM, EXCEPT AS MAY OTHERWISE BE PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/
/	VERSION 5A
/	APRIL 28, 1977
/	VERSION NUMBER IS AVAILABLE AT ENTRY POINTS
/	ENTRIES
/
	ENTRY	FAD
	ENTRY	FSB
	ENTRY	FMP
	ENTRY	FDV
	ENTRY	STO
	ENTRY	FLOT
	ENTRY	FLOAT
	ENTRY	FIX
	ENTRY	IFIX
	ENTRY	IFAD
	ENTRY	ISTO
	ENTRY	ABS
	ENTRY	CHS

/THE FOLLOWING DEFINITIONS ENABLE LIBRARY OPTIMIZATIONS
/WHERE CRITICAL TIMING CONSIDERATIONS EXIST.
/THEY SHOULD BE USED WITH EXTREME CAUTION, AND MUST
/REFERENCE CURRENT PAGE AND PAGE ZERO SYMBOLS ONLY.

OPDEF	TADI	1400
OPDEF	DCAI	3400
OPDEF	JMSI	4400
OPDEF	JMPI	5400
SKPDF	JMSKP	4000
/
/
ABSYM	HAC	20
ABSYM	MAC	21
ABSYM	LAC	22
ABSYM	SRH	23
ABSYM	SRM	24
ABSYM	SRL	25
ABSYM	ACS	26
ABSYM	ACX	27
ABSYM	SRS	30
ABSYM	SRX	31
ABSYM	MQH	30
ABSYM	MQM	31
ABSYM	MQL	32

//	ADDITION AND SUBTRACTION ROUTINE
//

	LAP		/LEAVE AUTO PAGING

ADSRAD,	ADSRAC		/SOME INDIRECTS TO SAVE CORE...
ARSAB,	ARS
GTSPLA,	GTSPLT
NORMAD,	NORMAC
COMAD,	COM

FSB,	BLOCK	1
	5	/FLOATING POINT SUBTRACT
	TAD	FSB	/ CALL 1,FSB
	DCA	FAD	/ ARG <F.P. VARIABLE>
	TAD	FSB#
	DCA	FAD#
	CLA CLL CML RAR
	JMP	ED1
/
ER1,	FAD
FAD,	BLOCK	1
	5		/FLOATING POINT ADD SUBROUTINE
ED1,	DCA	FSB	/ CALL 1,FAD
	TAD	FAD	/ ARG <VARIABLE>
	DCA	FAD1
FAD1,	NOP		/CDF TO PICK UP ARGUMENT
	TADI	FAD#
	INC	FAD#
	DCA	7
	CLA CMA
	TADI	FAD#
	INC	FAD#
	DCA	10
FADENT,	TAD	ER1
	DCA	ER0
	TAD	ACH	/EXAMINE THE FLOATING AC
	SNA CLA
	JMP	FADLD	/IT'S ZERO, DO A LOAD...
	JMSI	GTSPLA
	JMP	FADEND
	TAD	SRS
	TAD	FSB
	DCA	SRS
	TAD	ACX
	SNA
	JMP	SHFAC
	CIA
	TAD	SRX
	SMA
	JMP	SHFAC
	DCA	FSB
SHFSR,	TAD	SRH
	CLL RAR
	DCA	SRH
	TAD	SRM
	RAR
	DCA	SRM
	TAD	SRL
	RAR
	DCA	SRL
	ISZ	FSB
	JMP	SHFSR
	JMP	JD1
/
SHFAC,	CMA
	DCA	FSB
	TAD	SRX
	DCA	ACX
	JMP	ED3A
ED3,	JMSI	ARSAB
ED3A,	ISZ	FSB
	JMP	ED3
/
JD1,	TAD	ACS
	SMA CLA
	JMP	ED4
	CLA CLL CMA RTL	/ GENERATE -3
	JMSI	COMAD
ED4,	TAD	SRS
	SPA CLA
	JMSI	COMAD
	JMSI	ADSRAD
	TAD	HAC
	SMA CLA
	JMP	ED5
	CLA CLL CMA RTL
	JMSI	COMAD
	CLA CLL CML RAR
ED5,	DCA	ACS
	DCA	RSW
FADEND, JMSI	NORMAD
	JMP	FADEX


FADLD,	TAD	7	/FLOATING LOAD WHEN AC=0
	DCA	FADSB#
	JMS	FADSB
	SZA		/CHECK FOR 0.-0. DON'T GIVE -0.
	TAD	FSB
	AND	ABSSW
	DCA	ACH
	JMS	FADSB
	DCA	ACM
	JMS	FADSB
	DCA	ACL
FADEX,	CLA CMA
	DCA	ABSSW
	DCA	FSB	/FOR IFAD AFTER SUBTRACT
	CLA STL RTL	/=0002
	TAD	FAD	/HIGH SPEED RETURN
	DCA	FAD3
FAD3,	NOP
	JMPI	FAD#

ABSSW,	7777		/ABSOLUTE VALUE SWITCH

FADSB,	0		/TIME SAVING SUBROUTINE
	NOP		/CHANGED TO CDF
	TADI	10
	JMPI	FADSB

/	FLOATING POINT ABSOLUTE VALUE FUNCTION

ABS,	BLOCK	1
	5		/ CALL 1,ABS
	TAD	ABS	/ ARG <F.P. VARIABLE>
	DCA	FAD
	TAD	ABS#
	DCA	FAD#
	CLL STA RAR	/=3777
	DCA	ABSSW
	JMP	ED1	/GO INTO ADD ROUTINE...

	PAGE


/	ROUTINE TO GET OPERAND INTO SR, SEPARATE SIGNS AND
/	EXPONENTS OF AC AND SR, AND MOVE GLOBAL AC TO LOCAL AC.
/

GTSPLT, 0
	TAD	7
	DCA	GTS1
GTS1,	NOP
	TADI	10	/PICK UP HIGH ORDER WORD
	JMS	SPLIT	/MUST NOT CHANGE DATA FIELD****
	DCA	SRH
	TAD	ACX
	SZA
	INC	GTSPLT
	DCA	SRX
	TAD	ACS
	DCA	SRS
	TADI	10	/PICK UP WORD 2
	DCA	SRM
	TADI	10	/PICK UP WORD 3
	DCA	SRL
	TAD	ACH
	JMS	SPLIT	/EXPAND THE FLOATING AC...
	DCA	HAC
	DCA	RSW
GTS2,	TAD	ACM	/NEEDS LABEL TO FORCE CDF!
	DCA	MAC
	TAD	ACL
	DCA	LAC
	JMPI	GTSPLT
/

SPLIT,	0		/BREAK UP SIGN, EXPON, AND HI-ORD BITS
	DCA	TMP	/ROUTINE MUST NOT CHANGE DATA FIELD****
	TAD	TMP
	RAR
	RTR
	AND	(377
	DCA	ACX
	CLA CLL CML RAR	/ = 4000
	AND	TMP
	DCA	ACS
	TAD	TMP
	AND	(7
	JMPI	SPLIT
TMP,	0
/
/

ALS,	0		/LOCAL AC SHIFT LEFT SUBROUTINE
	TAD	LAC
	CLL RAL
	DCA	LAC
	TAD	MAC
	RAL
	DCA	MAC
	TAD	HAC
	RAL
	DCA	HAC
	JMPI	ALS
/
/	ADD SR TO AC
/

ADSRAC, 0		/ADD LOCAL SR TO LOCAL AC
	CLL
	TAD	LAC
	TAD	SRL
	DCA	LAC
	CLA RAL
	TAD	MAC
	TAD	SRM
	DCA	MAC
	CLA RAL
	TAD	HAC
	TAD	SRH
	DCA	HAC
	JMPI	ADSRAC
/
/	ROUTINE TO NORMALIZE AND RECOMBINE ACCUMULATOR,
/	  AND PLACE LOCAL ACC. IN GLOBAL ACC.
/
ARSAD,	ARS		/SOME CORE SAVING INDIRECTS
ERRAD,	ERR
RSW,	0		/ROUNDING BIT

NORMAC, 0		/NORMALIZE AND PACKING SUBROUTINE
ED6,	TAD	HAC
	TAD	(7770
	SPA CLA
	JMP	RUND
	JMSI	ARSAD
	ISZ	ACX
	JMP	ED6
/
/		ROUNDOFF ROUTINE
/
RUND,	TAD	RSW
	SNA CLA
	JMP	LEFTST
	ISZ	LAC
	JMP	LEFTST
	ISZ	MAC
	JMP	LEFTST
	ISZ	HAC
	DCA	RSW
	JMP	ED6
/
LEFTST, TAD	ACX
	SNA SPA
	JMP	ZEROUT
	DCA	ACX
	CLA CLL CMA RTL	/ = -3
	TAD	HAC
	SMA SZA CLA
	JMP	COMBIN
	JMS	ALS
	CLA CMA
	JMP	LEFTST
/
COMBIN, TAD	ACX
	CLL RAL
	RTL
	SPA
	JMPI	ERRAD
	TAD	HAC
	TAD	ACS
ED7,	DCA	ACH
	TAD	MAC
	DCA	ACM
	TAD	LAC
	DCA	ACL
	JMPI	NORMAC

ZEROUT, CLA
	DCA	LAC
	DCA	MAC
	JMP	ED7

	PAGE
/
/	INDIRECT STORE
/

ISTO,	BLOCK	1
	5		/FLOATING POINT INDIRECT STORE
	TAD	ISTO	/ CALL 1,ISTO
	DCA	IST1	/ ARG <2WORD ADDRESS>
IST1,	NOP
	TADI	ISTO#
	INC	ISTO#
	DCA	IST2
	TADI	ISTO#
	DCA	7
	TAD	ISTO
	DCA	STO
	TAD	ISTO#
	DCA	STO#
IST2,	NOP
	TADI	7
	INC	7
	DCA	ISTO
	CLA CMA
	TADI	7
	DCA	10
	TAD	ISTO
	DCA	STOSB#
	JMP	STOX
/
/
/	ROUTINE TO STORE CONTENTS OF FL. PT. ACC AND CLEAR IT
/
STO,	BLOCK	1
	5		/ CALL 1,STO
	TAD	STO	/ ARG <F.P. VARIABLE>
	DCA	STO1
STO1,	NOP		/REPLACED BY CDF
	TADI	STO#
	INC	STO#
	DCA	STOSB#
	CLA CMA
	TADI	STO#
	DCA	10
STOX,	TAD	ACH
	JMS	STOSB
	DCA	ACH
	TAD	ACM
	JMS	STOSB
	DCA	ACM
	TAD	ACL
	JMS	STOSB
	DCA	ACL
	INC	STO#
	CLA STL RTL	/=0002
	TAD	STO	/SOME TIME SAVING CODE...
	DCA	STO3
STO3,	NOP		/REPLACED BY CIF CDF
	JMPI	STO#

STOSB,	0		/TIME SAVING SUBROUTINE
	NOP		/CHANGED TO A CDF DESTINATION
	DCAI	10
	JMPI	STOSB
/
/	FLOATING POINT TO FIXED POINT CONVERSION
/
FXER,	4611
	3040	/"FIX" ERROR
FIX,	BLOCK	1
	5	
FIXX,	TAD	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
	JMSI	ADSRAE
	ISZ	FMP1
	JMP	MULT
	JMSI	NORMAG
	RETRN	FMP
/
/
/		FLOATING POINT DIVISION
/
DIVZ,	4411
	2632
FDV,	BLOCK	1
	5
	TAD	ER4
	DCAI	ER01
	TAD	FDV
	DCA	FDV0
FDV0,	NOP		/CDF TO FIELD OF CALLING PROGRAM
	TADI	FDV#
	INC	FDV#
	DCA	7
	CLA CMA
	TADI	FDV#
	INC	FDV#
	DCA	10
	JMSI	GTSPLB
	JMP	DIVERR
	TAD	ACS
	TAD	SRS
	DCA	ACS
	TAD	SRX
	CIA
	TAD	ACX
	TAD	(177
	DCA	ACX
	DCA	MQL
	TAD	(-35
	DCA	FDV0
DVID,	CLA CLL CML RAR	/ = 4000
	AND	SRH
	TAD	HAC
	SPA CLA
	JMP	FDV1
	JMSI	COMAF
FDV1,	JMSI	ADSRAE
	TAD	MQL
	RAL
	DCA	MQL
	TAD	MQM
	RAL
	DCA	MQM
	TAD	MQH
	RAL
	DCA	MQH
	JMS	ALS
	ISZ	FDV0
	JMP	DVID
/
	TAD	MQH
	DCA	HAC
	TAD	MQM
	DCA	MAC
	TAD	MQL
	DCA	LAC
	JMSI	NORMAG
FDVRET,	RETRN	FDV

DIVERR,	CALL	1,ERROR
	ARG	DIVZ
	CLA CLL CMA RAR
	DCA	ACH
	JMP	FDVRET

	PAGE
/
/	ROUTINE TO GET TWO'S COMPLEMENT OF TRIPLE WORD NUMBER
/	IF NO ADDRESS IN AC UPON ENTRY, SR IS ASSUMED.
/
COM,	0
	TAD	(25		/ADDRESS OF SRL
	DCA	PTR2
	CLA CLL CMA RTL	/ = -3
	DCA	CTR2
ED8,	TAD I 	PTR2
	CMA
	SZL
	CLL IAC
	DCA I	PTR2
	CLA CMA CML
	TAD	PTR2
	DCA	PTR2
	ISZ	CTR2
	JMP	ED8
	JMP I	COM
PTR2,	0
CTR2,	0
/
/	CONVERT FIXED POINT TO FLOATING POINT
/
	CPAGE	14

FLOAT,	BLOCK	1
	5		/FLOAT FUNCTION
	TAD	FLOAT	/ CALL 1,FLOAT
	DCA	FLO1	/ ARG <INT. VARIABLE>
FLO1,	NOP
	TADI	FLOAT#
	INC	FLOAT#
	DCA	FLO2
	TADI	FLOAT#
	INC	FLOAT#
	DCA	7
	TAD	FLOAT
	DCA	FLOT
	TAD	FLOAT#
	DCA	FLOT#
FLO2,	NOP		/CDF TO FIELD OF ARGUMENT
	TADI	7
	JMP	FLOTX
/
/	INTEGER TO FLOATING POINT CONVERSION
/
FLOT,	BLOCK	1
	5		/ CALL 0,FLOT
FLOTX,	CLL		/ASSUMES INTEGER VARIABLE IN AC
	SPA
	CIA CML
	DCA	MAC
	DCA	HAC
	DCA	LAC
	RAR
	DCA	ACS
	TAD	(217
	DCA	ACX
	DCA	RSW
	JMS	NORMAC
	RETRN	FLOT

/	INDIRECT FLOATING POINT ADD

	CPAGE	36
IFAD,	BLOCK	1
	5		/ CALL 1,IFAD
	TAD	IFAD	/ ARG <2WORD ADDRESS>
	DCA	IFA1
IFA1,	NOP
	TADI	IFAD#
	INC	IFAD#
	DCA	IFA2
	CLA CMA
	TADI	IFAD#
	INC	IFAD#
	DCA	10
IFA2,	NOP
	TADI	10
	DCA	7
	CLA CMA
	TADI	10
	DCA	10
	TAD	IFAD
	DCA	FAD
	TAD	IFAD#
	DCA	FAD#
	JMP	FADENT


ARS,	0		/LOCAL AC SHIFT RIGHT SUBROUTINE
	TAD	HAC
	CLL RAR
	DCA	HAC
	TAD	MAC
	RAR
	DCA	MAC
	TAD	LAC
	RAR
	DCA	LAC
	CLA RAL
	DCA	RSW
	JMPI	ARS

FPER,	5726
	0614		/"OVFL" ERROR
CHS,	BLOCK	1
	5		/FLOATING POINT NEGATION
	TAD	ACH	/ CALL 0,CHS
	SZA
	TAD	(4000
CHSRET,	DCA	ACH
	RETRN	CHS
/
/	ERROR ROUTINES
/
ER0,	0		/CONTAINS ADDRESS OF CURRENT ENTRY PT
ERR,	CLA
	TAD I	ER0	/BANK CALL IS FROM
	DCA	CHS
	ISZ	ER0	/INDEX TO ADDRESS
	TAD I	ER0	/ADDRESS
	DCA	CHS#
	CALL	1,ERROR
	ARG	FPER
	CLA CLL CMA RAR
	JMP	CHSRET

	END

