1 dnl AMD64 mpn_gcd_1
-- mpn by
1 gcd.
3 dnl Based on the K7 gcd_1.asm
, by Kevin Ryde. Rehacked for AMD64 by Torbjorn
6 dnl Copyright
2000-2002, 2005, 2009, 2011, 2012 Free Software Foundation
, Inc.
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
')
38 C AMD K8,K9 5.21 (4.95)
41 C AMD bobcat 6.71 (6.56)
42 C Intel P4 13.5 (12.75)
43 C Intel core2 6.20 (6.16)
44 C Intel NHM 6.49 (6.25)
45 C Intel SBR 7.75 (7.57)
46 C Intel atom 8.77 (8.54)
47 C VIA nano 6.60 (6.20)
48 C Numbers measured with: speed -CD -s16-64 -t48 mpn_gcd_1
50 C ctz_table[n] is the number of trailing zeros on n, or MAXSHIFT if n==0.
53 deflit(MASK, eval((m4_lshift(1,MAXSHIFT))-1))
55 DEF_OBJECT(ctz_table,64)
58 ` .byte m4_count_trailing_zeros(i)
62 C Threshold of when to
call bmod when U is one limb. Should be about
63 C
(time_in_cycles
(bmod_1
,1) + call_overhead
) / (cycles
/bit
).
64 define
(`BMOD_THRES_LOG2
', 8)
74 IFDOS(`define(`STACK_ALLOC', 40)')
75 IFSTD(`define(`STACK_ALLOC', 8)')
82 mov (up), %rax C U low limb
92 push %rcx C common twos
102 C Both U and V are single limbs, reduce with bmod if u0 >> v0.
105 shr $BMOD_THRES_LOG2, %r8
109 sub $STACK_ALLOC, %rsp C maintain ABI required rsp alignment
112 IFDOS(` mov %rdx, %r8 ')
113 IFDOS
(`
mov %rsi
, %rdx
')
114 IFDOS(` mov %rdi, %rcx ')
115 ASSERT
(nz
, `
test $15, %rsp
')
116 CALL( mpn_modexact_1_odd)
119 add $STACK_ALLOC, %rsp
123 LEA( ctz_table, %rsi)
131 sub $STACK_ALLOC, %rsp C maintain ABI required rsp alignment
133 cmp $BMOD_1_TO_MOD_1_THRESHOLD, n
135 IFDOS(` mov %rdx, %r8 ')
136 IFDOS
(`
mov %rsi
, %rdx
')
137 IFDOS(` mov %rdi, %rcx ')
138 ASSERT
(nz
, `
test $15, %rsp
')
142 ALIGN(16) C K8 BC P4 NHM SBR
143 L(top): cmovc %rcx, %rax C if x-y < 0 0
144 cmovc %rdi, %rdx C use x,y-x 0
145 L(mid): and $MASK, R32(%rcx) C 0
146 movzbl (%rsi,%rcx), R32(%rcx) C 1
148 shr R8(%rcx), %rax C 3