1*45761Sbostic/*- 2*45761Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*45761Sbostic * All rights reserved. 4*45761Sbostic * 5*45761Sbostic * This code is derived from software contributed to Berkeley by 6*45761Sbostic * Computer Consoles Inc. 7*45761Sbostic * 8*45761Sbostic * %sccs.include.redist.c% 9*45761Sbostic * 10*45761Sbostic * @(#)Kaddd.s 7.1 (Berkeley) 12/06/90 11*45761Sbostic */ 1224133Ssam 1345701Sbostic#include "../math/fp.h" 1425693Ssam#include "../tahoe/SYS.h" 1524133Ssam 1625664Ssam/* 1725664Ssam * _Kaddd(acc_most,acc_least,op_most,op_least,hfs) 1825664Ssam */ 1924133Ssam 2025664SsamENTRY(Kaddd, R10|R9|R8|R7|R6|R5|R4|R3|R2) 2125664Ssam/* 2225664Ssam * see which operand has a greater exponent 2325664Ssam * The greater one will be fetched into r0,r1,r2,r3. 2425664Ssam * r0,r1 - 'pure' fraction, r2 - exponent, r3 - sign). 2525664Ssam * The smaller operand will be fetched into r4,r5,r6,r7. 2625664Ssam */ 2724133Ssam tstl 4(fp) # handle (a+b) where a and/or b = 0.0 2824133Ssam jneq next 2924133Ssam movl 16(fp),r1 3024133Ssam movl 12(fp),r0 3124133Ssam ret 3224133Ssamnext: 3324133Ssam tstl 12(fp) 3424133Ssam jneq doit 3524133Ssam movl 8(fp),r1 3624133Ssam movl 4(fp),r0 3724133Ssam ret 3824133Ssamdoit: 3924133Ssam andl3 $EXPMASK,4(fp),r0 4024133Ssam andl3 $EXPMASK,12(fp),r1 4124133Ssam cmpl r0,r1 4224133Ssam jgtr first_greater 4324133Ssam 4424133Ssam movl 12(fp),r0 # bigger operand to r0,r1 4524133Ssam movl 16(fp),r1 4624133Ssam 4724133Ssam movl 4(fp),r4 # smaller operand to r4,r5 4824133Ssam movl 8(fp),r5 4924133Ssam jmp expo 5024133Ssam 5124133Ssamfirst_greater: 5224133Ssam movl 4(fp),r0 # bigger operand to r0,r1 5324133Ssam movl 8(fp),r1 5424133Ssam 5524133Ssam movl 12(fp),r4 # smaller operand to r4,r5 5624133Ssam movl 16(fp),r5 5724133Ssam 5824133Ssam 5925664Ssam/* 6025664Ssam * Compute exponents: 6125664Ssam */ 6224133Ssamexpo: 6324133Ssam andl3 $EXPMASK,r0,r2 # r2 will hold the exponent. 6424133Ssam shrl $EXPSHIFT,r2,r2 6524133Ssam andl3 $EXPMASK,r4,r6 # r6 will hold the exponent. 6624133Ssam shrl $EXPSHIFT,r6,r6 6725664Ssam/* 6825664Ssam * Compare the exponents: 6925664Ssam */ 7024133Ssam subl3 r6,r2,r8 7124133Ssam jeql signs 7224133Ssam cmpl r8,$MAX_EXP_DIF 7324133Ssam jleq signs 7424133Ssam ret # return the bigger number. 7524133Ssam 7625664Ssam/* 7725664Ssam * Remember the signs: 7825664Ssam */ 7924133Ssamsigns: 8024133Ssam clrl r3 8124133Ssam bbc $31,r0,sign2 # if negative remember it. 8224133Ssam incl r3 8324133Ssamsign2: 8424133Ssam clrl r7 8524133Ssam bbc $31,r4,frac # if negative remember it. 8624133Ssam incl r7 8725664Ssam/* 8825664Ssam * Compute 'pure' fraction: 8925664Ssam */ 9024133Ssamfrac: 9124133Ssam # clear the non fraction parts. 9224133Ssam andl2 $(0!(EXPMASK | SIGNBIT)),r0 9324133Ssam # add the hidden bit. 9424133Ssam orl2 $(0!CLEARHID),r0 9524133Ssam # clear the non fraction parts. 9624133Ssam andl2 $(0!(EXPMASK | SIGNBIT)),r4 9724133Ssam # add the hidden bit. 9824133Ssam orl2 $(0!CLEARHID),r4 9924133Ssam 10025664Ssam/* 10125664Ssam * Shift the smaller operand: 10225664Ssam */ 10324133Ssam shrq r8,r4,r4 10424133Ssameql_exps: 10524133Ssam cmpl r3,r7 10624133Ssam jeql add 10724133Ssam bbc $0,r3,negr4r5 10825664Ssam/* 10925664Ssam * Negate the pair r0,r1: 11025664Ssam */ 11124133Ssam clrl r3 11224133Ssam mcoml r1,r1 11324133Ssam clrl r9 # r9 - carry flag. 11424133Ssam incl r1 11524133Ssam bcc comr0 11624133Ssam incl r9 # remember the carry. 11724133Ssamcomr0: mcoml r0,r0 11824133Ssam bbc $0,r9,add 11924133Ssam incl r0 12024133Ssam 12125664Ssam/* 12225664Ssam * Add the fractions: 12325664Ssam */ 12424133Ssamadd: 12524133Ssam clrl r10 # to remember the sign of the result. 12624133Ssam addl2 r5,r1 12724133Ssam adwc r4,r0 12824133Ssam jgeq norm # if positive go to normelize. 12924133Ssam incl r10 # else remember it and negate the result. 13025664Ssam/* 13125664Ssam * Negate the pair r0,r1: 13225664Ssam */ 13324133Ssam clrl r3 13424133Ssam mcoml r1,r1 13524133Ssam clrl r9 # r9 - carry flag. 13624133Ssam incl r1 13724133Ssam bcc comr00 13824133Ssam incl r9 # remember the carry. 13924133Ssamcomr00: mcoml r0,r0 14024133Ssam bbc $0,r9,norm 14124133Ssam incl r0 14224133Ssamnorm: pushl 20(fp) # addr of returnen exception. 14325664Ssam callf $8,_Kfnorm 14424133Ssam 14525664Ssam/* 14625664Ssam * Add the sign bit 14725664Ssam */ 14824133Ssam bbs $0,r10,negative 14924133Ssam bbs $0,r3,negative 15024133Ssam ret 15124133Ssamnegative: 15224133Ssam orl2 $SIGNBIT,r0 15324133Ssam ret 15424133Ssam 15524133Ssam 15625664Ssam/* 15725664Ssam * Negate the pair r4,r5: 15825664Ssam */ 15924133Ssamnegr4r5: 16024133Ssam clrl r7 16124133Ssam mcoml r5,r5 16224133Ssam clrl r9 # r9 - carry flag. 16324133Ssam incl r5 16424133Ssam bcc comr4 16524133Ssam incl r9 # remember the carry. 16624133Ssamcomr4: mcoml r4,r4 16724133Ssam bbc $0,r9,add 16824133Ssam incl r4 16924133Ssam jmp add 17024133Ssam 17124133Ssam movl r4,r0 # return the smaller operand. 17224133Ssam movl r5,r1 17324133Ssam ret 174