Yes, we do need to delete m_op somehow.
[ipdf/code.git] / src / sub_digits_asm.S
1 .section .text
2 .globl sub_digits
3 .type sub_digits, @function
4
5 #ifdef __x86_64__
6
7 # Subtract two arrays of 64 bit digits, with carry, modifying the first argument
8 # Address at first argument %rdi is array to add and modify
9 # Address at second %rsi will be added (not modified)
10 # Third argument is counter of number of digits
11 # Result in %rax is the final result in the carry flag
12 # Exploits the fact that inc and dec do not affect the carry flag
13 sub_digits:
14         subq $0, %rax           # Reset the carry/borrow flag
15         loop:
16                 movq (%rsi), %rax # Temporarily store digit from second array
17                 sbbq %rax, (%rdi) # Subtract digits in second and first array, store in first
18                 dec %rdx # Decrement counter
19                 jz end_loop # We are done
20                 
21                 # Move to next element in the first array
22                 leaq 8(,%rdi,1), %rdi
23                 # Move to next element in the second array
24                 leaq 8(,%rsi,1), %rsi
25                 jmp loop # Repeat
26         end_loop:
27                 movq $0, %rax
28                 jnc end
29                 movq $1, %rax
30         end:
31                 ret # We are done
32
33 #else
34
35 sub_digits:
36         ret
37
38 #endif

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