Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / _fssub.c
1 /* Floating point library in optimized assembly for 8051
2  * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #define SDCC_FLOAT_LIB
21 #include <float.h>
22
23
24 #ifdef FLOAT_ASM_MCS51
25
26 //float __fssub (float a, float b) __reentrant
27 static void dummy(void) __naked
28 {
29         __asm
30         .globl  ___fssub
31 ___fssub:
32         mov     r0, sp
33         dec     r0
34         dec     r0
35         xch     a, @r0
36         cpl     acc.7
37         xch     a, @r0
38         ljmp    ___fsadd
39         __endasm;
40 }
41
42 #else
43
44 /*
45 ** libgcc support for software floating point.
46 ** Copyright (C) 1991 by Pipeline Associates, Inc.  All rights reserved.
47 ** Permission is granted to do *anything* you want with this file,
48 ** commercial or otherwise, provided this message remains intact.  So there!
49 ** I would appreciate receiving any updates/patches/changes that anyone
50 ** makes, and am willing to be the repository for said changes (am I
51 ** making a big mistake?).
52 **
53 ** Pat Wood
54 ** Pipeline Associates, Inc.
55 ** pipeline!phw@motown.com or
56 ** sun!pipeline!phw or
57 ** uunet!motown!pipeline!phw
58 */
59
60 /* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */
61
62 union float_long
63   {
64     float f;
65     long l;
66   };
67
68 /* subtract two floats */
69 float __fssub (float a1, float a2)
70 {
71   volatile union float_long fl1, fl2;
72
73   fl1.f = a1;
74   fl2.f = a2;
75
76   /* check for zero args */
77   if (!fl2.l)
78     return (fl1.f);
79   if (!fl1.l)
80     return (-fl2.f);
81
82   /* twiddle sign bit and add */
83   fl2.l ^= SIGNBIT;
84   return fl1.f + fl2.f; 
85 }
86
87 #endif