1 dnl AMD64 mpn_addmul_1
and mpn_submul_1 for CPUs with mulx.
3 dnl Copyright
2012, 2013 Free Software Foundation
, Inc.
5 dnl
This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
8 dnl it under the terms of
either:
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.
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
20 dnl
or both
in parallel
, as here.
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
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
/.
31 include(`..
/config.m4
')
49 define(`rp', `
%rdi
') C rcx
50 define(`up', `
%rsi
') C rdx
51 define(`n_param', `
%rdx
') C r8
52 define(`v0_param',`
%rcx
') C r9
57 ifdef(`OPERATION_addmul_1',`
58 define
(`ADDSUB
', `add')
59 define
(`ADCSBB
', `adc')
60 define
(`func
', `mpn_addmul_1')
62 ifdef(`OPERATION_submul_1',`
63 define
(`ADDSUB
', `sub')
64 define
(`ADCSBB
', `sbb')
65 define
(`func
', `mpn_submul_1')
68 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
70 IFDOS(` define(`up', ``
%rsi
'') ') dnl
71 IFDOS(` define(`rp', ``
%rcx
'') ') dnl
72 IFDOS(` define(`vl', ``
%r9
'') ') dnl
73 IFDOS(` define(`r9', ``rdi
'') ') dnl
74 IFDOS(` define(`n', ``
%r8
'') ') dnl
75 IFDOS(` define(`r8', ``r11
'') ') dnl
87 lea (up,n_param,8), up
88 lea -32(rp,n_param,8), rp
89 mov R32(n_param), R32(%rax)
90 xchg v0_param, v0 C FIXME: is this insn fast?
100 L(b1): mulx %r8, %rbx, %rax
103 mulx (up,n,8), %r9, %r8
104 mulx 8(up,n,8), %r11, %r10
105 test R32(%rax), R32(%rax) C clear cy
108 L(b0): mulx %r8, %r9, %r8
109 mulx 8(up,n,8), %r11, %r10
110 mulx 16(up,n,8), %r13, %r12
111 xor R32(%rax), R32(%rax)
114 L(b3): mulx %r8, %r11, %r10
115 mulx 8(up,n,8), %r13, %r12
116 mulx 16(up,n,8), %rbx, %rax
122 test R32(%rax), R32(%rax) C clear cy
125 L(b2): mulx %r8, %r13, %r12
126 mulx 8(up,n,8), %rbx, %rax
131 mulx (up,n,8), %r9, %r8
132 test R32(%rax), R32(%rax) C clear cy
135 L(top): ADDSUB %r9, (rp,n,8)
136 L(lo3): mulx (up,n,8), %r9, %r8
137 ADCSBB %r11, 8(rp,n,8)
138 L(lo2): mulx 8(up,n,8), %r11, %r10
139 ADCSBB %r13, 16(rp,n,8)
140 L(lo1): mulx 16(up,n,8), %r13, %r12
141 ADCSBB %rbx, 24(rp,n,8)
143 L(lo0): mulx 24(up,n,8), %rbx, %rax
147 adc $0, %rax C rax = carry limb
151 L(end): ADDSUB %r9, (rp)
152 L(wd3): ADCSBB %r11, 8(rp)
153 L(wd2): ADCSBB %r13, 16(rp)
154 L(wd1): ADCSBB %rbx, 24(rp)