1 dnl x86
-64 mpn_divrem_1
-- mpn by limb division.
3 dnl Copyright
2004, 2005, 2007-2012, 2014 Free Software Foundation
, Inc.
5 dnl
This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
8 dnl it under the terms of
either:
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.
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
20 dnl
or both
in parallel
, as here.
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
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
')
38 C Intel core2 24.5 24.5 19.5
39 C Intel corei 20.5 19.5 18
41 C VIA nano 25.5 25.5 24
44 C mpn_divrem_1 (mp_ptr qp, mp_size_t fn,
45 C mp_srcptr np, mp_size_t nn, mp_limb_t d)
48 C mpn_preinv_divrem_1 (mp_ptr qp, mp_size_t fn,
49 C mp_srcptr np, mp_size_t nn, mp_limb_t d,
50 C mp_limb_t dinv, int cnt)
54 define(`fn_param', `
%rsi
')
55 define(`up_param', `
%rdx
')
56 define(`un_param', `
%rcx
')
58 define(`dinv', `
%r9
') C only for mpn_preinv_divrem_1
59 C shift passed on stack C only for mpn_preinv_divrem_1
67 C rax rbx rcx rdx rsi rdi rbp r8 r9 r10 r11 r12 r13 r14 r15
73 IFSTD(`define(`CNTOFF', `
40($1)')')
74 IFDOS
(`define
(`CNTOFF
', `104($1)')')
79 PROLOGUE(mpn_preinv_divrem_1)
81 IFDOS(` mov 56(%rsp), %r8 ')
82 IFDOS
(`
mov 64(%rsp
), %r9
')
83 xor R32(%rax), R32(%rax)
91 add fn_param, un_param
94 lea -8(qp,un_param,8), qp
99 mov CNTOFF(%rsp), R8(cnt)
105 PROLOGUE(mpn_divrem_1)
107 IFDOS(` mov 56(%rsp), %r8 ')
108 xor R32
(%rax
), R32
(%rax
)
116 add fn_param
, un_param
120 lea -8(qp
,un_param
,8), qp
121 xor R32
(%rbp
), R32
(%rbp
)
129 mov -8(up
,un
,8), %rbp
134 sbb R32
(%rax
), R32
(%rax
)
142 IFSTD
(`
mov d
, %rdi
')
143 IFDOS(` sub $32, %rsp ')
144 IFDOS
(`
mov d
, %rcx
')
145 ASSERT(nz, `test $15, %rsp')
146 CALL( mpn_invert_limb
)
147 IFDOS
(`
add $32, %rsp
')
157 L(ntop):mov (up,un,8), %r10 C K8-K10 P6-CNR P6-NHM P4
158 mul dinv C 0,13 0,20 0,18 0,45
159 add %r10, %rax C 4 8 3 12
160 adc %rbp, %rdx C 5 9 10 13
161 mov %rax, %rbp C 5 9 4 13
162 mov %rdx, %r13 C 6 11 12 23
163 imul d, %rdx C 6 11 11 23
164 sub %rdx, %r10 C 10 16 14 33
166 add %r10, %rax C 11 17 15 34
167 cmp %rbp, %r10 C 11 17 15 34
168 cmovc %r10, %rax C 12 18 16 35
172 L(nok): mov %r13, (qp) C
174 L(nent):lea 1(%rax), %rbp C
178 xor R32(%rcx), R32(%rcx)
188 mov -8(up,un,8), %rax
206 IFSTD(` sub $8, %rsp ')
207 IFSTD
(`
mov d
, %rdi
')
208 IFDOS(` sub $40, %rsp ')
209 IFDOS
(`
mov d
, %rcx
')
210 ASSERT(nz, `test $15, %rsp')
211 CALL( mpn_invert_limb
)
212 IFSTD
(`
add $8, %rsp
')
213 IFDOS(` add $40, %rsp ')
233 L
(utop
):mov (up
,un
,8), %r10
253 L
(uok
): mov %r13
, (qp
)
255 L
(ent
): mov (up
,un
,8), %rbp
260 L
(uend
):shl R8
(%rcx
), %rbp
275 L
(eok
): mov %r13
, (qp
)
290 ALIGN(16) C K8
-K10 P6
-CNR P6
-NHM P4
291 L
(ftop
):mul dinv C
0,12 0,17 0,17
292 add %r11
, %rdx C
5 8 10
293 mov %rax
, %r11 C
4 8 3
294 mov %rdx
, %r13 C
6 9 11
295 imul
%rbp
, %rdx C
6 9 11
297 add %rdx
, %rax C
10 14 14
298 cmp %r11
, %rdx C
10 14 14
299 cmovc
%rdx
, %rax C
11 15 15
303 L
(fent
):lea 1(%rax
), %r11 C