| 1 |
dnl AMD64 mpn_mul_1 optimised for AMD bt1/bt2. |
| 2 |
|
| 3 |
dnl Copyright 2003-2005, 2007, 2008, 2011, 2012, 2019 Free Software |
| 4 |
dnl Foundation, Inc. |
| 5 |
|
| 6 |
dnl This file is part of the GNU MP Library. |
| 7 |
dnl |
| 8 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify |
| 9 |
dnl it under the terms of either: |
| 10 |
dnl |
| 11 |
dnl * the GNU Lesser General Public License as published by the Free |
| 12 |
dnl Software Foundation; either version 3 of the License, or (at your |
| 13 |
dnl option) any later version. |
| 14 |
dnl |
| 15 |
dnl or |
| 16 |
dnl |
| 17 |
dnl * the GNU General Public License as published by the Free Software |
| 18 |
dnl Foundation; either version 2 of the License, or (at your option) any |
| 19 |
dnl later version. |
| 20 |
dnl |
| 21 |
dnl or both in parallel, as here. |
| 22 |
dnl |
| 23 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but |
| 24 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 25 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 26 |
dnl for more details. |
| 27 |
dnl |
| 28 |
dnl You should have received copies of the GNU General Public License and the |
| 29 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not, |
| 30 |
dnl see https://www.gnu.org/licenses/. |
| 31 |
|
| 32 |
include(`../config.m4') |
| 33 |
|
| 34 |
C cycles/limb |
| 35 |
C AMD K8,K9 4.53 old measurement |
| 36 |
C AMD K10 4.53 old measurement |
| 37 |
C AMD bd1 4.56 old measurement |
| 38 |
C AMD bd2 4.47 old measurement |
| 39 |
C AMD bd3 ? |
| 40 |
C AMD bd4 ? |
| 41 |
C AMD zen ? |
| 42 |
C AMD bt1 5.12 |
| 43 |
C AMD bt2 5.17 |
| 44 |
C Intel P4 12.6 old measurement |
| 45 |
C Intel PNR 4.53 old measurement |
| 46 |
C Intel NHM 4.36 old measurement |
| 47 |
C Intel SBR 3.0 old measurement |
| 48 |
C Intel IBR 2.55 old measurement |
| 49 |
C Intel HWL 2.28 old measurement |
| 50 |
C Intel BWL 2.36 old measurement |
| 51 |
C Intel SKL 2.39 old measurement |
| 52 |
C Intel atom 21.0 old measurement |
| 53 |
C Intel SLM 9 old measurement |
| 54 |
C Intel GLM ? |
| 55 |
C VIA nano ? |
| 56 |
|
| 57 |
C The loop of this code is the result of running a code generation and |
| 58 |
C optimisation tool suite written by David Harvey and Torbjorn Granlund. |
| 59 |
|
| 60 |
ABI_SUPPORT(DOS64) |
| 61 |
ABI_SUPPORT(STD64) |
| 62 |
|
| 63 |
C Standard parameters |
| 64 |
define(`rp', `%rdi') |
| 65 |
define(`up', `%rsi') |
| 66 |
define(`n_param', `%rdx') |
| 67 |
define(`v0', `%rcx') |
| 68 |
define(`cy', `%r8') |
| 69 |
C Standard allocations |
| 70 |
define(`n', `%rbx') |
| 71 |
define(`w0', `%r8') |
| 72 |
define(`w1', `%r9') |
| 73 |
define(`w2', `%r10') |
| 74 |
define(`w3', `%r11') |
| 75 |
|
| 76 |
C DOS64 parameters |
| 77 |
IFDOS(` define(`rp', `%rcx') ') dnl |
| 78 |
IFDOS(` define(`up', `%rsi') ') dnl |
| 79 |
IFDOS(` define(`n_param', `%r8') ') dnl |
| 80 |
IFDOS(` define(`v0', `%r9') ') dnl |
| 81 |
IFDOS(` define(`cy', `56(%rsp)')') dnl |
| 82 |
C DOS64 allocations |
| 83 |
IFDOS(` define(`n', `%rbx') ') dnl |
| 84 |
IFDOS(` define(`w0', `%r8') ') dnl |
| 85 |
IFDOS(` define(`w1', `%rdi') ') dnl |
| 86 |
IFDOS(` define(`w2', `%r10') ') dnl |
| 87 |
IFDOS(` define(`w3', `%r11') ') dnl |
| 88 |
|
| 89 |
ALIGN(64) |
| 90 |
PROLOGUE(mpn_mul_1) |
| 91 |
IFDOS(` push %rsi ') |
| 92 |
IFDOS(` push %rdi ') |
| 93 |
IFDOS(` mov %rdx, %rsi ') |
| 94 |
|
| 95 |
push %rbx |
| 96 |
mov (up), %rax |
| 97 |
|
| 98 |
lea (rp,n_param,8), rp |
| 99 |
lea (up,n_param,8), up |
| 100 |
mov n_param, n |
| 101 |
|
| 102 |
test $1, R8(n_param) |
| 103 |
jne L(bx1) |
| 104 |
|
| 105 |
L(bx0): mul v0 |
| 106 |
neg n |
| 107 |
mov %rax, w0 |
| 108 |
mov %rdx, w1 |
| 109 |
test $2, R8(n) |
| 110 |
jne L(L2) |
| 111 |
|
| 112 |
L(b00): add $2, n |
| 113 |
jmp L(L0) |
| 114 |
|
| 115 |
ALIGN(16) |
| 116 |
L(b11): mov %rax, w2 |
| 117 |
mov %rdx, w3 |
| 118 |
neg n |
| 119 |
inc n |
| 120 |
jmp L(L3) |
| 121 |
|
| 122 |
ALIGN(16) |
| 123 |
L(bx1): mul v0 |
| 124 |
test $2, R8(n) |
| 125 |
jne L(b11) |
| 126 |
|
| 127 |
L(b01): sub $3, n |
| 128 |
jc L(n1) |
| 129 |
mov %rax, w2 |
| 130 |
mov %rdx, w3 |
| 131 |
neg n |
| 132 |
|
| 133 |
ALIGN(16) |
| 134 |
L(top): mov -16(up,n,8), %rax |
| 135 |
mul v0 |
| 136 |
mov %rax, w0 |
| 137 |
mov %rdx, w1 |
| 138 |
mov w2, -24(rp,n,8) |
| 139 |
add w3, w0 |
| 140 |
adc $0, w1 |
| 141 |
L(L0): mov -8(up,n,8), %rax |
| 142 |
mul v0 |
| 143 |
mov %rax, w2 |
| 144 |
mov %rdx, w3 |
| 145 |
mov w0, -16(rp,n,8) |
| 146 |
add w1, w2 |
| 147 |
adc $0, w3 |
| 148 |
L(L3): mov (up,n,8), %rax |
| 149 |
mul v0 |
| 150 |
mov %rax, w0 |
| 151 |
mov %rdx, w1 |
| 152 |
mov w2, -8(rp,n,8) |
| 153 |
add w3, w0 |
| 154 |
adc $0, w1 |
| 155 |
L(L2): mov 8(up,n,8), %rax |
| 156 |
mul v0 |
| 157 |
mov %rax, w2 |
| 158 |
mov %rdx, w3 |
| 159 |
mov w0, (rp,n,8) |
| 160 |
add w1, w2 |
| 161 |
adc $0, w3 |
| 162 |
add $4, n |
| 163 |
js L(top) |
| 164 |
|
| 165 |
L(end): mov w2, -8(rp) |
| 166 |
mov w3, %rax |
| 167 |
pop %rbx |
| 168 |
IFDOS(` pop %rdi ') |
| 169 |
IFDOS(` pop %rsi ') |
| 170 |
ret |
| 171 |
|
| 172 |
ALIGN(32) |
| 173 |
L(n1): mov %rax, -8(rp) |
| 174 |
mov %rdx, %rax |
| 175 |
pop %rbx |
| 176 |
IFDOS(` pop %rdi ') |
| 177 |
IFDOS(` pop %rsi ') |
| 178 |
ret |
| 179 |
EPILOGUE() |
| 180 |
|
| 181 |
ASM_START() |
| 182 |
TEXT |
| 183 |
ALIGN(64) |
| 184 |
PROLOGUE(mpn_mul_1c) |
| 185 |
IFDOS(` push %rsi ') |
| 186 |
IFDOS(` push %rdi ') |
| 187 |
IFDOS(` mov %rdx, %rsi ') |
| 188 |
mov cy, w2 |
| 189 |
push %rbx |
| 190 |
mov (up), %rax |
| 191 |
|
| 192 |
lea (rp,n_param,8), rp |
| 193 |
lea (up,n_param,8), up |
| 194 |
mov n_param, n |
| 195 |
|
| 196 |
test $1, R8(n_param) |
| 197 |
jne L(cx1) |
| 198 |
|
| 199 |
L(cx0): mul v0 |
| 200 |
neg n |
| 201 |
mov %rax, w0 |
| 202 |
mov %rdx, w1 |
| 203 |
add w2, w0 |
| 204 |
adc $0, w1 |
| 205 |
test $2, R8(n) |
| 206 |
jne L(L2) |
| 207 |
|
| 208 |
L(c00): add $2, n |
| 209 |
jmp L(L0) |
| 210 |
|
| 211 |
ALIGN(16) |
| 212 |
L(cx1): mul v0 |
| 213 |
test $2, R8(n) |
| 214 |
je L(c01) |
| 215 |
|
| 216 |
L(c11): neg n |
| 217 |
inc n |
| 218 |
add %rax, w2 |
| 219 |
mov %rdx, w3 |
| 220 |
adc $0, w3 |
| 221 |
jmp L(L3) |
| 222 |
|
| 223 |
L(c01): cmp $1, n |
| 224 |
jz L(m1) |
| 225 |
neg n |
| 226 |
add $3, n |
| 227 |
add %rax, w2 |
| 228 |
mov %rdx, w3 |
| 229 |
adc $0, w3 |
| 230 |
jmp L(top) |
| 231 |
|
| 232 |
ALIGN(32) |
| 233 |
L(m1): add %rax, w2 |
| 234 |
mov %rdx, %rax |
| 235 |
mov w2, -8(rp) |
| 236 |
adc $0, %rax |
| 237 |
pop %rbx |
| 238 |
IFDOS(` pop %rdi ') |
| 239 |
IFDOS(` pop %rsi ') |
| 240 |
ret |
| 241 |
EPILOGUE() |