4 # r3 : upper half of 64 bit word n
5 # r4 : lower half of 64 bit word n
7 # the reminder r of the division is to be stored to &__r and
8 # the quotient q is to be returned
13 st %r2,24(%r15) # store pointer to reminder for later
16 ltr %r2,%r5 # reload and test divisor
18 # divisor >= 0x80000000
21 slr %r1,%r2 # special case if last bit of d is set
22 brc 3,0f # (n/4) div (n/2) can overflow by 1
23 ahi %r0,-1 # trick: subtract n/2, then divide
24 0: dr %r0,%r2 # signed division
25 ahi %r1,1 # trick part 2: add 1 to the quotient
26 # now (n >> 2) = (d >> 1) * %r1 + %r0
28 nr %r3,%r1 # test last bit of q
30 alr %r0,%r2 # add (d>>1) to r
31 1: srl %r1,1 # q >>= 1
32 # now (n >> 2) = (d&-2) * %r1 + %r0
34 nr %r3,%r5 # test last bit of d
40 2: # now (n >> 2) = d * %r1 + %r0
43 brc 12,3f # overflow on r ?
47 nr %r3,%r4 # test next to last bit of n
50 4: clr %r0,%r5 # r >= d ?
54 # now (n >> 1) = d * %r1 + %r0
56 5: # divisor < 0x80000000
58 dr %r0,%r2 # signed division
59 # now (n >> 1) = d * %r1 + %r0
60 6: alr %r1,%r1 # q <<= 1
62 brc 12,7f # overflow on r ?
66 nr %r3,%r4 # isolate last bit of n
67 alr %r0,%r3 # r += (n & 1)
68 clr %r0,%r5 # r >= d ?
72 8: # now n = d * %r1 + %r0