5e7e7e90ae5870ab032262fc917a715250aed73c
[fw/sdcc] / device / lib / _fsrshift.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 static void dummy(void) _naked
26 {
27         _asm
28         .globl  fs_rshift_a
29 fs_rshift_a:
30         jz      00020$
31         mov     r0, a
32         add     a, exp_a        // adjust exponent
33         jnc     00001$
34         mov     a, #255         // don't roll over
35 00001$:
36         mov     exp_a, a
37 #ifdef FLOAT_SHIFT_SPEEDUP
38         mov     a, r0
39         add     a, #248
40         jnc     00003$
41         xch     a, r4
42         xch     a, r3
43         xch     a, r2
44         mov     r1, a
45         clr     a
46         xch     a, r4
47         //mov   r1, ar2         // avoid dependence on register bank
48         //mov   r2, ar3
49         //mov   r3, ar4
50         //mov   r4, #0
51         add     a, #248
52         jnc     00003$
53         xch     a, r3
54         xch     a, r2
55         mov     r1, a
56         clr     a
57         xch     a, r3
58         //mov   r1, ar2
59         //mov   r2, ar3
60         //mov   r3, #0
61         add     a, #248
62         jnc     00003$
63         xch     a, r2
64         mov     r1, a
65         clr     a
66         xch     a, r2
67         //mov   r1, ar2
68         //mov   r2, #0
69         add     a, #248
70         jnc     00003$
71         mov     r1, #0
72         ret
73 00003$:
74         add     a, #8
75         jz      00020$
76         mov     r0, a
77 #endif
78 00005$:
79         clr     c
80         mov     a, r4
81         rrc     a
82         mov     r4, a
83         mov     a, r3
84         rrc     a
85         mov     r3, a
86         mov     a, r2
87         rrc     a
88         mov     r2, a
89         mov     a, r1
90         rrc     a
91         mov     r1, a
92         djnz    r0, 00005$
93 00020$:
94         ret
95         _endasm;
96 }
97