From: David Gow Date: Sat, 5 Jul 2014 16:32:16 +0000 (+0800) Subject: This might help: divide an arbint by a uint64 X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=b0561967639ff158020b334433ac481a082480cc;hp=e4c05570709db2718a983c27322942769eab4c86;ds=sidebyside This might help: divide an arbint by a uint64 --- diff --git a/src/div_digits_asm.s b/src/div_digits_asm.s new file mode 100644 index 0000000..b11dd92 --- /dev/null +++ b/src/div_digits_asm.s @@ -0,0 +1,28 @@ +.section .text +.globl div_digits +.type div_digits, @function + +# div_digits(digits, div, size, res, rem) +# divides an arbint in digits by uint64 div into res with remainder rem +# Either res or rem may alias digits +# digits = rdi, div = rsx, size = rdx, res = rcx, rem = r8 +div_digits: + movq %rdx, %r9 + leaq -8(%rdi,%r9,8), %rdi # We want to point to the end of the buffer (LSB) + leaq -8(%rcx,%r9,8), %rcx # We want to point to the end of the buffer (LSB) + leaq -8(%r8,%r9,8), %r8 # We want to point to the end of the buffer (LSB) + movq $0, %rdx +loop: + movq (%rdi), %rax + divq %rsi # rdx:rax/rsi => rax, rdx:rax%rsi => rdx + movq %rax, (%rcx) + movq %rdx, (%r8) + dec %r9 + leaq -8(%rdi), %rdi + leaq -8(%rcx), %rcx + leaq -8(%r8), %r8 + jnz loop +end: + ret + +