Merge branch 'master' of git.ucc.asn.au:/ipdf/code
[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)
6 # divides an arbint in digits by uint64 div into res, returns remainder
7 # res may alias digits
8 # digits = rdi, div = rsx, size = rdx, res = rcx,
9 div_digits:
10         movq %rdx, %r8
11         leaq -8(%rdi,%r8,8), %rdi       # We want to point to the end of the buffer (LSB)
12         leaq -8(%rcx,%r8,8), %rcx       # We want to point to the end of the buffer (LSB)
13         movq $0, %rdx
14 loop:
15         movq (%rdi), %rax
16         divq %rsi                       # rdx:rax/rsi => rax, rdx:rax%rsi => rdx
17         movq %rax, (%rcx)
18         dec %r8
19         leaq -8(%rdi), %rdi
20         leaq -8(%rcx), %rcx
21         jnz loop
22 end:
23         movq %rdx, %rax                 # return the remainder
24         ret
25         
26         

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