1 /* $NetBSD: divsi3.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */
4 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
8 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
11 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
17 #include <machine/asm.h>
20 * stack is aligned as there's a possibility of branching to .L_overflow
21 * which makes a C call
26 sub sp, sp, #4 /* align stack */
28 add sp, sp, #4 /* unalign stack */
34 sub sp, sp, #4 /* align stack */
36 add sp, sp, #4 /* unalign stack */
41 #if !defined(_KERNEL) && !defined(_STANDALONE)
42 mov r0, #8 /* SIGFPE */
43 bl PIC_SYM(_C_LABEL(raise), PLT) /* raise it */
46 /* XXX should cause a fatal error */
52 .L_udivide: /* r0 = r0 / r1; r1 = r0 % r1 */
56 /* r0 = r1 / r0; r1 = r1 % r0 */
63 orr ip, ip, #0x20000000 /* ip bit 0x20000000 = -ve r1 */
65 orrcs ip, ip, #0x10000000 /* ip bit 0x10000000 = bit 0 of r1 */
68 .L_divide_l0: /* r0 == 1 */
74 .L_divide: /* r0 = r0 / r1; r1 = r0 % r1 */
78 /* r0 = r1 / r0; r1 = r1 % r0 */
82 ands ip, r0, #0x80000000
84 ands r2, r1, #0x80000000
87 orr ip, r2, ip, lsr #1 /* ip bit 0x40000000 = -ve division */
88 /* ip bit 0x80000000 = -ve remainder */
95 * If the highest bit of the dividend is set, we have to be
96 * careful when shifting the divisor. Test this.
102 * At this point, the highest bit of r1 is known to be set.
103 * We abuse this below in the tst instructions.
105 tst r1, r0 /*, lsl #0 */
169 * tst r1, r0, lsl #31
239 subhs r1, r1,r0, lsl #31
240 addhs r3, r3,r2, lsl #31
243 subhs r1, r1,r0, lsl #30
244 addhs r3, r3,r2, lsl #30
247 subhs r1, r1,r0, lsl #29
248 addhs r3, r3,r2, lsl #29
251 subhs r1, r1,r0, lsl #28
252 addhs r3, r3,r2, lsl #28
255 subhs r1, r1,r0, lsl #27
256 addhs r3, r3,r2, lsl #27
259 subhs r1, r1,r0, lsl #26
260 addhs r3, r3,r2, lsl #26
263 subhs r1, r1,r0, lsl #25
264 addhs r3, r3,r2, lsl #25
267 subhs r1, r1,r0, lsl #24
268 addhs r3, r3,r2, lsl #24
271 subhs r1, r1,r0, lsl #23
272 addhs r3, r3,r2, lsl #23
275 subhs r1, r1,r0, lsl #22
276 addhs r3, r3,r2, lsl #22
279 subhs r1, r1,r0, lsl #21
280 addhs r3, r3,r2, lsl #21
283 subhs r1, r1,r0, lsl #20
284 addhs r3, r3,r2, lsl #20
287 subhs r1, r1,r0, lsl #19
288 addhs r3, r3,r2, lsl #19
291 subhs r1, r1,r0, lsl #18
292 addhs r3, r3,r2, lsl #18
295 subhs r1, r1,r0, lsl #17
296 addhs r3, r3,r2, lsl #17
299 subhs r1, r1,r0, lsl #16
300 addhs r3, r3,r2, lsl #16
303 subhs r1, r1,r0, lsl #15
304 addhs r3, r3,r2, lsl #15
307 subhs r1, r1,r0, lsl #14
308 addhs r3, r3,r2, lsl #14
311 subhs r1, r1,r0, lsl #13
312 addhs r3, r3,r2, lsl #13
315 subhs r1, r1,r0, lsl #12
316 addhs r3, r3,r2, lsl #12
319 subhs r1, r1,r0, lsl #11
320 addhs r3, r3,r2, lsl #11
323 subhs r1, r1,r0, lsl #10
324 addhs r3, r3,r2, lsl #10
327 subhs r1, r1,r0, lsl #9
328 addhs r3, r3,r2, lsl #9
331 subhs r1, r1,r0, lsl #8
332 addhs r3, r3,r2, lsl #8
335 subhs r1, r1,r0, lsl #7
336 addhs r3, r3,r2, lsl #7
339 subhs r1, r1,r0, lsl #6
340 addhs r3, r3,r2, lsl #6
343 subhs r1, r1,r0, lsl #5
344 addhs r3, r3,r2, lsl #5
347 subhs r1, r1,r0, lsl #4
348 addhs r3, r3,r2, lsl #4
351 subhs r1, r1,r0, lsl #3
352 addhs r3, r3,r2, lsl #3
355 subhs r1, r1,r0, lsl #2
356 addhs r3, r3,r2, lsl #2
359 subhs r1, r1,r0, lsl #1
360 addhs r3, r3,r2, lsl #1
373 bicmi r0, r0, #0x80000000 /* Fix incase we divided 0x80000000 */