| 1 |
dnl AMD64 mpn_addmul_1 for CPUs with mulx and adx. |
| 2 |
|
| 3 |
dnl Contributed to the GNU project by Torbjörn Granlund. |
| 4 |
|
| 5 |
dnl Copyright 2012, 2013, 2022 Free Software Foundation, Inc. |
| 6 |
|
| 7 |
dnl This file is part of the GNU MP Library. |
| 8 |
dnl |
| 9 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify |
| 10 |
dnl it under the terms of either: |
| 11 |
dnl |
| 12 |
dnl * the GNU Lesser General Public License as published by the Free |
| 13 |
dnl Software Foundation; either version 3 of the License, or (at your |
| 14 |
dnl option) any later version. |
| 15 |
dnl |
| 16 |
dnl or |
| 17 |
dnl |
| 18 |
dnl * the GNU General Public License as published by the Free Software |
| 19 |
dnl Foundation; either version 2 of the License, or (at your option) any |
| 20 |
dnl later version. |
| 21 |
dnl |
| 22 |
dnl or both in parallel, as here. |
| 23 |
dnl |
| 24 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but |
| 25 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 26 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 27 |
dnl for more details. |
| 28 |
dnl |
| 29 |
dnl You should have received copies of the GNU General Public License and the |
| 30 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not, |
| 31 |
dnl see https://www.gnu.org/licenses/. |
| 32 |
|
| 33 |
include(`../config.m4') |
| 34 |
|
| 35 |
C cycles/limb |
| 36 |
C AMD K8,K9 - |
| 37 |
C AMD K10 - |
| 38 |
C AMD bd1 - |
| 39 |
C AMD bd2 - |
| 40 |
C AMD bd3 - |
| 41 |
C AMD bd4 - |
| 42 |
C AMD zn1 ? |
| 43 |
C AMD zn2 ? |
| 44 |
C AMD zn3 ? |
| 45 |
C AMD bt1 - |
| 46 |
C AMD bt2 - |
| 47 |
C Intel P4 - |
| 48 |
C Intel CNR - |
| 49 |
C Intel PNR - |
| 50 |
C Intel NHM - |
| 51 |
C Intel WSM - |
| 52 |
C Intel SBR - |
| 53 |
C Intel IBR - |
| 54 |
C Intel HWL - |
| 55 |
C Intel BWL ? |
| 56 |
C Intel SKL ? |
| 57 |
C Intel RKL ? |
| 58 |
C Intel ALD 1.29 |
| 59 |
C Intel atom - |
| 60 |
C Intel SLM - |
| 61 |
C Intel GLM - |
| 62 |
C VIA nano - |
| 63 |
|
| 64 |
define(`rp', `%rdi') dnl rcx |
| 65 |
define(`up', `%rsi') dnl rdx |
| 66 |
define(`n_param', `%rdx') dnl r8 |
| 67 |
define(`v0_param',`%rcx') dnl r9 |
| 68 |
|
| 69 |
define(`n', `%rcx') dnl |
| 70 |
define(`v0', `%rdx') dnl |
| 71 |
|
| 72 |
|
| 73 |
ASM_START() |
| 74 |
TEXT |
| 75 |
ALIGN(16) |
| 76 |
PROLOGUE(mpn_addmul_1) |
| 77 |
mov (up), %r8 |
| 78 |
|
| 79 |
push %rbx |
| 80 |
push %r12 |
| 81 |
push %r13 |
| 82 |
|
| 83 |
mov %rdx, %rax |
| 84 |
mov %rcx, v0 |
| 85 |
mov %rax, n |
| 86 |
|
| 87 |
and $3, R8(%rax) |
| 88 |
jz L(b0) |
| 89 |
cmp $2, R8(%rax) |
| 90 |
jl L(b1) |
| 91 |
jz L(b2) |
| 92 |
|
| 93 |
L(b3): mulx( %r8, %r11, %r10) |
| 94 |
mulx( 8,(up), %r13, %r12) |
| 95 |
mulx( 16,(up), %rbx, %rax) |
| 96 |
inc n |
| 97 |
lea -8(up), up |
| 98 |
lea -24(rp), rp |
| 99 |
jmp L(lo3) |
| 100 |
|
| 101 |
L(b0): mulx( %r8, %r9, %r8) |
| 102 |
mulx( 8,(up), %r11, %r10) |
| 103 |
mulx( 16,(up), %r13, %r12) |
| 104 |
lea -16(rp), rp |
| 105 |
jmp L(lo0) |
| 106 |
|
| 107 |
L(b2): mulx( %r8, %r13, %r12) |
| 108 |
mulx( 8,(up), %rbx, %rax) |
| 109 |
lea -2(n), n |
| 110 |
jrcxz L(n2) |
| 111 |
mulx( 16,(up), %r9, %r8) |
| 112 |
lea 16(up), up |
| 113 |
jmp L(lo2) |
| 114 |
L(n2): jmp L(wd2) |
| 115 |
|
| 116 |
L(b1): mulx( %r8, %rbx, %rax) |
| 117 |
sub $1, n |
| 118 |
jrcxz L(n1) |
| 119 |
mulx( 8,(up), %r9, %r8) |
| 120 |
mulx( 16,(up), %r11, %r10) |
| 121 |
lea 8(up), up |
| 122 |
lea -8(rp), rp |
| 123 |
jmp L(lo1) |
| 124 |
L(n1): add (rp), %rbx |
| 125 |
adc %rcx, %rax |
| 126 |
mov %rbx, (rp) |
| 127 |
pop %r13 |
| 128 |
pop %r12 |
| 129 |
pop %rbx |
| 130 |
ret |
| 131 |
|
| 132 |
L(top): mulx( (up), %r9, %r8) |
| 133 |
adcx( %r10, %r13) |
| 134 |
mov %r11, -8(rp) |
| 135 |
L(lo2): adox( (rp), %r13) |
| 136 |
mulx( 8,(up), %r11, %r10) |
| 137 |
adcx( %r12, %rbx) |
| 138 |
mov %r13, (rp) |
| 139 |
L(lo1): adox( 8,(rp), %rbx) |
| 140 |
mulx( 16,(up), %r13, %r12) |
| 141 |
adcx( %rax, %r9) |
| 142 |
mov %rbx, 8(rp) |
| 143 |
L(lo0): adox( 16,(rp), %r9) |
| 144 |
mulx( 24,(up), %rbx, %rax) |
| 145 |
adcx( %r8, %r11) |
| 146 |
mov %r9, 16(rp) |
| 147 |
L(lo3): adox( 24,(rp), %r11) |
| 148 |
lea 32(up), up |
| 149 |
lea 32(rp), rp |
| 150 |
lea -4(n), n |
| 151 |
jrcxz L(end) |
| 152 |
jmp L(top) |
| 153 |
|
| 154 |
L(end): adcx( %r10, %r13) |
| 155 |
mov %r11, -8(rp) |
| 156 |
L(wd2): adox( (rp), %r13) |
| 157 |
adcx( %r12, %rbx) |
| 158 |
mov %r13, (rp) |
| 159 |
adox( 8,(rp), %rbx) |
| 160 |
adcx( %rcx, %rax) |
| 161 |
adox( %rcx, %rax) |
| 162 |
mov %rbx, 8(rp) |
| 163 |
pop %r13 |
| 164 |
pop %r12 |
| 165 |
pop %rbx |
| 166 |
ret |
| 167 |
EPILOGUE() |
| 168 |
ASM_END() |