110c5ea769e0459f5f9a4e67640fadc6159b9f0f
[firefly-linux-kernel-4.4.55.git] / arch / sh / lib / udivsi3-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         .global __udivsi3
45         .set    __udivsi3_i4, __udivsi3_i4i
46         .set    __udivsi3, __udivsi3_i4i
47         .type   __udivsi3_i4i, @function
48         .type   __sdivsi3_i4i, @function
49 __udivsi3_i4i:
50         sts pr,r1
51         mov.l r4,@-r15
52         extu.w r5,r0
53         cmp/eq r5,r0
54         swap.w r4,r0
55         shlr16 r4
56         bf/s large_divisor
57         div0u
58         mov.l r5,@-r15
59         shll16 r5
60 sdiv_small_divisor:
61         div1 r5,r4
62         bsr div6
63         div1 r5,r4
64         div1 r5,r4
65         bsr div6
66         div1 r5,r4
67         xtrct r4,r0
68         xtrct r0,r4
69         bsr div7
70         swap.w r4,r4
71         div1 r5,r4
72         bsr div7
73         div1 r5,r4
74         xtrct r4,r0
75         mov.l @r15+,r5
76         swap.w r0,r0
77         mov.l @r15+,r4
78         jmp @r1
79         rotcl r0
80 div7:
81         div1 r5,r4
82 div6:
83                     div1 r5,r4; div1 r5,r4; div1 r5,r4
84         div1 r5,r4; div1 r5,r4; rts;        div1 r5,r4
85
86 divx3:
87         rotcl r0
88         div1 r5,r4
89         rotcl r0
90         div1 r5,r4
91         rotcl r0
92         rts
93         div1 r5,r4
94
95 large_divisor:
96         mov.l r5,@-r15
97 sdiv_large_divisor:
98         xor r4,r0
99         .rept 4
100         rotcl r0
101         bsr divx3
102         div1 r5,r4
103         .endr
104         mov.l @r15+,r5
105         mov.l @r15+,r4
106         jmp @r1
107         rotcl r0
108
109         .global __sdivsi3_i4i
110         .global __sdivsi3_i4
111         .global __sdivsi3
112         .set    __sdivsi3_i4, __sdivsi3_i4i
113         .set    __sdivsi3, __sdivsi3_i4i
114 __sdivsi3_i4i:
115         mov.l r4,@-r15
116         cmp/pz r5
117         mov.l r5,@-r15
118         bt/s pos_divisor
119         cmp/pz r4
120         neg r5,r5
121         extu.w r5,r0
122         bt/s neg_result
123         cmp/eq r5,r0
124         neg r4,r4
125 pos_result:
126         swap.w r4,r0
127         bra sdiv_check_divisor
128         sts pr,r1
129 pos_divisor:
130         extu.w r5,r0
131         bt/s pos_result
132         cmp/eq r5,r0
133         neg r4,r4
134 neg_result:
135         mova negate_result,r0
136         ;
137         mov r0,r1
138         swap.w r4,r0
139         lds r2,macl
140         sts pr,r2
141 sdiv_check_divisor:
142         shlr16 r4
143         bf/s sdiv_large_divisor
144         div0u
145         bra sdiv_small_divisor
146         shll16 r5
147         .balign 4
148 negate_result:
149         neg r0,r0
150         jmp @r2
151         sts macl,r2