1 /* Floating point library in optimized assembly for 8051
2 * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #define SDCC_FLOAT_LIB
24 #ifdef FLOAT_ASM_MCS51
26 // float __fsadd (float a, float b) reentrant
27 static void dummy(void) _naked
31 // extract the two inputs, placing them into:
32 // sign exponent mantiassa
33 // ---- -------- ---------
34 // a: sign_a exp_a r4/r3/r2
35 // b: sign_b exp_b r7/r6/r5
37 // r1: used to extend precision of a's mantissa
38 // r0: general purpose loop counter
44 .globl fsadd_direct_entry
46 // we're going to extend mantissa to 32 bits temporarily
49 // which exponent is greater?
55 // a's exponent was greater, so shift b's mantissa
59 // b's exponent was greater, so shift a's mantissa
63 lcall fs_rshift_a // acc has # of shifts to do
66 // decide if we need to add or subtract
67 // sign_a and sign_b are stored in the flag bits of psw,
68 // so this little trick checks if the arguements ave the
76 // add the mantissas (both positive or both negative)
86 // check for overflow past 24 bits
94 ljmp fs_round_and_return
99 // subtract the mantissas (one of them is negative)
111 // if we get a negative result, turn it positive and
129 ljmp fs_round_and_return
138 ** libgcc support for software floating point.
139 ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved.
140 ** Permission is granted to do *anything* you want with this file,
141 ** commercial or otherwise, provided this message remains intact. So there!
142 ** I would appreciate receiving any updates/patches/changes that anyone
143 ** makes, and am willing to be the repository for said changes (am I
144 ** making a big mistake?).
147 ** Pipeline Associates, Inc.
148 ** pipeline!phw@motown.com or
149 ** sun!pipeline!phw or
150 ** uunet!motown!pipeline!phw
161 float __fsadd (float a1, float a2)
163 volatile long mant1, mant2;
164 volatile union float_long fl1, fl2;
165 volatile int exp1, exp2;
166 volatile unsigned long sign = 0;
171 /* check for zero args */
180 if (exp1 > exp2 + 25)
182 if (exp2 > exp1 + 25)
185 mant1 = MANT (fl1.l);
186 mant2 = MANT (fl2.l);
195 mant2 >>= exp1 - exp2;
199 mant1 >>= exp2 - exp1;
213 while (mant1<HIDDEN) {
219 while (mant1 & 0xff000000) {
226 /* turn off hidden bit */
229 /* pack up and go home */
230 fl1.l = PACK (sign, (unsigned long) exp1, mant1);