From:	CSBVAX::MRGATE!@KL.SRI.Com,@cis.upenn.edu:CLAYTON@xrt.upenn.edu@SMTP  8-SEP-1987 20:15
To:	EVERHART
Subj:	Re: Quadword Math Routines Provided Here...

Received: from linc.cis.upenn.edu by KL.SRI.COM with TCP; Sat 5 Sep 87 10:18:34-PDT
Received: by linc.cis.upenn.edu
	id AA25285; Sat, 5 Sep 87 13:18:23 EDT
Posted-Date: Sat, 5 Sep 87 13:00 EDT
Message-Id: <8709051718.AA25285@linc.cis.upenn.edu>
Received: from xrt.upenn.edu by cis.upenn.edu; Sat, 5 Sep 87 13:22 EDT
Date: Sat, 5 Sep 87 13:00 EDT
From: "Clayton, Paul D." <@cis.upenn.edu:CLAYTON@xrt.upenn.edu>
Subject: Re: Quadword Math Routines Provided Here...
To: ECKERT%CAR54.DEC@decwrl.dec.com, INFO-VAX@kl.sri.com
X-Vms-To: @INFOVAX,CLAYTON


Information From TSO Financial - The Saga Continues...
Chapter 20 - Sept. 5, 1987

Ted from MITRE Corporation asked for a quad-word add routine. I am submitting
the following routines for add, subtract, multiply and divide on quad word
information. I have used these routines for the purpose of handling times as
returned by VMS. 

Credit for these routines goes to Bob Stodola, who works at The Institute For
Cancer Research (ICR) in Penna, USA. Thanks Bob.


!	.TITLE	QUAD_MATH
;
;	CALL SUBQUAD(A,B,C)
;
;	RETURNS: A - B -> C
;
	.PSECT	SUBQUAD	NOWRT,EXE
	.ENTRY	SUBQUAD	^M<R2>
;
;
A=4
B=8
C=12
	MOVQ	@A(AP),R0
	MOVAQ	@B(AP),R2
	SUBL	(R2)+,R0
	SBWC	(R2),R1
	MOVQ	R0,@C(AP)
	RET
;
;
;
	.PSECT	COMPQUAD	NOWRT,EXE
	.ENTRY	COMPQUAD	^M<R2>
;
;
;
	MOVQ	@A(AP),R0
	MOVAQ	@B(AP),R2
	SUBL	(R2)+,R0
	SB#(R2),R1
	MOVQ	R0,R0			;"TEST" QUADWORD
	BEQL	10$
	BGTR	20$
	MOVL	#-1,R0
	BRB	30$
10$:
	CLRL	R0
	BRB	30$
20$:
	MOVL	#1,R0
30$:
	RET
;
;
;
	.PSECT	EDIV	NOWRT,EXE
	.ENTRY	EDIV	^M<R2>
;
;	CALL EDIV (A,B,C)
;	RETURNS A/B->C
;
	MOVQ	@A(AP),R0
	MOVAL	@B(AP),R2
	EDIV	(R2),R0,R0,R1
	MOVL	R0,@C(AP)
	RET
;
;
;
	.PSECT	EMUL	NOWRT,EXE
	.ENTRY	EMUL	^M<R2>
;
;	CALL EMUL (A,B,C)
;	RETURNS A*B->C
;
	MOVAL	@A(AP),R1
	MOVAL	@B(AP),R2
	EMUL	(R1),(R2),#0,R0
	MOVQ	R0,@C(AP)
	RET
;
;
;	CALL ADDQUAD(A,B,C)
;
;	RETURNS: A + B -> C
;
	.PSECT	ADDQUAD	NOWRT,EXE
	.ENTRY	ADDQUAD	^M<R2>
;
;
A=4
B=8
C=12
	MOVQ	@A(AP),R0
	MOVAQ	@B(AP),R2
	ADDL	(R2)+,R0
	ADWC	(R2),R1
	MOVQ	R0,@C(AP)
	RET
;
;
;	RESULT = QUAD_TO_D,F(A)
;
;	RETURNS: A -> CONVERT TO DOUBLE,FLOATING -> RESULT
;
	.PSECT	QUAD_TO_DF	NOWRT,EXE
QUAD_TO_F::
	.ENTRY	QUAD_TO_D ^M<R2,R3>
;
;
A=4
	MOVQ	@A(AP),R0
	CVTLD	R1,R2
	TSTL	R2
	BEQL	5$
	EXTV	#7,#8,R2,R1
	ADDL	#32,R1
	INSV	R1,#7,#8,R2
5$:
	BBCC	#31,R0,10$
	ADDD	#^F2147483648,R2
10$:
	CVTLD	R0,R0
	ADDD	R2,R0
	RET
	.END

Paul D. Clayton - Manager Of Systems
TSO Financial - Horsham, Pa. USA
Address - CLAYTON%XRT@CIS.UPENN.EDU

