Debian Codegraph @

mpn/x86/k7/gcd_11.asm

raw
1 dnl x86 mpn_gcd_11 optimised for AMD K7.
2
3 dnl Contributed to the GNU project by by Kevin Ryde. Rehacked by Torbjorn
4 dnl Granlund.
5
6 dnl Copyright 2000-2002, 2005, 2009, 2011, 2012, 2014, 2015 Free Software
7 dnl Foundation, Inc.
8
9 dnl This file is part of the GNU MP Library.
10 dnl
11 dnl The GNU MP Library is free software; you can redistribute it and/or modify
12 dnl it under the terms of either:
13 dnl
14 dnl * the GNU Lesser General Public License as published by the Free
15 dnl Software Foundation; either version 3 of the License, or (at your
16 dnl option) any later version.
17 dnl
18 dnl or
19 dnl
20 dnl * the GNU General Public License as published by the Free Software
21 dnl Foundation; either version 2 of the License, or (at your option) any
22 dnl later version.
23 dnl
24 dnl or both in parallel, as here.
25 dnl
26 dnl The GNU MP Library is distributed in the hope that it will be useful, but
27 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 dnl for more details.
30 dnl
31 dnl You should have received copies of the GNU General Public License and the
32 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
33 dnl see https://www.gnu.org/licenses/.
34
35 include(`../config.m4')
36
37
38 C cycles/bit (approx)
39 C AMD K7 5.31
40 C AMD K8,K9 5.33
41 C AMD K10 5.30
42 C AMD bd1 ?
43 C AMD bobcat 7.02
44 C Intel P4-2 10.1
45 C Intel P4-3/4 10.0
46 C Intel P6/13 5.88
47 C Intel core2 6.26
48 C Intel NHM 6.83
49 C Intel SBR 8.50
50 C Intel atom 8.90
51 C VIA nano ?
52 C Numbers measured with: speed -CD -s16-32 -t16 mpn_gcd_1
53
54
55 C ctz_table[n] is the number of trailing zeros on n, or MAXSHIFT if n==0.
56
57 deflit(MAXSHIFT, 6)
58 deflit(MASK, eval((m4_lshift(1,MAXSHIFT))-1))
59
60 DEF_OBJECT(ctz_table,64)
61 .byte MAXSHIFT
62 forloop(i,1,MASK,
63 ` .byte m4_count_trailing_zeros(i)
64 ')
65 END_OBJECT(ctz_table)
66
67
68 define(`u0', `%eax')
69 define(`v0', `%edx')
70
71 ASM_START()
72 TEXT
73 ALIGN(16)
74 PROLOGUE(mpn_gcd_11)
75 push %edi
76 push %esi
77
78 mov 12(%esp), %eax
79 mov 16(%esp), %edx
80
81 LEAL( ctz_table, %esi)
82 jmp L(odd)
83
84 ALIGN(16) C
85 L(top): cmovc( %ecx, %eax) C u = |v - u|
86 cmovc( %edi, %edx) C v = min(u,v)
87 L(mid): and $MASK, %ecx C
88 movzbl (%esi,%ecx), %ecx C
89 jz L(shift_alot) C
90 shr %cl, %eax C
91 L(odd): mov %eax, %edi C
92 mov %edx, %ecx C
93 sub %eax, %ecx C
94 sub %edx, %eax C
95 jnz L(top) C
96
97 L(end): mov %edx, %eax
98 pop %esi
99 pop %edi
100 ret
101
102 L(shift_alot):
103 shr $MAXSHIFT, %eax
104 mov %eax, %ecx
105 jmp L(mid)
106 EPILOGUE()
107 ASM_END()