Debian Codegraph @

mpn/x86_64/coreisbr/cnd_sub_n.asm

raw
1 dnl AMD64 mpn_cnd_add_n, mpn_cnd_sub_n
2
3 dnl Copyright 2011-2013, 2017 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 C cycles/limb
34 C AMD K8,K9
35 C AMD K10
36 C AMD bd1
37 C AMD bd2
38 C AMD bd3
39 C AMD bd4
40 C AMD zen
41 C AMD bobcat
42 C AMD jaguar
43 C Intel P4
44 C Intel PNR 3.0
45 C Intel NHM 2.75
46 C Intel SBR 2.15
47 C Intel IBR 1.96
48 C Intel HWL 2.0
49 C Intel BWL 1.65
50 C Intel SKL 1.65
51 C Intel atom
52 C Intel SLM 4.5
53 C VIA nano
54
55 C NOTES
56 C * It might seem natural to use the cmov insn here, but since this function
57 C is supposed to have the exact same execution pattern for cnd true and
58 C false, and since cmov's documentation is not clear about whether it
59 C actually reads both source operands and writes the register for a false
60 C condition, we cannot use it.
61 C * Given that we have a dedicated cnd_add_n, it might look strange that this
62 C file provides cnd_add_n and not just cnd_sub_n. But that's harmless, and
63 C this file's generality might come in handy for some pipeline.
64
65 C INPUT PARAMETERS
66 define(`cnd_arg', `%rdi') dnl rcx
67 define(`rp', `%rsi') dnl rdx
68 define(`up', `%rdx') dnl r8
69 define(`vp', `%rcx') dnl r9
70 define(`n', `%r8') dnl rsp+40
71
72 define(`cnd', `%rbx')
73
74 ifdef(`OPERATION_cnd_add_n',`
75 define(ADDSUB, add)
76 define(ADCSBB, adc)
77 define(func, mpn_cnd_add_n)')
78 ifdef(`OPERATION_cnd_sub_n',`
79 define(ADDSUB, sub)
80 define(ADCSBB, sbb)
81 define(func, mpn_cnd_sub_n)')
82
83 MULFUNC_PROLOGUE(mpn_cnd_add_n mpn_cnd_sub_n)
84
85 ABI_SUPPORT(DOS64)
86 ABI_SUPPORT(STD64)
87
88 ASM_START()
89 TEXT
90 ALIGN(16)
91 PROLOGUE(func)
92 FUNC_ENTRY(4)
93 IFDOS(` mov 56(%rsp), R32(%r8)')
94 push %rbx
95 push %rbp
96 push %r12
97 push %r13
98
99 neg cnd_arg
100 sbb cnd, cnd C make cnd mask
101
102 test $1, R8(n)
103 jz L(x0)
104 L(x1): test $2, R8(n)
105 jz L(b1)
106
107 L(b3): mov (vp), %rdi
108 mov 8(vp), %r9
109 mov 16(vp), %r10
110 and cnd, %rdi
111 mov (up), %r12
112 and cnd, %r9
113 mov 8(up), %r13
114 and cnd, %r10
115 mov 16(up), %rbp
116 ADDSUB %rdi, %r12
117 mov %r12, (rp)
118 ADCSBB %r9, %r13
119 mov %r13, 8(rp)
120 ADCSBB %r10, %rbp
121 mov %rbp, 16(rp)
122 sbb R32(%rax), R32(%rax) C save carry
123 lea 24(up), up
124 lea 24(vp), vp
125 lea 24(rp), rp
126 sub $3, n
127 jnz L(top)
128 jmp L(end)
129
130 L(x0): xor R32(%rax), R32(%rax)
131 test $2, R8(n)
132 jz L(top)
133
134 L(b2): mov (vp), %rdi
135 mov 8(vp), %r9
136 mov (up), %r12
137 and cnd, %rdi
138 mov 8(up), %r13
139 and cnd, %r9
140 ADDSUB %rdi, %r12
141 mov %r12, (rp)
142 ADCSBB %r9, %r13
143 mov %r13, 8(rp)
144 sbb R32(%rax), R32(%rax) C save carry
145 lea 16(up), up
146 lea 16(vp), vp
147 lea 16(rp), rp
148 sub $2, n
149 jnz L(top)
150 jmp L(end)
151
152 L(b1): mov (vp), %rdi
153 mov (up), %r12
154 and cnd, %rdi
155 ADDSUB %rdi, %r12
156 mov %r12, (rp)
157 sbb R32(%rax), R32(%rax) C save carry
158 lea 8(up), up
159 lea 8(vp), vp
160 lea 8(rp), rp
161 dec n
162 jz L(end)
163
164 ALIGN(16)
165 L(top): mov (vp), %rdi
166 mov 8(vp), %r9
167 mov 16(vp), %r10
168 mov 24(vp), %r11
169 lea 32(vp), vp
170 and cnd, %rdi
171 mov (up), %r12
172 and cnd, %r9
173 mov 8(up), %r13
174 and cnd, %r10
175 mov 16(up), %rbp
176 and cnd, %r11
177 add R32(%rax), R32(%rax) C restore carry
178 mov 24(up), %rax
179 lea 32(up), up
180 ADCSBB %rdi, %r12
181 mov %r12, (rp)
182 ADCSBB %r9, %r13
183 mov %r13, 8(rp)
184 ADCSBB %r10, %rbp
185 mov %rbp, 16(rp)
186 ADCSBB %r11, %rax
187 mov %rax, 24(rp)
188 lea 32(rp), rp
189 sbb R32(%rax), R32(%rax) C save carry
190 sub $4, n
191 jnz L(top)
192
193 L(end): neg R32(%rax)
194 pop %r13
195 pop %r12
196 pop %rbp
197 pop %rbx
198 FUNC_EXIT()
199 ret
200 EPILOGUE()