Debian Codegraph @

libgcc/config/or1k/lib1funcs.S

raw
1 /* Copyright (C) 2018-2025 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 3, or (at your option) any
6 later version.
7
8 This file is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 Under Section 7 of GPL version 3, you are granted additional
14 permissions described in the GCC Runtime Library Exception, version
15 3.1, as published by the Free Software Foundation.
16
17 You should have received a copy of the GNU General Public License and
18 a copy of the GCC Runtime Library Exception along with this program;
19 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
20 <http://www.gnu.org/licenses/>. */
21
22 /* An executable stack is *not* required for these functions. */
23 #ifdef __linux__
24 .section .note.GNU-stack,"",%progbits
25 .previous
26 #endif
27
28 #ifdef L__mulsi3
29 .balign 4
30 .globl __mulsi3
31 .type __mulsi3, @function
32 __mulsi3:
33 l.movhi r11, 0 /* initial r */
34
35 /* Given R = X * Y ... */
36 1: l.sfeq r4, r0 /* while (y != 0) */
37 l.bf 2f
38 l.andi r5, r4, 1 /* if (y & 1) ... */
39 l.add r12, r11, r3
40 l.sfne r5, r0
41 #if defined(__or1k_cmov__)
42 l.cmov r11, r12, r11 /* ... r += x. */
43 l.srli r4, r4, 1 /* y >>= 1 */
44 #else
45 l.bnf 3f
46 l.srli r4, r4, 1 /* y >>= 1 */
47 l.ori r11, r12, 0
48 3:
49 #endif
50 l.j 1b
51 l.add r3, r3, r3 /* x <<= 1 */
52
53 2: l.jr r9
54 l.nop
55
56 .size __mulsi3, . - __mulsi3
57 #endif
58
59 #if defined(L__udivsi3) || defined(L__umodsi3) \
60 || defined(L__divsi3) || defined(L__modsi3)
61 .global __udivmodsi3_internal
62 .hidden __udivmodsi3_internal
63 .type __udivmodsi3_internal, @function
64 #endif
65
66 #ifdef L__udivsi3
67 .balign 4
68 .global __udivsi3
69 .type __udivsi3, @function
70 __udivsi3:
71 __udivmodsi3_internal:
72 /* Note that the other division routines assume that r13
73 is not clobbered by this routine, and use that as to
74 save a return address without creating a stack frame. */
75
76 l.sfeq r4, r0 /* division by zero; return 0. */
77 l.ori r11, r0, 0 /* initial quotient */
78 l.bf 9f
79 l.ori r12, r3, 0 /* initial remainder */
80
81 /* Given X/Y, shift Y left until Y >= X. */
82 l.ori r6, r0, 1 /* mask = 1 */
83 1: l.sflts r4, r0 /* y has msb set */
84 l.bf 2f
85 l.sfltu r4, r12 /* y < x */
86 l.add r4, r4, r4 /* y <<= 1 */
87 l.bf 1b
88 l.add r6, r6, r6 /* mask <<= 1 */
89
90 /* Shift Y back to the right again, subtracting from X. */
91 2: l.add r7, r11, r6 /* tmp1 = quot + mask */
92 3: l.srli r6, r6, 1 /* mask >>= 1 */
93 l.sub r8, r12, r4 /* tmp2 = x - y */
94 l.sfleu r4, r12 /* y <= x */
95 l.srli r4, r4, 1 /* y >>= 1 */
96 #if defined(__or1k_cmov__)
97 l.cmov r11, r7, r11 /* if (y <= x) quot = tmp1 */
98 l.cmov r12, r8, r12 /* if (y <= x) x = tmp2 */
99 #else
100 l.bnf 4f
101 l.nop
102 l.ori r11, r7, 0
103 l.ori r12, r8, 0
104 4:
105 #endif
106 l.sfne r6, r0 /* loop until mask == 0 */
107 l.bf 3b
108 l.add r7, r11, r6 /* delay fill from loop start */
109
110 9: l.jr r9
111 l.nop
112
113 .size __udivsi3, . - __udivsi3
114 .size __udivmodsi3_internal, . - __udivmodsi3_internal
115 #endif
116
117 #ifdef L__umodsi3
118 .balign 4
119 .global __umodsi3
120 .type __umodsi3, @function
121 .cfi_startproc
122 __umodsi3:
123 /* Know that __udivmodsi3_internal does not clobber r13. */
124 l.ori r13, r9, 0
125 .cfi_register 9, 13
126 l.jal __udivmodsi3_internal
127 l.nop
128 l.jr r13 /* return to saved lr */
129 l.ori r11, r12, 0 /* move remainder to rv */
130
131 .cfi_endproc
132 .size __umodsi3, . - __umodsi3
133 #endif
134
135 /* For signed division we do:
136
137 -x / y = x / -y = -(x / y)
138 -x % y = -(x % y)
139 x % -y = x % y
140
141 which has the property that (x/y)*y + (x%y) = x. */
142
143 #ifdef L__divsi3
144 .balign 4
145 .global __divsi3
146 .type __divsi3, @function
147 .cfi_startproc
148 __divsi3:
149 l.xor r6, r3, r4 /* need result negate? */
150
151 l.sflts r3, r0 /* abs(x) */
152 #if defined(__or1k_cmov__)
153 l.sub r5, r0, r3
154 l.cmov r3, r5, r3
155 #else
156 l.bnf 1f
157 l.sub r5, r0, r3
158 l.ori r3, r5, 0
159 1:
160 #endif
161 l.sflts r4, r0 /* abs(y) */
162 #if defined(__or1k_cmov__)
163 l.sub r5, r0, r4
164 l.cmov r4, r5, r4
165 #else
166 l.bnf 2f
167 l.sub r5, r0, r4
168 l.ori r4, r5, 0
169 2:
170 #endif
171
172 /* If the result will not require sign flip, tail call. */
173 l.sflts r6, r0
174 l.bnf __udivmodsi3_internal
175 l.ori r13, r9, 0 /* save lr */
176
177 /* Otherwise, know that __udivmodsi3_internal does not clobber r13.
178 Perform a normal call, then negate and return via saved lr. */
179 .cfi_register 9, 13
180 l.jal __udivmodsi3_internal
181 l.nop
182 l.jr r13
183 l.sub r11, r0, r11
184
185 .cfi_endproc
186 .size __divsi3, . - __divsi3
187 #endif
188
189 #ifdef L__modsi3
190 .balign 4
191 .global __modsi3
192 .type __modsi3, @function
193 .cfi_startproc
194 __modsi3:
195 l.sflts r4, r0 /* abs(y) */
196 #if defined(__or1k_cmov__)
197 l.sub r5, r0, r4
198 l.cmov r4, r5, r4
199 #else
200 l.bnf 2f
201 l.sub r5, r0, r4
202 l.ori r4, r5, 0
203 2:
204 #endif
205
206 l.sflts r3, r0 /* x negative? */
207 l.bf 1f
208 l.ori r13, r9, 0 /* save lr */
209
210 /* Know that __udivmodsi3_internal does not clobber r13. */
211 .cfi_register 9, 13
212
213 /* X positive; no negate of the result required. */
214 l.jal __udivmodsi3_internal
215 l.nop
216 l.jr r13 /* return to saved lr */
217 l.ori r11, r12, 0 /* move remainder to rv */
218
219 /* X negative; negate both X and the result. */
220 1: l.jal __udivmodsi3_internal
221 l.sub r3, r0, r3
222 l.jr r13 /* return to saved lr */
223 l.sub r11, r0, r12 /* negate remainder to rv */
224
225 .cfi_endproc
226 .size __modsi3, .- __modsi3
227 #endif