2 .macro ARM_MOD_BODY dividend, divisor, order, spare
4 #if __LINUX_ARM_ARCH__ >= 5
8 sub \order, \order, \spare
9 mov \divisor, \divisor, lsl \order
15 @ Unless the divisor is very big, shift it up in multiples of
16 @ four bits, since this is the amount of unwinding in the main
17 @ division loop. Continue shifting until the divisor is
18 @ larger than the dividend.
19 1: cmp \divisor, #0x10000000
20 cmplo \divisor, \dividend
21 movlo \divisor, \divisor, lsl #4
22 addlo \order, \order, #4
25 @ For very big divisors, we must shift it a bit at a time, or
26 @ we will be in danger of overflowing.
27 1: cmp \divisor, #0x80000000
28 cmplo \divisor, \dividend
29 movlo \divisor, \divisor, lsl #1
30 addlo \order, \order, #1
35 @ Perform all needed substractions to keep only the reminder.
36 @ Do comparisons in batch of 4 first.
37 subs \order, \order, #3 @ yes, 3 is intended here
40 1: cmp \dividend, \divisor
41 subhs \dividend, \dividend, \divisor
42 cmp \dividend, \divisor, lsr #1
43 subhs \dividend, \dividend, \divisor, lsr #1
44 cmp \dividend, \divisor, lsr #2
45 subhs \dividend, \dividend, \divisor, lsr #2
46 cmp \dividend, \divisor, lsr #3
47 subhs \dividend, \dividend, \divisor, lsr #3
49 mov \divisor, \divisor, lsr #4
50 subges \order, \order, #4
57 @ Either 1, 2 or 3 comparison/substractions are left.
61 cmp \dividend, \divisor
62 subhs \dividend, \dividend, \divisor
63 mov \divisor, \divisor, lsr #1
64 3: cmp \dividend, \divisor
65 subhs \dividend, \dividend, \divisor
66 mov \divisor, \divisor, lsr #1
67 4: cmp \dividend, \divisor
68 subhs \dividend, \dividend, \divisor
77 rsbmi r1, r1, #0 @ loops below use unsigned.
78 movs ip, r0 @ preserve sign of dividend
79 rsbmi r0, r0, #0 @ if negative make positive
80 subs r2, r1, #1 @ compare divisor with 1
81 cmpne r0, r1 @ compare dividend with divisor
83 tsthi r1, r2 @ see if divisor is power of 2
87 ARM_MOD_BODY r0, r1, r2, r3
98 mov r0, #0 @ About as wrong as it could be.