1 dnl x86 mpn_gcd_1 optimised for processors with fast
BSF.
3 dnl Based on the K7 gcd_1.asm
, by Kevin Ryde. Rehacked by Torbjorn Granlund.
5 dnl Copyright
2000-2002, 2005, 2009, 2011, 2012, 2015 Free Software
8 dnl
This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
11 dnl it under the terms of
either:
13 dnl
* the GNU Lesser General
Public License as published by the Free
14 dnl Software Foundation
; either version 3 of the License, or (at your
15 dnl option
) any later version.
19 dnl
* the GNU General
Public License as published by the Free Software
20 dnl Foundation
; either version 2 of the License, or (at your option) any
23 dnl
or both
in parallel
, as here.
25 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
26 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
27 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
30 dnl You should have received copies of the GNU General
Public License
and the
31 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
32 dnl see
https://www.gnu.
org/licenses
/.
34 include(`..
/config.m4
')
51 C Numbers measured with: speed -CD -s16-32 -t16 mpn_gcd_1
53 C Threshold of when to call bmod when U is one limb. Should be about
54 C (time_in_cycles(bmod_1,1) + call_overhead) / (cycles/bit).
55 define(`BMOD_THRES_LOG2', 6)
74 mov (up
), %eax C U
low limb
76 bsf %eax, %eax C min
(ctz
(u0
),ctz
(v0
))
81 push %eax C preserve common twos over
call
82 push v0 C preserve v0 argument over
call
87 C Both U
and V are single limbs
, reduce with bmod if u0
>> v0.
90 shr $BMOD_THRES_LOG
2, %ecx
96 cmp $BMOD
_1_TO_MOD
_1_THRESHOLD
, n
98 ifdef
(`PIC_WITH_EBX
',`dnl
101 call L(movl_eip_to_ebx)
102 add $_GLOBAL_OFFSET_TABLE_, %ebx
111 ifdef
(`PIC_WITH_EBX
',`dnl
114 call L(movl_eip_to_ebx)
115 add $_GLOBAL_OFFSET_TABLE_, %ebx
120 CALL( mpn_modexact_1_odd
)
123 ifdef
(`PIC_WITH_EBX
',`dnl
124 add $16, %esp C deallocate params
127 add $12, %esp C deallocate params
133 C test %eax, %eax C FIXME: does this lower latency?
137 ALIGN(16) C K10 BD C2 NHM SBR
138 L(top): cmovc( %esi, %eax) C if x-y < 0 0,3 0,3 0,6 0,5 0,5
139 cmovc( %edi, %edx) C use x,y-x 0,3 0,3 2,8 1,7 1,7
140 L(mid): shr %cl, %eax C 1,7 1,6 2,8 2,8 2,8
141 mov %edx, %esi C 1 1 4 3 3
142 sub %eax, %esi C 2 2 5 4 4
143 bsf %esi, %ecx C 3 3 6 5 5
144 mov %eax, %edi C 2 2 3 3 4
145 sub %edx, %eax C 2 2 4 3 4
156 ifdef(`PIC_WITH_EBX',`dnl