1/* 2 * Copyright (c) 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Computer Consoles Inc. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21#if defined(SYSLIBC_SCCS) && !defined(lint) 22 .asciz "@(#)addf.s 1.2 (Berkeley) 02/17/89" 23#endif /* SYSLIBC_SCCS and not lint */ 24 25#include <tahoemath/fp.h> 26#include "DEFS.h" 27 28XENTRY(addf, R2|R3|R4|R5|R6|R7|R8|R9|R10) 29/* 30 * see which operand has a greater exponent 31 * The greater one will be fetched into r0,r2,r3. 32 * r0- 'pure' fraction, r2 - exponent, r3 - sign). 33 * The smaller operand will be fetched into r4,r6,r7. 34 */ 35 clrl r1 36 andl3 $EXPMASK,4(fp),r0 37 andl3 $EXPMASK,12(fp),r1 38 cmpl r0,r1 39 jgtr first_greater 40 41 movl 12(fp),r0 # bigger operand to r0 42 43 movl 4(fp),r4 # smaller operand to r4 44 jmp expo 45 46first_greater: 47 movl 4(fp),r0 # bigger operand to r0 48 49 movl 12(fp),r4 # smaller operand to r4 50 51 52/* 53 *compute exponents: 54 */ 55expo: 56 andl3 $EXPMASK,r0,r2 # r2 will hold the exponent of greater operand. 57 jeql is_res1 # check for reserved operand. 58 shrl $EXPSHIFT,r2,r2 59 60 61 andl3 $EXPMASK,r4,r6 # r6 will hold the exponent of smaller operand. 62 jeql is_res2 # check for reserved operand. 63 shrl $EXPSHIFT,r6,r6 64/* 65 *compare the exponents: 66 */ 67 subl3 r6,r2,r8 68 jeql signs 69 cmpl r8,$MAX_EXP_DIF 70 jlss signs 71 ret # return the bigger number. 72 73/* 74 *remember the signs: 75 */ 76signs: 77 clrl r3 78 bbc $31,r0,sign2 # if negative remember it.(R3=1) 79 incl r3 80sign2: 81 clrl r7 82 bbc $31,r4,frac # if negative remember it.(R7=1) 83 incl r7 84/* 85 *compute 'pure' fraction: 86 */ 87frac: 88 # clear the non fraction parts. 89 andl2 $(0!(EXPMASK | SIGNBIT)),r0 90 # add the hidden bit. 91 orl2 $(0!CLEARHID),r0 92 # clear the non fraction parts. 93 andl2 $(0!(EXPMASK | SIGNBIT)),r4 94 # add the hidden bit. 95 orl2 $(0!CLEARHID),r4 96 97/* 98 *shift the smaller operand: 99 */ 100 shar r8,r4,r4 101eql_exps: 102 cmpl r3,r7 103 jeql add 104 bbc $0,r3,negr4 105/* 106 *negate r0: 107 */ 108 clrl r3 109 mnegl r0,r0 110 111/* 112 *add the fractions: 113 */ 114add: 115 clrl r10 116 addl2 r4,r0 117 jgeq norm 118 incl r10 119/* 120 *negate the pair r0,r1: 121 */ 122 mnegl r0,r0 123norm: callf $4,sfnorm 124 125/* 126 *add the sign bit 127 */ 128 bbs $0,r10,negative 129 bbs $0,r3,negative # the bigger operand was negative. 130 ret 131negative: 132 orl2 $SIGNBIT,r0 133 ret 134 135 136/* 137 *negate r4: 138 */ 139negr4: 140 mnegl r4,r4 141 jmp add 142 143 144is_res1: 145 bbs $31,r0,res_op 146 movl r4,r0 # return the smaller operand. 147 ret 148 149is_res2: 150 bbs $31,r4,res_op 151 ret # we allready have the 'result' in r0,r1. 152 153res_op: 154 callf $4,sfpresop 155 ret 156