| 1 |
dnl x86-64 mpn_addmul_1 and mpn_submul_1, optimized for "Core 2". |
| 2 |
|
| 3 |
dnl Copyright 2003-2005, 2007-2009, 2011, 2012 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 4 |
| 35 |
C AMD K10 4 |
| 36 |
C AMD bd1 5.1 |
| 37 |
C AMD bobcat |
| 38 |
C Intel P4 ? |
| 39 |
C Intel core2 4.3-4.5 (fluctuating) |
| 40 |
C Intel NHM 5.0 |
| 41 |
C Intel SBR 4.1 |
| 42 |
C Intel atom ? |
| 43 |
C VIA nano 5.25 |
| 44 |
|
| 45 |
C INPUT PARAMETERS |
| 46 |
define(`rp', `%rdi') |
| 47 |
define(`up', `%rsi') |
| 48 |
define(`n', `%rdx') |
| 49 |
define(`v0', `%rcx') |
| 50 |
|
| 51 |
ifdef(`OPERATION_addmul_1',` |
| 52 |
define(`ADDSUB', `add') |
| 53 |
define(`func', `mpn_addmul_1') |
| 54 |
define(`func_1c', `mpn_addmul_1c') |
| 55 |
') |
| 56 |
ifdef(`OPERATION_submul_1',` |
| 57 |
define(`ADDSUB', `sub') |
| 58 |
define(`func', `mpn_submul_1') |
| 59 |
define(`func_1c', `mpn_submul_1c') |
| 60 |
') |
| 61 |
|
| 62 |
MULFUNC_PROLOGUE(mpn_addmul_1 mpn_addmul_1c mpn_submul_1 mpn_submul_1c) |
| 63 |
|
| 64 |
ABI_SUPPORT(DOS64) |
| 65 |
ABI_SUPPORT(STD64) |
| 66 |
|
| 67 |
C For DOS, on the stack we have four saved registers, return address, |
| 68 |
C space for four register arguments, and finally the carry input. |
| 69 |
|
| 70 |
IFDOS(` define(`carry_in', `72(%rsp)')') dnl |
| 71 |
IFSTD(` define(`carry_in', `%r8')') dnl |
| 72 |
|
| 73 |
ASM_START() |
| 74 |
TEXT |
| 75 |
ALIGN(16) |
| 76 |
PROLOGUE(func_1c) |
| 77 |
FUNC_ENTRY(4) |
| 78 |
push %rbx |
| 79 |
push %rbp |
| 80 |
lea (%rdx), %rbx |
| 81 |
neg %rbx |
| 82 |
|
| 83 |
mov (up), %rax |
| 84 |
mov (rp), %r10 |
| 85 |
|
| 86 |
lea -16(rp,%rdx,8), rp |
| 87 |
lea (up,%rdx,8), up |
| 88 |
mul %rcx |
| 89 |
add carry_in, %rax |
| 90 |
adc $0, %rdx |
| 91 |
jmp L(start_nc) |
| 92 |
EPILOGUE() |
| 93 |
|
| 94 |
ALIGN(16) |
| 95 |
PROLOGUE(func) |
| 96 |
FUNC_ENTRY(4) |
| 97 |
push %rbx |
| 98 |
push %rbp |
| 99 |
lea (%rdx), %rbx |
| 100 |
neg %rbx |
| 101 |
|
| 102 |
mov (up), %rax |
| 103 |
mov (rp), %r10 |
| 104 |
|
| 105 |
lea -16(rp,%rdx,8), rp |
| 106 |
lea (up,%rdx,8), up |
| 107 |
mul %rcx |
| 108 |
|
| 109 |
L(start_nc): |
| 110 |
bt $0, R32(%rbx) |
| 111 |
jc L(odd) |
| 112 |
|
| 113 |
lea (%rax), %r11 |
| 114 |
mov 8(up,%rbx,8), %rax |
| 115 |
lea (%rdx), %rbp |
| 116 |
mul %rcx |
| 117 |
add $2, %rbx |
| 118 |
jns L(n2) |
| 119 |
|
| 120 |
lea (%rax), %r8 |
| 121 |
mov (up,%rbx,8), %rax |
| 122 |
lea (%rdx), %r9 |
| 123 |
jmp L(mid) |
| 124 |
|
| 125 |
L(odd): add $1, %rbx |
| 126 |
jns L(n1) |
| 127 |
|
| 128 |
lea (%rax), %r8 |
| 129 |
mov (up,%rbx,8), %rax |
| 130 |
lea (%rdx), %r9 |
| 131 |
mul %rcx |
| 132 |
lea (%rax), %r11 |
| 133 |
mov 8(up,%rbx,8), %rax |
| 134 |
lea (%rdx), %rbp |
| 135 |
jmp L(e) |
| 136 |
|
| 137 |
ALIGN(16) |
| 138 |
L(top): mul %rcx |
| 139 |
ADDSUB %r8, %r10 |
| 140 |
lea (%rax), %r8 |
| 141 |
mov (up,%rbx,8), %rax |
| 142 |
adc %r9, %r11 |
| 143 |
mov %r10, -8(rp,%rbx,8) |
| 144 |
mov (rp,%rbx,8), %r10 |
| 145 |
lea (%rdx), %r9 |
| 146 |
adc $0, %rbp |
| 147 |
L(mid): mul %rcx |
| 148 |
ADDSUB %r11, %r10 |
| 149 |
lea (%rax), %r11 |
| 150 |
mov 8(up,%rbx,8), %rax |
| 151 |
adc %rbp, %r8 |
| 152 |
mov %r10, (rp,%rbx,8) |
| 153 |
mov 8(rp,%rbx,8), %r10 |
| 154 |
lea (%rdx), %rbp |
| 155 |
adc $0, %r9 |
| 156 |
L(e): add $2, %rbx |
| 157 |
js L(top) |
| 158 |
|
| 159 |
mul %rcx |
| 160 |
ADDSUB %r8, %r10 |
| 161 |
adc %r9, %r11 |
| 162 |
mov %r10, -8(rp) |
| 163 |
adc $0, %rbp |
| 164 |
L(n2): mov (rp), %r10 |
| 165 |
ADDSUB %r11, %r10 |
| 166 |
adc %rbp, %rax |
| 167 |
mov %r10, (rp) |
| 168 |
adc $0, %rdx |
| 169 |
L(n1): mov 8(rp), %r10 |
| 170 |
ADDSUB %rax, %r10 |
| 171 |
mov %r10, 8(rp) |
| 172 |
mov R32(%rbx), R32(%rax) C zero rax |
| 173 |
adc %rdx, %rax |
| 174 |
pop %rbp |
| 175 |
pop %rbx |
| 176 |
FUNC_EXIT() |
| 177 |
ret |
| 178 |
EPILOGUE() |