c1e537309ec5f491b74517b292345c519ae11d95
[platform/upstream/gmp.git] / mpn / x86 / atom / sse2 / aorsmul_1.asm
1 dnl x86-32 mpn_addmul_1 and mpn_submul_1 optimised for Intel Atom.
2
3 dnl  Contributed to the GNU project by Torbjorn Granlund and Marco Bodrato.
4 dnl
5 dnl  Copyright 2011 Free Software Foundation, Inc.
6 dnl
7 dnl  This file is part of the GNU MP Library.
8 dnl
9 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU Lesser General Public License as published
11 dnl  by the Free Software Foundation; either version 3 of the License, or (at
12 dnl  your option) any later version.
13 dnl
14 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 dnl  License for more details.
18 dnl
19 dnl  You should have received a copy of the GNU Lesser General Public License
20 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22 include(`../config.m4')
23
24 C                           cycles/limb
25 C                           cycles/limb
26 C P5                             -
27 C P6 model 0-8,10-12             -
28 C P6 model 9  (Banias)
29 C P6 model 13 (Dothan)
30 C P4 model 0  (Willamette)
31 C P4 model 1  (?)
32 C P4 model 2  (Northwood)
33 C P4 model 3  (Prescott)
34 C P4 model 4  (Nocona)
35 C Intel Atom                     8
36 C AMD K6
37 C AMD K7                         -
38 C AMD K8
39 C AMD K10
40
41 define(`rp', `%edi')
42 define(`up', `%esi')
43 define(`n',  `%ecx')
44
45 ifdef(`OPERATION_addmul_1',`
46         define(ADDSUB,  add)
47         define(func_1,  mpn_addmul_1)
48         define(func_1c, mpn_addmul_1c)')
49 ifdef(`OPERATION_submul_1',`
50         define(ADDSUB,  sub)
51         define(func_1,  mpn_submul_1)
52         define(func_1c, mpn_submul_1c)')
53
54 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_addmul_1c mpn_submul_1 mpn_submul_1c)
55
56         TEXT
57         ALIGN(16)
58 PROLOGUE(func_1)
59         xor     %edx, %edx
60 L(ent): push    %edi
61         push    %esi
62         push    %ebx
63         mov     16(%esp), rp
64         mov     20(%esp), up
65         mov     24(%esp), n
66         movd    28(%esp), %mm7
67         test    $1, n
68         jz      L(fi0or2)
69         movd    (up), %mm0
70         pmuludq %mm7, %mm0
71         shr     $2, n
72         jnc     L(fi1)
73
74 L(fi3): lea     -8(up), up
75         lea     -8(rp), rp
76         movd    12(up), %mm1
77         movd    %mm0, %ebx
78         pmuludq %mm7, %mm1
79         add     $1, n                   C increment and clear carry
80         jmp     L(lo3)
81
82 L(fi1): movd    %mm0, %ebx
83         jz      L(wd1)
84         movd    4(up), %mm1
85         pmuludq %mm7, %mm1
86         jmp     L(lo1)
87
88 L(fi0or2):
89         movd    (up), %mm1
90         pmuludq %mm7, %mm1
91         shr     $2, n
92         movd    4(up), %mm0
93         jc      L(fi2)
94         lea     -4(up), up
95         lea     -4(rp), rp
96         movd    %mm1, %eax
97         pmuludq %mm7, %mm0
98         jmp     L(lo0)
99
100 L(fi2): lea     4(up), up
101         add     $1, n                   C increment and clear carry
102         movd    %mm1, %eax
103         lea     -12(rp), rp
104         jmp     L(lo2)
105
106 C       ALIGN(16)                       C alignment seems irrelevant
107 L(top): movd    4(up), %mm1
108         adc     $0, %edx
109         ADDSUB  %eax, 12(rp)
110         movd    %mm0, %ebx
111         pmuludq %mm7, %mm1
112         lea     16(rp), rp
113 L(lo1): psrlq   $32, %mm0
114         adc     %edx, %ebx
115         movd    %mm0, %edx
116         movd    %mm1, %eax
117         movd    8(up), %mm0
118         pmuludq %mm7, %mm0
119         adc     $0, %edx
120         ADDSUB  %ebx, (rp)
121 L(lo0): psrlq   $32, %mm1
122         adc     %edx, %eax
123         movd    %mm1, %edx
124         movd    %mm0, %ebx
125         movd    12(up), %mm1
126         pmuludq %mm7, %mm1
127         adc     $0, %edx
128         ADDSUB  %eax, 4(rp)
129 L(lo3): psrlq   $32, %mm0
130         adc     %edx, %ebx
131         movd    %mm0, %edx
132         movd    %mm1, %eax
133         lea     16(up), up
134         movd    (up), %mm0
135         adc     $0, %edx
136         ADDSUB  %ebx, 8(rp)
137 L(lo2): psrlq   $32, %mm1
138         adc     %edx, %eax
139         movd    %mm1, %edx
140         pmuludq %mm7, %mm0
141         dec     n
142         jnz     L(top)
143
144 L(end): adc     n, %edx                 C n is zero here
145         ADDSUB  %eax, 12(rp)
146         movd    %mm0, %ebx
147         lea     16(rp), rp
148 L(wd1): psrlq   $32, %mm0
149         adc     %edx, %ebx
150         movd    %mm0, %eax
151         adc     n, %eax
152         ADDSUB  %ebx, (rp)
153         emms
154         adc     n, %eax
155         pop     %ebx
156         pop     %esi
157         pop     %edi
158         ret
159 EPILOGUE()
160 PROLOGUE(func_1c)
161         mov     20(%esp), %edx          C carry
162         jmp     L(ent)
163 EPILOGUE()