blob: 110c5ea769e0459f5f9a4e67640fadc6159b9f0f [file] [log] [blame]
Paul Mundt1aad54a2008-11-18 17:33:48 +09001/* Copyright (C) 2006 Free Software Foundation, Inc.
2
3This file is free software; you can redistribute it and/or modify it
4under the terms of the GNU General Public License as published by the
5Free Software Foundation; either version 2, or (at your option) any
6later version.
7
8In addition to the permissions in the GNU General Public License, the
9Free Software Foundation gives you unlimited permission to link the
10compiled version of this file into combinations with other programs,
11and to distribute those combinations without any restriction coming
12from the use of this file. (The General Public License restrictions
13do apply in other respects; for example, they cover modification of
14the file, and distribution when not linked into a combine
15executable.)
16
17This file is distributed in the hope that it will be useful, but
18WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; see the file COPYING. If not, write to
24the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25Boston, 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
Paul Mundt9ef10022008-11-20 15:26:35 +090043 .global __udivsi3_i4
Paul Mundt1aad54a2008-11-18 17:33:48 +090044 .global __udivsi3
Paul Mundt9ef10022008-11-20 15:26:35 +090045 .set __udivsi3_i4, __udivsi3_i4i
Paul Mundt1aad54a2008-11-18 17:33:48 +090046 .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
60sdiv_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
80div7:
81 div1 r5,r4
82div6:
83 div1 r5,r4; div1 r5,r4; div1 r5,r4
84 div1 r5,r4; div1 r5,r4; rts; div1 r5,r4
85
86divx3:
87 rotcl r0
88 div1 r5,r4
89 rotcl r0
90 div1 r5,r4
91 rotcl r0
92 rts
93 div1 r5,r4
94
95large_divisor:
96 mov.l r5,@-r15
97sdiv_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
Paul Mundt9ef10022008-11-20 15:26:35 +0900110 .global __sdivsi3_i4
Paul Mundt1aad54a2008-11-18 17:33:48 +0900111 .global __sdivsi3
Paul Mundt9ef10022008-11-20 15:26:35 +0900112 .set __sdivsi3_i4, __sdivsi3_i4i
Paul Mundt1aad54a2008-11-18 17:33:48 +0900113 .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
125pos_result:
126 swap.w r4,r0
127 bra sdiv_check_divisor
128 sts pr,r1
129pos_divisor:
130 extu.w r5,r0
131 bt/s pos_result
132 cmp/eq r5,r0
133 neg r4,r4
134neg_result:
135 mova negate_result,r0
136 ;
137 mov r0,r1
138 swap.w r4,r0
139 lds r2,macl
140 sts pr,r2
141sdiv_check_divisor:
142 shlr16 r4
143 bf/s sdiv_large_divisor
144 div0u
145 bra sdiv_small_divisor
146 shll16 r5
147 .balign 4
148negate_result:
149 neg r0,r0
150 jmp @r2
151 sts macl,r2