Inflict Qt4 upon the codebase
[ipdf/code.git] / src / mul_digits_asm.S
1 .section .text
2 .globl mul_digits
3 .type mul_digits, @function
4
5 #ifdef __x86_64__
6
7 # Multiply an array of 64 bit digits by *one* 64 bit digit, modifies the array in place
8 mul_digits:
9         movq %rdx, %rcx # rdx is reserved for mulq, use rcx as counter
10         movq $0, %r12 # Overflow register
11         loop:
12                 movq %rsi, %rax # Value to multiply in %rax
13                 mulq (%rdi) # Multiply, stored in %rdx:%rax (ie: we get TWO digits)
14                 
15                 # Add overflow from previous operation
16                 add %r12, %rax
17                 # Upper digit gets saved as next overflow
18                 movq %rdx, %r12
19                 
20                 # Lower digit goes in current array position
21                 movq %rax, (%rdi)
22                 
23                 dec %rcx # Decrement counter
24                 jz end_loop # We are done
25                 
26                 # Move to next element in the array
27                 leaq 8(,%rdi,1), %rdi
28                 jmp loop # Repeat
29                 
30         end_loop:
31         end:
32                 movq %r12, %rax # Return overflow
33                 ret # We are done
34
35 #else
36
37 mul_digits:
38         ret
39
40 #endif

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