Upload Tizen:Base source
[external/gmp.git] / mpn / x86_64 / aors_n.asm
1 dnl  AMD64 mpn_add_n, mpn_sub_n
2
3 dnl  Copyright 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4
5 dnl  This file is part of the GNU MP Library.
6
7 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl  it under the terms of the GNU Lesser General Public License as published
9 dnl  by the Free Software Foundation; either version 3 of the License, or (at
10 dnl  your option) any later version.
11
12 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 dnl  License for more details.
16
17 dnl  You should have received a copy of the GNU Lesser General Public License
18 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
19
20 include(`../config.m4')
21
22 C            cycles/limb
23 C K8,K9:         1.5
24 C K10:           1.5
25 C P4:            ?
26 C P6 core2:      4.9
27 C P6 corei7:
28 C P6 atom:       4
29
30 C The inner loop of this code is the result of running a code generation and
31 C optimization tool suite written by David Harvey and Torbjorn Granlund.
32
33 C INPUT PARAMETERS
34 define(`rp',    `%rdi')
35 define(`up',    `%rsi')
36 define(`vp',    `%rdx')
37 define(`n',     `%rcx')
38 define(`cy',    `%r8')          C (only for mpn_add_nc)
39
40 ifdef(`OPERATION_add_n', `
41         define(ADCSBB,        adc)
42         define(func,          mpn_add_n)
43         define(func_nc,       mpn_add_nc)')
44 ifdef(`OPERATION_sub_n', `
45         define(ADCSBB,        sbb)
46         define(func,          mpn_sub_n)
47         define(func_nc,       mpn_sub_nc)')
48
49 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
50
51 ASM_START()
52         TEXT
53         ALIGN(16)
54 PROLOGUE(func_nc)
55         mov     R32(n), R32(%rax)
56         and     $3, R32(%rax)
57         shr     $2, n
58         bt      $0, %r8                 C cy flag <- carry parameter
59         jz      L(1)
60         jmp     L(ent)
61 EPILOGUE()
62         ALIGN(16)
63 PROLOGUE(func)
64         mov     R32(n), R32(%rax)
65         shr     $2, n
66         jz      L(0)
67         and     $3, R32(%rax)
68
69 L(ent): mov     (up), %r8
70         mov     8(up), %r9
71         dec     n
72         jmp     L(mid)
73
74         ALIGN(16)
75 L(top): ADCSBB  (vp), %r8
76         ADCSBB  8(vp), %r9
77         ADCSBB  16(vp), %r10
78         ADCSBB  24(vp), %r11
79         mov     %r8, (rp)
80         lea     32(up), up
81         mov     %r9, 8(rp)
82         mov     %r10, 16(rp)
83         dec     n
84         mov     %r11, 24(rp)
85         lea     32(vp), vp
86         mov     (up), %r8
87         mov     8(up), %r9
88         lea     32(rp), rp
89 L(mid): mov     16(up), %r10
90         mov     24(up), %r11
91         jnz     L(top)
92
93 L(end): lea     32(up), up
94         ADCSBB  (vp), %r8
95         ADCSBB  8(vp), %r9
96         ADCSBB  16(vp), %r10
97         ADCSBB  24(vp), %r11
98         lea     32(vp), vp
99         mov     %r8, (rp)
100         mov     %r9, 8(rp)
101         mov     %r10, 16(rp)
102         mov     %r11, 24(rp)
103         lea     32(rp), rp
104
105         inc     R32(%rax)
106         dec     R32(%rax)
107         jnz     L(1)
108         adc     %eax, %eax
109         ret
110
111 L(0):   test    R32(%rax), R32(%rax)
112 L(1):   dec     R32(%rax)
113         mov     (up), %r8
114         jnz     L(2)
115         ADCSBB  (vp), %r8
116         mov     %r8, (rp)
117         adc     %eax, %eax
118         ret
119
120 L(2):   dec     R32(%rax)
121         mov     8(up), %r9
122         jnz     L(3)
123         ADCSBB  (vp), %r8
124         ADCSBB  8(vp), %r9
125         mov     %r8, (rp)
126         mov     %r9, 8(rp)
127         adc     %eax, %eax
128         ret
129
130 L(3):   mov     16(up), %r10
131         ADCSBB  (vp), %r8
132         ADCSBB  8(vp), %r9
133         ADCSBB  16(vp), %r10
134         mov     %r8, (rp)
135         mov     %r9, 8(rp)
136         mov     %r10, 16(rp)
137         setc    %al
138         ret
139 EPILOGUE()