Tizen 2.1 base
[external/gmp.git] / mpn / x86_64 / core2 / aorsmul_1.asm
1 dnl  x86-64 mpn_addmul_1 and mpn_submul_1, optimized for "Core 2".
2
3 dnl  Copyright 2003, 2004, 2005, 2007, 2008, 2009 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:         4
24 C K10:           4
25 C P4:            ?
26 C P6 core2:      4.3-4.5 (fluctuating)
27 C P6 corei7:     5
28
29 C INPUT PARAMETERS
30 define(`rp',    `%rdi')
31 define(`up',    `%rsi')
32 define(`n',     `%rdx')
33 define(`v0',    `%rcx')
34
35 ifdef(`OPERATION_addmul_1',`
36       define(`ADDSUB',        `add')
37       define(`func',  `mpn_addmul_1')
38 ')
39 ifdef(`OPERATION_submul_1',`
40       define(`ADDSUB',        `sub')
41       define(`func',  `mpn_submul_1')
42 ')
43
44 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
45
46 ASM_START()
47         TEXT
48         ALIGN(16)
49 PROLOGUE(func)
50         push    %rbx
51         push    %rbp
52         lea     (%rdx), %rbx
53         neg     %rbx
54
55         mov     (up), %rax
56         mov     (rp), %r10
57
58         lea     -16(rp,%rdx,8), rp
59         lea     (up,%rdx,8), up
60         mul     %rcx
61
62         bt      $0, R32(%rbx)
63         jc      L(odd)
64
65         lea     (%rax), %r11
66         mov     8(up,%rbx,8), %rax
67         lea     (%rdx), %rbp
68         mul     %rcx
69         add     $2, %rbx
70         jns     L(n2)
71
72         lea     (%rax), %r8
73         mov     (up,%rbx,8), %rax
74         lea     (%rdx), %r9
75         jmp     L(mid)
76
77 L(odd): add     $1, %rbx
78         jns     L(n1)
79
80         lea     (%rax), %r8
81         mov     (up,%rbx,8), %rax
82         lea     (%rdx), %r9
83         mul     %rcx
84         lea     (%rax), %r11
85         mov     8(up,%rbx,8), %rax
86         lea     (%rdx), %rbp
87         jmp     L(e)
88
89         ALIGN(16)
90 L(top): mul     %rcx
91         ADDSUB  %r8, %r10
92         lea     (%rax), %r8
93         mov     (up,%rbx,8), %rax
94         adc     %r9, %r11
95         mov     %r10, -8(rp,%rbx,8)
96         mov     (rp,%rbx,8), %r10
97         lea     (%rdx), %r9
98         adc     $0, %rbp
99 L(mid): mul     %rcx
100         ADDSUB  %r11, %r10
101         lea     (%rax), %r11
102         mov     8(up,%rbx,8), %rax
103         adc     %rbp, %r8
104         mov     %r10, (rp,%rbx,8)
105         mov     8(rp,%rbx,8), %r10
106         lea     (%rdx), %rbp
107         adc     $0, %r9
108 L(e):   add     $2, %rbx
109         js      L(top)
110
111         mul     %rcx
112         ADDSUB  %r8, %r10
113         adc     %r9, %r11
114         mov     %r10, -8(rp)
115         adc     $0, %rbp
116 L(n2):  mov     (rp), %r10
117         ADDSUB  %r11, %r10
118         adc     %rbp, %rax
119         mov     %r10, (rp)
120         adc     $0, %rdx
121 L(n1):  mov     8(rp), %r10
122         ADDSUB  %rax, %r10
123         mov     %r10, 8(rp)
124         mov     R32(%rbx), R32(%rax)    C zero rax
125         adc     %rdx, %rax
126         pop     %rbp
127         pop     %rbx
128         ret
129 EPILOGUE()