Debian Codegraph @

mpn/x86_64/coreihwl/gcd_22.asm

raw
1 dnl AMD64 mpn_gcd_22. Assumes useless bsf, useless shrd, useful tzcnt, shlx.
2
3 dnl Copyright 2019 Free Software Foundation, Inc.
4
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/.
30
31 include(`../config.m4')
32
33
34 C cycles/bit
35 C AMD K8,K9 -
36 C AMD K10 -
37 C AMD bd1 -
38 C AMD bd2 -
39 C AMD bd3 -
40 C AMD bd4 6.7
41 C AMD bt1 -
42 C AMD bt2 -
43 C AMD zn1 5.4
44 C AMD zn2 5.5
45 C Intel P4 -
46 C Intel CNR -
47 C Intel PNR -
48 C Intel NHM -
49 C Intel WSM -
50 C Intel SBR -
51 C Intel IBR -
52 C Intel HWL 7.1
53 C Intel BWL 5.5
54 C Intel SKL 5.6
55 C Intel atom -
56 C Intel SLM -
57 C Intel GLM -
58 C Intel GLM+ -
59 C VIA nano -
60
61
62 define(`u1', `%rdi')
63 define(`u0', `%rsi')
64 define(`v1', `%rdx')
65 define(`v0', `%rcx')
66
67 define(`s0', `%r8')
68 define(`s1', `%r9')
69 define(`t0', `%r10')
70 define(`t1', `%r11')
71 define(`cnt', `%rax')
72
73 dnl ABI_SUPPORT(DOS64) C returns mp_double_limb_t in memory
74 ABI_SUPPORT(STD64)
75
76 ASM_START()
77 TEXT
78 ALIGN(64)
79 PROLOGUE(mpn_gcd_22)
80 FUNC_ENTRY(4)
81
82 ALIGN(16)
83 L(top): mov v0, t0
84 sub u0, t0
85 jz L(lowz) C jump when low limb result = 0
86 mov v1, t1
87 sbb u1, t1
88
89 rep;bsf t0, cnt C tzcnt!
90
91 mov u0, s0
92 sub v0, u0
93 mov u1, s1
94 sbb v1, u1
95
96 L(bck): cmovc t0, u0 C u = |u - v|
97 cmovc t1, u1 C u = |u - v|
98 cmovc s0, v0 C v = min(u,v)
99 cmovc s1, v1 C v = min(u,v)
100
101 xor R32(t0), R32(t0)
102 sub cnt, t0
103 shlx( t0, u1, s1)
104 shrx( cnt, u0, u0)
105 shrx( cnt, u1, u1)
106 or s1, u0
107
108 test v1, v1
109 jnz L(top)
110 test u1, u1
111 jnz L(top)
112
113 L(gcd_11):
114 mov v0, %rdi
115 C mov u0, %rsi
116 TCALL( mpn_gcd_11)
117
118 L(lowz):C We come here when v0 - u0 = 0
119 C 1. If v1 - u1 = 0, then gcd is u = v.
120 C 2. Else compute gcd_21({v1,v0}, |u1-v1|)
121 mov v1, t0
122 sub u1, t0
123 je L(end)
124
125 xor t1, t1
126 mov u0, s0
127 mov u1, s1
128 rep;bsf t0, cnt C tzcnt!
129 mov u1, u0
130 xor u1, u1
131 sub v1, u0
132 jmp L(bck)
133
134 L(end): mov v0, %rax
135 C mov v1, %rdx
136 L(ret): FUNC_EXIT()
137 ret
138 EPILOGUE()