1 /*-------------------------------------------------------------------------
2 _fsadd.c - Floating point library in optimized assembly for 8051
4 Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
30 #define __SDCC_FLOAT_LIB
35 #ifdef FLOAT_ASM_MCS51
37 // float __fsadd (float a, float b) __reentrant
38 static void dummy(void) __naked
42 // extract the two inputs, placing them into:
43 // sign exponent mantissa
44 // ---- -------- --------
45 // a: sign_a exp_a r4/r3/r2
46 // b: sign_b exp_b r7/r6/r5
48 // r1: used to extend precision of a's mantissa
49 // r0: general purpose loop counter
55 .globl fsadd_direct_entry
57 // we're going to extend mantissa to 32 bits temporarily
60 // which exponent is greater?
66 // a's exponent was greater, so shift b's mantissa
70 // b's exponent was greater, so shift a's mantissa
74 lcall fs_rshift_a
// acc has # of shifts to do
77 // decide if we need to add or subtract
78 // sign_a and sign_b are stored in the flag bits of psw,
79 // so this little trick checks if the arguments have the
87 // add the mantissas (both positive or both negative)
97 // check for overflow past 24 bits
105 ljmp fs_round_and_return
110 // subtract the mantissas (one of them is negative)
122 // if we get a negative result, turn it positive and
140 ljmp fs_round_and_return
148 ** libgcc support for software floating point.
149 ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved.
150 ** Permission is granted to do *anything* you want with this file,
151 ** commercial or otherwise, provided this message remains intact. So there!
152 ** I would appreciate receiving any updates/patches/changes that anyone
153 ** makes, and am willing to be the repository for said changes (am I
154 ** making a big mistake?).
157 ** Pipeline Associates, Inc.
158 ** pipeline!phw@motown.com or
159 ** sun!pipeline!phw or
160 ** uunet!motown!pipeline!phw
170 float __fsadd (float a1
, float a2
) __SDCC_FLOAT_NONBANKED
175 int exp1
, exp2
, expd
;
178 pfl2
= (long _AUTOMEM
*)&a2
;
180 mant2
= MANT (*pfl2
) << 4;
183 /* check for zero args */
187 pfl1
= (long _AUTOMEM
*)&a1
;
189 mant1
= MANT (*pfl1
) << 4;
191 if (*pfl1
& 0x80000000)
193 /* check for zero args */
226 while (mant1
< (HIDDEN
<<4)) {
232 while (mant1
& 0xf0000000) {
239 /* turn off hidden bit */
240 mant1
&= ~(HIDDEN
<<4);
242 /* pack up and go home */
244 *pfl1
= (sign
? (SIGNBIT
| __INFINITY
) : __INFINITY
);
248 *pfl1
= PACK (sign
? SIGNBIT
: 0 , exp1
, mant1
>>4);