gen: encode 0xf0000000 as an immediate
[neatcc/cc.git] / div.s
blob23802fcded6183db06eeae0a6b9a548a42b8e308
1 @ ARM software division implementation
2 @ These functions are assembled using neatas and are included in gen.c
3 .global __udivdi3
4 __udivdi3:
5 mov r2, #0
6 mov r3, #0
8 @ zero divider
9 tst r1, r1
10 beq .end
12 @ shift the operand
13 .shl:
14 movs r12, r1, LSL r2
15 add r2, r2, #1
16 bpl .shl
18 mov r12, #1
20 @ the main division algorithm
21 .shr:
22 subs r2, r2, #1
23 bmi .end
24 cmps r0, r1, LSL r2
25 bcc .shr
26 sub r0, r0, r1, LSL r2
27 add r3, r3, r12, LSL r2
28 b .shr
29 .end:
30 mov r1, r0
31 mov r0, r3
32 mov pc, lr
34 .global __umoddi3
35 __umoddi3:
36 stmfd sp!, {lr}
37 bl __udivdi3
38 mov r0, r1
39 ldmfd sp!, {pc}
41 .global __divdi3
42 __divdi3:
43 stmfd sp!, {r4, r5, lr}
45 mov r4, r0
46 mov r5, r1
48 @ handle negative operands
49 tst r0, r0
50 rsbmi r0, r0, #0
51 tst r1, r1
52 rsbmi r1, r1, #0
54 bl __udivdi3
56 @ result is negative
57 teq r4, r5
58 rsbmi r0, r0, #0
59 tst r4, r4
60 rsbmi r1, r1, #0
62 ldmfd sp!, {r4, r5, pc}
64 .global __moddi3
65 __moddi3:
66 stmfd sp!, {lr}
67 bl __divdi3
68 mov r0, r1
69 ldmfd sp!, {pc}