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