b11dd92ce1b0ae669bcf8d977b45d17e1b860a8a
[ipdf/code.git] / src / div_digits_asm.s
1 .section .text
2 .globl div_digits
3 .type div_digits, @function
4
5 # div_digits(digits, div, size, res, rem)
6 # divides an arbint in digits by uint64 div into res with remainder rem
7 # Either res or rem may alias digits
8 # digits = rdi, div = rsx, size = rdx, res = rcx, rem = r8
9 div_digits:
10         movq %rdx, %r9
11         leaq -8(%rdi,%r9,8), %rdi       # We want to point to the end of the buffer (LSB)
12         leaq -8(%rcx,%r9,8), %rcx       # We want to point to the end of the buffer (LSB)
13         leaq -8(%r8,%r9,8), %r8         # We want to point to the end of the buffer (LSB)
14         movq $0, %rdx
15 loop:
16         movq (%rdi), %rax
17         divq %rsi                       # rdx:rax/rsi => rax, rdx:rax%rsi => rdx
18         movq %rax, (%rcx)
19         movq %rdx, (%r8)
20         dec %r9
21         leaq -8(%rdi), %rdi
22         leaq -8(%rcx), %rcx
23         leaq -8(%r8), %r8
24         jnz loop
25 end:
26         ret
27         
28         

UCC git Repository :: git.ucc.asn.au