/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: r_ari.s,v 1.2 1997/09/25 16:00:20 ae59 Exp $ */
/*
$Log: r_ari.s,v $
# Revision 1.2  1997/09/25  16:00:20  ae59
# Copyright message
#
# Revision 1.1  1994/01/27  13:40:55  ae59
# Put under RCS control
#
 */
/****************************************************************/
/*                                                              */
/*      Filename        : r_ari.c                               */
/*                                                              */
/*      Entries         : a_real r_addd(a,b)                    */
/*                        a_real r_addn(a,b)                    */
/*                        a_real r_addu(a,b                    )*/
/*                        a_real r_subd(a,b)                    */
/*                        a_real r_subn(a,b)                    */
/*                        a_real r_subu(a,b)                    */
/*                        a_real r_muld(a,b)                    */
/*                        a_real r_muln(a,b)                    */
/*                        a_real r_mulu(a,b)                    */
/*                        a_real r_divd(a,b)                    */
/*                        a_real r_divn(a,b)                    */
/*                        a_real r_divu(a,b)                    */
/*                               a_real a,b;                    */
/*                        void   r_lfsr()                       */
/*                                                              */
/*      Arguments       : a = first IEEE operand of operation   */
/*                        b = second IEEE operand of operation  */
/*                                                              */
/*      Description     : Addition, Subtraction,		         */
/*                        Multiplication, Division of IEEE      */
/*                        numbers. Result is rounded downwards, */
/*                        nearest or upwards according to the   */
/*                        suffix.                               */
/*                        Assembly routines for HP PA.          */
/*                                                              */
/*      Date            : 1994-01-10                            */
/*      1994-01-10      : save fpu register in case of exception*/
/*      1992-07-08      : changed fsrd temd according name conv.*/
/*      1992-07-07      : add function r_lfsr cb                */
/*      1992-06-12      : changed pxsc_trap... to r_ftrp =b=    */
/*                        expand tabs in header                 */
/*      1992-05-21      : org date                              */
/****************************************************************/
/*                                                              */
/* Parameteruebergabe:                                          */
/*   Eingabezahlen stehen in %fr7 und %fr5                      */
/*   Resultat steht in %fr4                                     */
/*                                                              */
/****************************************************************/


	.CODE

r_addd
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	; lade Adresse von e_srdd nach %r19. %r27 ist global-pointer
	ADDIL	LR'e_srdd-$global$, %r27
	LDO	RR'e_srdd-$global$(%r1), %r19
	; lade fsr
	FLDWS	0(0,%r19), %fr0
	; addiere, Resultat nach %fr4
	FADD,DBL %fr5, %fr7, %fr4
	; speichere fsr
	FSTWS	%fr0, 0(0,%r19)
	; lade trap enable mask nach %r20
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	; lade fsr nach %r21
	LDW	0(0,%r19), %r21
	; teste auf Auftreten einer freigegebenen Exception
	; speichere nach %r26 als Eingabe des handlers. In
	; r22 werden die enabled-bits aus den aufgetretenen
	; Exceptions wieder geloescht (nur fuer disabled Exc.
	; werden flags mitgefuehrt) und das fsr wieder in den
	; Speicher geschrieben.
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_addd1
	STW	%r22, 0(0,%r19)
	; trap-handler aufrufen
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_addd1
	.LEAVE
	.PROCEND

r_addn
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdn-$global$, %r27
	LDO	RR'e_srdn-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FADD,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_addn1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_addn1
	.LEAVE
	.PROCEND

r_addu
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdu-$global$, %r27
	LDO	RR'e_srdu-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FADD,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_addu1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_addu1
	.LEAVE
	.PROCEND

r_subd
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdd-$global$, %r27
	LDO	RR'e_srdd-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FSUB,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_subd1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_subd1
	.LEAVE
	.PROCEND

r_subn
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdn-$global$, %r27
	LDO	RR'e_srdn-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FSUB,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_subn1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_subn1
	.LEAVE
	.PROCEND

r_subu
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdu-$global$, %r27
	LDO	RR'e_srdu-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FSUB,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_subu1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_subu1
	.LEAVE
	.PROCEND

r_muld
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdd-$global$, %r27
	LDO	RR'e_srdd-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FMPY,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_muld1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_muld1
	.LEAVE
	.PROCEND

r_muln
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdn-$global$, %r27
	LDO	RR'e_srdn-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FMPY,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_muln1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_muln1
	.LEAVE
	.PROCEND

r_mulu
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdu-$global$, %r27
	LDO	RR'e_srdu-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FMPY,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_mulu1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_mulu1
	.LEAVE
	.PROCEND

r_divd
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdd-$global$, %r27
	LDO	RR'e_srdd-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FDIV,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_divd1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_divd1
	.LEAVE
	.PROCEND

r_divn
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdn-$global$, %r27
	LDO	RR'e_srdn-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FDIV,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_divn1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_divn1
	.LEAVE
	.PROCEND

r_divu
	.PROC
	.CALLINFO CALLER, FRAME=8, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdu-$global$, %r27
	LDO	RR'e_srdu-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	FDIV,DBL %fr5, %fr7, %fr4
	FSTWS	%fr0, 0(0,%r19)
	ADDIL	LR'e_temd-$global$, %r27
	LDW	RR'e_temd-$global$(0,%r1), %r20
	LDW	0(0,%r19), %r21
	ANDCM	%r21, %r20, %r22
	AND,<>	%r20, %r21, %r26
	B	r_divu1
	STW	%r22, 0(0,%r19)
	LDO -56(%r30), %r19
	.CALL
	BL	r_ftrp, %r2
	FSTDS     %fr4,0(0,%r19)
	LDO -56(%r30), %r19
	FLDDS     0(0,%r19), %fr4
r_divu1
	.LEAVE
	.PROCEND

r_lfsr
	.PROC
	.CALLINFO CALLER, FRAME=0, SAVE_RP
	.ENTER
	ADDIL	LR'e_srdn-$global$, %r27
	LDO	RR'e_srdn-$global$(%r1), %r19
	FLDWS	0(0,%r19), %fr0
	.LEAVE
	.PROCEND

	.EXPORT r_addd,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_addn,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_addu,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_subd,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_subn,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_subu,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_muld,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_muln,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_mulu,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_divd,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_divn,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_divu,ENTRY,ARGW0=FR,ARGW1=FU,ARGW2=FR,ARGW3=FU,RTNVAL=FU
	.EXPORT r_lfsr,ENTRY

	.IMPORT $global$, DATA
	.IMPORT e_srdd, DATA
	.IMPORT e_srdn, DATA
	.IMPORT e_srdu, DATA
	.IMPORT e_temd, DATA
	.IMPORT r_ftrp, CODE
	.END
