beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / x86_64 / coreisbr / rsh1aors_n.asm
blobfd2eaea7bb96a809e103f864bfc4b2142ab6e3b8
1 dnl X86-64 mpn_rsh1add_n, mpn_rsh1sub_n optimised for Intel Sandy Bridge.
3 dnl Copyright 2003, 2005, 2009-2012 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
6 dnl
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of either:
9 dnl
10 dnl * the GNU Lesser General Public License as published by the Free
11 dnl Software Foundation; either version 3 of the License, or (at your
12 dnl option) any later version.
13 dnl
14 dnl or
15 dnl
16 dnl * the GNU General Public License as published by the Free Software
17 dnl Foundation; either version 2 of the License, or (at your option) any
18 dnl later version.
19 dnl
20 dnl or both in parallel, as here.
21 dnl
22 dnl The GNU MP Library is distributed in the hope that it will be useful, but
23 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 dnl for more details.
26 dnl
27 dnl You should have received copies of the GNU General Public License and the
28 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29 dnl see https://www.gnu.org/licenses/.
31 include(`../config.m4')
34 C cycles/limb
35 C AMD K8,K9 ?
36 C AMD K10 4.25
37 C Intel P4 21.5
38 C Intel core2 3.2
39 C Intel NHM 3.87
40 C Intel SBR 2.05
41 C Intel atom ?
42 C VIA nano 44.9
44 C INPUT PARAMETERS
45 define(`rp', `%rdi')
46 define(`up', `%rsi')
47 define(`vp', `%rdx')
48 define(`n', `%rcx')
50 ifdef(`OPERATION_rsh1add_n', `
51 define(ADDSUB, add)
52 define(ADCSBB, adc)
53 define(func_n, mpn_rsh1add_n)
54 define(func_nc, mpn_rsh1add_nc)')
55 ifdef(`OPERATION_rsh1sub_n', `
56 define(ADDSUB, sub)
57 define(ADCSBB, sbb)
58 define(func_n, mpn_rsh1sub_n)
59 define(func_nc, mpn_rsh1sub_nc)')
61 MULFUNC_PROLOGUE(mpn_rsh1add_n mpn_rsh1add_nc mpn_rsh1sub_n mpn_rsh1sub_nc)
63 ABI_SUPPORT(DOS64)
64 ABI_SUPPORT(STD64)
66 ASM_START()
67 TEXT
69 ALIGN(16)
70 PROLOGUE(func_nc)
71 FUNC_ENTRY(4)
72 IFDOS(` mov 56(%rsp), %r8 ')
73 push %rbx
74 push %rbp
76 neg %r8 C set C flag from parameter
77 mov (up), %rbp
78 ADCSBB (vp), %rbp
80 jmp L(ent)
81 EPILOGUE()
83 ALIGN(16)
84 PROLOGUE(func_n)
85 FUNC_ENTRY(4)
86 push %rbx
87 push %rbp
89 mov (up), %rbp
90 ADDSUB (vp), %rbp
91 L(ent):
92 sbb R32(%rbx), R32(%rbx) C save cy
93 mov R32(%rbp), R32(%rax)
94 and $1, R32(%rax) C return value
96 mov R32(n), R32(%r11)
97 and $3, R32(%r11)
99 cmp $1, R32(%r11)
100 je L(do) C jump if n = 1 5 9 ...
102 L(n1): cmp $2, R32(%r11)
103 jne L(n2) C jump unless n = 2 6 10 ...
104 add R32(%rbx), R32(%rbx) C restore cy
105 mov 8(up), %r10
106 ADCSBB 8(vp), %r10
107 lea 8(up), up
108 lea 8(vp), vp
109 lea 8(rp), rp
110 sbb R32(%rbx), R32(%rbx) C save cy
112 shrd $1, %r10, %rbp
113 mov %rbp, -8(rp)
114 jmp L(cj1)
116 L(n2): cmp $3, R32(%r11)
117 jne L(n3) C jump unless n = 3 7 11 ...
118 add R32(%rbx), R32(%rbx) C restore cy
119 mov 8(up), %r9
120 mov 16(up), %r10
121 ADCSBB 8(vp), %r9
122 ADCSBB 16(vp), %r10
123 lea 16(up), up
124 lea 16(vp), vp
125 lea 16(rp), rp
126 sbb R32(%rbx), R32(%rbx) C save cy
128 shrd $1, %r9, %rbp
129 mov %rbp, -16(rp)
130 jmp L(cj2)
132 L(n3): dec n C come here for n = 4 8 12 ...
133 add R32(%rbx), R32(%rbx) C restore cy
134 mov 8(up), %r8
135 mov 16(up), %r9
136 ADCSBB 8(vp), %r8
137 ADCSBB 16(vp), %r9
138 mov 24(up), %r10
139 ADCSBB 24(vp), %r10
140 lea 24(up), up
141 lea 24(vp), vp
142 lea 24(rp), rp
143 sbb R32(%rbx), R32(%rbx) C save cy
145 shrd $1, %r8, %rbp
146 mov %rbp, -24(rp)
147 shrd $1, %r9, %r8
148 mov %r8, -16(rp)
149 L(cj2): shrd $1, %r10, %r9
150 mov %r9, -8(rp)
151 L(cj1): mov %r10, %rbp
153 L(do):
154 shr $2, n C 4
155 je L(end) C 2
156 ALIGN(16)
157 L(top): add R32(%rbx), R32(%rbx) C restore cy
159 mov 8(up), %r8
160 mov 16(up), %r9
161 ADCSBB 8(vp), %r8
162 ADCSBB 16(vp), %r9
163 mov 24(up), %r10
164 mov 32(up), %r11
165 ADCSBB 24(vp), %r10
166 ADCSBB 32(vp), %r11
168 lea 32(up), up
169 lea 32(vp), vp
171 sbb R32(%rbx), R32(%rbx) C save cy
173 shrd $1, %r8, %rbp
174 mov %rbp, (rp)
175 shrd $1, %r9, %r8
176 mov %r8, 8(rp)
177 shrd $1, %r10, %r9
178 mov %r9, 16(rp)
179 shrd $1, %r11, %r10
180 mov %r10, 24(rp)
182 dec n
183 mov %r11, %rbp
184 lea 32(rp), rp
185 jne L(top)
187 L(end): shrd $1, %rbx, %rbp
188 mov %rbp, (rp)
189 pop %rbp
190 pop %rbx
191 FUNC_EXIT()
193 EPILOGUE()