Debian Codegraph @

mpn/x86_64/zen/aorsmul_1.asm

raw
1 dnl AMD64 mpn_addmul_1 and mpn_submul_1 for CPUs with mulx.
2
3 dnl Copyright 2012, 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 4.3
40 C AMD zen 2
41 C AMD bt1 -
42 C AMD bt2 -
43 C Intel P4 -
44 C Intel PNR -
45 C Intel NHM -
46 C Intel SBR -
47 C Intel IBR -
48 C Intel HWL ?
49 C Intel BWL ?
50 C Intel SKL ?
51 C Intel atom -
52 C Intel SLM -
53 C VIA nano -
54
55 define(`rp', `%rdi') C rcx
56 define(`up', `%rsi') C rdx
57 define(`n_param', `%rdx') C r8
58 define(`v0_param',`%rcx') C r9
59
60 define(`n', `%rcx')
61 define(`v0', `%rdx')
62
63 ifdef(`OPERATION_addmul_1',`
64 define(`ADDSUB', `add')
65 define(`ADCSBB', `adc')
66 define(`func', `mpn_addmul_1')
67 ')
68 ifdef(`OPERATION_submul_1',`
69 define(`ADDSUB', `sub')
70 define(`ADCSBB', `sbb')
71 define(`func', `mpn_submul_1')
72 ')
73
74 ABI_SUPPORT(DOS64)
75 ABI_SUPPORT(STD64)
76
77 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
78
79 ASM_START()
80 TEXT
81 ALIGN(16)
82 PROLOGUE(func)
83 FUNC_ENTRY(4)
84 mov (up), %r8
85
86 push %rbx
87 push %r12
88 push %r13
89
90 lea (up,n_param,8), up
91 lea -32(rp,n_param,8), rp
92 mov R32(n_param), R32(%rax)
93 xchg v0_param, v0 C FIXME: is this insn fast?
94
95 neg n
96
97 and $3, R8(%rax)
98 jz L(b0)
99 cmp $2, R8(%rax)
100 jz L(b2)
101 jg L(b3)
102
103 L(b1): mulx( %r8, %rbx, %rax)
104 sub $-1, n
105 jz L(wd1)
106 .byte 0xc4,0x62,0xb3,0xf6,0x04,0xce C mulx (up,n,8), %r9, %r8
107 .byte 0xc4,0x62,0xa3,0xf6,0x54,0xce,0x08 C mulx 8(up,n,8), %r11, %r10
108 test R32(%rax), R32(%rax) C clear cy
109 jmp L(lo1)
110
111 L(b0): mulx( %r8, %r9, %r8)
112 .byte 0xc4,0x62,0xa3,0xf6,0x54,0xce,0x08 C mulx 8(up,n,8), %r11, %r10
113 .byte 0xc4,0x62,0x93,0xf6,0x64,0xce,0x10 C mulx 16(up,n,8), %r13, %r12
114 xor R32(%rax), R32(%rax)
115 jmp L(lo0)
116
117 L(b3): mulx( %r8, %r11, %r10)
118 .byte 0xc4,0x62,0x93,0xf6,0x64,0xce,0x08 C mulx 8(up,n,8), %r13, %r12
119 .byte 0xc4,0xe2,0xe3,0xf6,0x44,0xce,0x10 C mulx 16(up,n,8), %rbx, %rax
120 add %r10, %r13
121 adc %r12, %rbx
122 adc $0, %rax
123 sub $-3, n
124 jz L(wd3)
125 test R32(%rax), R32(%rax) C clear cy
126 jmp L(lo3)
127
128 L(b2): mulx( %r8, %r13, %r12)
129 .byte 0xc4,0xe2,0xe3,0xf6,0x44,0xce,0x08 C mulx 8(up,n,8), %rbx, %rax
130 add %r12, %rbx
131 adc $0, %rax
132 sub $-2, n
133 jz L(wd2)
134 .byte 0xc4,0x62,0xb3,0xf6,0x04,0xce C mulx (up,n,8), %r9, %r8
135 test R32(%rax), R32(%rax) C clear cy
136 jmp L(lo2)
137
138 L(top): ADDSUB %r9, (rp,n,8)
139 L(lo3): .byte 0xc4,0x62,0xb3,0xf6,0x04,0xce C mulx (up,n,8), %r9, %r8
140 ADCSBB %r11, 8(rp,n,8)
141 L(lo2): .byte 0xc4,0x62,0xa3,0xf6,0x54,0xce,0x08 C mulx 8(up,n,8), %r11, %r10
142 ADCSBB %r13, 16(rp,n,8)
143 L(lo1): .byte 0xc4,0x62,0x93,0xf6,0x64,0xce,0x10 C mulx 16(up,n,8), %r13, %r12
144 ADCSBB %rbx, 24(rp,n,8)
145 adc %rax, %r9
146 L(lo0): .byte 0xc4,0xe2,0xe3,0xf6,0x44,0xce,0x18 C mulx 24(up,n,8), %rbx, %rax
147 adc %r8, %r11
148 adc %r10, %r13
149 adc %r12, %rbx
150 adc $0, %rax C rax = carry limb
151 add $4, n
152 js L(top)
153
154 L(end): ADDSUB %r9, (rp)
155 L(wd3): ADCSBB %r11, 8(rp)
156 L(wd2): ADCSBB %r13, 16(rp)
157 L(wd1): ADCSBB %rbx, 24(rp)
158 adc n, %rax
159 pop %r13
160 pop %r12
161 pop %rbx
162 FUNC_EXIT()
163 ret
164 EPILOGUE()
165 ASM_END()