Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / _fsreturnval.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
21 #define SDCC_FLOAT_LIB
22 #include <float.h>
23
24
25 #ifdef FLOAT_ASM_MCS51
26
27 static void dummy(void) __naked
28 {
29         __asm
30
31         .globl  fs_round_and_return
32 fs_round_and_return:
33 #ifdef FLOAT_FULL_ACCURACY
34         // discard the extra 8 bits of precision we kept around in r1
35         cjne    r1, #128, 00001$
36         mov     a, r2
37         rrc     a
38         cpl     c
39 00001$:
40         jc      fs_zerocheck_return
41         mov     a, r2
42         add     a, #1
43         mov     r2, a
44         clr     a
45         addc    a, r3
46         mov     r3, a
47         clr     a
48         addc    a, r4
49         mov     r4, a
50         jnc     fs_zerocheck_return
51         mov     r4, #0x80
52         inc     exp_a
53 #endif
54
55         .globl  fs_zerocheck_return
56 fs_zerocheck_return:
57         // zero output is a special case
58         cjne    r4, #0, fs_direct_return
59         cjne    r3, #0, fs_direct_return
60         cjne    r2, #0, fs_direct_return
61
62         .globl  fs_return_zero
63 fs_return_zero:
64         clr     a
65         mov     b, a
66         mov     dph, a
67         mov     dpl, a
68         ret
69
70         .globl  fs_direct_return
71 fs_direct_return:
72         // collect all pieces and return
73         mov     c, sign_a
74         mov     a, exp_a
75         rrc     a
76         mov     b, r4
77         mov     b.7, c
78         mov     dph, r3
79         mov     dpl, r2
80         ret
81
82         .globl  fs_return_inf
83 fs_return_inf:
84         clr     a
85         mov     dph, a
86         mov     dpl, a
87         mov     b, #0x80
88         cpl     a
89         mov     c, sign_a
90         rrc     a
91         ret
92
93         .globl  fs_return_nan
94 fs_return_nan:
95         clr     a
96         mov     dph, a
97         mov     dpl, a
98         mov     b, #0xC0
99         mov     a, #0x7F
100         ret
101
102         __endasm;
103 }
104
105 #endif