191bf2eb29dd0b3045fd2ad2b327c234247c6b74
[linux-libre-firmware.git] / carl9170fw / carlfw / src / udivsi3_i4i-Os.S
1 /* Copyright (C) 2006 Free Software Foundation, Inc.
2
3 This file is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 In addition to the permissions in the GNU General Public License, the
9 Free Software Foundation gives you unlimited permission to link the
10 compiled version of this file into combinations with other programs,
11 and to distribute those combinations without any restriction coming
12 from the use of this file.  (The General Public License restrictions
13 do apply in other respects; for example, they cover modification of
14 the file, and distribution when not linked into a combine
15 executable.)
16
17 This file is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING.  If not, write to
24 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.  */
26
27 /* Moderately Space-optimized libgcc routines for the Renesas SH /
28    STMicroelectronics ST40 CPUs.
29    Contributed by J"orn Rennecke joern.rennecke@st.com.  */
30
31 /* Size: 186 bytes jointly for udivsi3_i4i and sdivsi3_i4i
32    sh4-200 run times:
33    udiv small divisor: 55 cycles
34    udiv large divisor: 52 cycles
35    sdiv small divisor, positive result: 59 cycles
36    sdiv large divisor, positive result: 56 cycles
37    sdiv small divisor, negative result: 65 cycles (*)
38    sdiv large divisor, negative result: 62 cycles (*)
39    (*): r2 is restored in the rts delay slot and has a lingering latency
40         of two more cycles.  */
41         .balign 4
42         .global ___udivsi3_i4i
43         .global ___udivsi3_i4
44         .set    ___udivsi3_i4, ___udivsi3_i4i
45 ___udivsi3_i4i:
46         sts pr,r1
47         mov.l r4,@-r15
48         extu.w r5,r0
49         cmp/eq r5,r0
50         swap.w r4,r0
51         shlr16 r4
52         bf/s large_divisor
53         div0u
54         mov.l r5,@-r15
55         shll16 r5
56 sdiv_small_divisor:
57         div1 r5,r4
58         bsr div6
59         div1 r5,r4
60         div1 r5,r4
61         bsr div6
62         div1 r5,r4
63         xtrct r4,r0
64         xtrct r0,r4
65         bsr div7
66         swap.w r4,r4
67         div1 r5,r4
68         bsr div7
69         div1 r5,r4
70         xtrct r4,r0
71         mov.l @r15+,r5
72         swap.w r0,r0
73         mov.l @r15+,r4
74         jmp @r1
75         rotcl r0
76 div7:
77         div1 r5,r4
78 div6:
79                     div1 r5,r4; div1 r5,r4; div1 r5,r4
80         div1 r5,r4; div1 r5,r4; rts;        div1 r5,r4
81
82 divx3:
83         rotcl r0
84         div1 r5,r4
85         rotcl r0
86         div1 r5,r4
87         rotcl r0
88         rts
89         div1 r5,r4
90
91 large_divisor:
92         mov.l r5,@-r15
93 sdiv_large_divisor:
94         xor r4,r0
95         .rept 4
96         rotcl r0
97         bsr divx3
98         div1 r5,r4
99         .endr
100         mov.l @r15+,r5
101         mov.l @r15+,r4
102         jmp @r1
103         rotcl r0
104
105         .global __sdivsi3_i4i
106         .global __sdivsi3_i4
107         .global __sdivsi3
108         .set    __sdivsi3_i4, __sdivsi3_i4i
109         .set    __sdivsi3, __sdivsi3_i4i
110 __sdivsi3_i4i:
111         mov.l r4,@-r15
112         cmp/pz r5
113         mov.l r5,@-r15
114         bt/s pos_divisor
115         cmp/pz r4
116         neg r5,r5
117         extu.w r5,r0
118         bt/s neg_result
119         cmp/eq r5,r0
120         neg r4,r4
121 pos_result:
122         swap.w r4,r0
123         bra sdiv_check_divisor
124         sts pr,r1
125 pos_divisor:
126         extu.w r5,r0
127         bt/s pos_result
128         cmp/eq r5,r0
129         neg r4,r4
130 neg_result:
131         mova negate_result,r0
132         ;
133         mov r0,r1
134         swap.w r4,r0
135         lds r2,macl
136         sts pr,r2
137 sdiv_check_divisor:
138         shlr16 r4
139         bf/s sdiv_large_divisor
140         div0u
141         bra sdiv_small_divisor
142         shll16 r5
143         .balign 4
144 negate_result:
145         neg r0,r0
146         jmp @r2
147         sts macl,r2