3 #include <linux/linkage.h>
6 # r3 : upper half of 64 bit word n
7 # r4 : lower half of 64 bit word n
9 # the reminder r of the division is to be stored to &__r and
10 # the quotient q is to be returned
14 st %r2,24(%r15) # store pointer to reminder for later
17 ltr %r2,%r5 # reload and test divisor
19 # divisor >= 0x80000000
22 slr %r1,%r2 # special case if last bit of d is set
23 brc 3,0f # (n/4) div (n/2) can overflow by 1
24 ahi %r0,-1 # trick: subtract n/2, then divide
25 0: dr %r0,%r2 # signed division
26 ahi %r1,1 # trick part 2: add 1 to the quotient
27 # now (n >> 2) = (d >> 1) * %r1 + %r0
29 nr %r3,%r1 # test last bit of q
31 alr %r0,%r2 # add (d>>1) to r
32 1: srl %r1,1 # q >>= 1
33 # now (n >> 2) = (d&-2) * %r1 + %r0
35 nr %r3,%r5 # test last bit of d
41 2: # now (n >> 2) = d * %r1 + %r0
44 brc 12,3f # overflow on r ?
48 nr %r3,%r4 # test next to last bit of n
51 4: clr %r0,%r5 # r >= d ?
55 # now (n >> 1) = d * %r1 + %r0
57 5: # divisor < 0x80000000
59 dr %r0,%r2 # signed division
60 # now (n >> 1) = d * %r1 + %r0
61 6: alr %r1,%r1 # q <<= 1
63 brc 12,7f # overflow on r ?
67 nr %r3,%r4 # isolate last bit of n
68 alr %r0,%r3 # r += (n & 1)
69 clr %r0,%r5 # r >= d ?
73 8: # now n = d * %r1 + %r0