| 1 |
dnl AMD64 mpn_cnd_add_n. |
| 2 |
|
| 3 |
dnl Copyright 2011-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 |
| 40 |
C AMD zen |
| 41 |
C AMD bobcat |
| 42 |
C AMD jaguar |
| 43 |
C Intel P4 |
| 44 |
C Intel PNR 3.0 |
| 45 |
C Intel NHM 3.75 |
| 46 |
C Intel SBR 1.93 |
| 47 |
C Intel IBR 1.89 |
| 48 |
C Intel HWL 1.78 |
| 49 |
C Intel BWL 1.50 |
| 50 |
C Intel SKL 1.50 |
| 51 |
C Intel atom |
| 52 |
C Intel SLM 4.0 |
| 53 |
C VIA nano |
| 54 |
|
| 55 |
C NOTES |
| 56 |
C * It might seem natural to use the cmov insn here, but since this function |
| 57 |
C is supposed to have the exact same execution pattern for cnd true and |
| 58 |
C false, and since cmov's documentation is not clear about whether it |
| 59 |
C actually reads both source operands and writes the register for a false |
| 60 |
C condition, we cannot use it. |
| 61 |
|
| 62 |
C INPUT PARAMETERS |
| 63 |
define(`cnd_arg', `%rdi') dnl rcx |
| 64 |
define(`rp', `%rsi') dnl rdx |
| 65 |
define(`up', `%rdx') dnl r8 |
| 66 |
define(`vp', `%rcx') dnl r9 |
| 67 |
define(`n', `%r8') dnl rsp+40 |
| 68 |
|
| 69 |
define(`cnd', `%rbx') |
| 70 |
|
| 71 |
define(ADDSUB, add) |
| 72 |
define(ADCSBB, adc) |
| 73 |
define(func, mpn_cnd_add_n) |
| 74 |
|
| 75 |
ABI_SUPPORT(DOS64) |
| 76 |
ABI_SUPPORT(STD64) |
| 77 |
|
| 78 |
ASM_START() |
| 79 |
TEXT |
| 80 |
ALIGN(16) |
| 81 |
PROLOGUE(mpn_cnd_add_n) |
| 82 |
FUNC_ENTRY(4) |
| 83 |
IFDOS(` mov 56(%rsp), R32(%r8)') |
| 84 |
push %rbx |
| 85 |
|
| 86 |
neg cnd_arg |
| 87 |
sbb cnd, cnd C make cnd mask |
| 88 |
|
| 89 |
test $1, R8(n) |
| 90 |
jz L(x0) |
| 91 |
L(x1): test $2, R8(n) |
| 92 |
jz L(b1) |
| 93 |
|
| 94 |
L(b3): mov (vp), %rdi |
| 95 |
mov 8(vp), %r9 |
| 96 |
mov 16(vp), %r10 |
| 97 |
and cnd, %rdi |
| 98 |
and cnd, %r9 |
| 99 |
and cnd, %r10 |
| 100 |
ADDSUB (up), %rdi |
| 101 |
mov %rdi, (rp) |
| 102 |
ADCSBB 8(up), %r9 |
| 103 |
mov %r9, 8(rp) |
| 104 |
ADCSBB 16(up), %r10 |
| 105 |
mov %r10, 16(rp) |
| 106 |
sbb R32(%rax), R32(%rax) C save carry |
| 107 |
lea 24(up), up |
| 108 |
lea 24(vp), vp |
| 109 |
lea 24(rp), rp |
| 110 |
sub $3, n |
| 111 |
jnz L(top) |
| 112 |
jmp L(end) |
| 113 |
|
| 114 |
L(x0): xor R32(%rax), R32(%rax) |
| 115 |
test $2, R8(n) |
| 116 |
jz L(top) |
| 117 |
|
| 118 |
L(b2): mov (vp), %rdi |
| 119 |
mov 8(vp), %r9 |
| 120 |
and cnd, %rdi |
| 121 |
and cnd, %r9 |
| 122 |
ADDSUB (up), %rdi |
| 123 |
mov %rdi, (rp) |
| 124 |
ADCSBB 8(up), %r9 |
| 125 |
mov %r9, 8(rp) |
| 126 |
sbb R32(%rax), R32(%rax) C save carry |
| 127 |
lea 16(up), up |
| 128 |
lea 16(vp), vp |
| 129 |
lea 16(rp), rp |
| 130 |
sub $2, n |
| 131 |
jnz L(top) |
| 132 |
jmp L(end) |
| 133 |
|
| 134 |
L(b1): mov (vp), %rdi |
| 135 |
and cnd, %rdi |
| 136 |
ADDSUB (up), %rdi |
| 137 |
mov %rdi, (rp) |
| 138 |
sbb R32(%rax), R32(%rax) C save carry |
| 139 |
lea 8(up), up |
| 140 |
lea 8(vp), vp |
| 141 |
lea 8(rp), rp |
| 142 |
dec n |
| 143 |
jz L(end) |
| 144 |
|
| 145 |
ALIGN(16) |
| 146 |
L(top): mov (vp), %rdi |
| 147 |
mov 8(vp), %r9 |
| 148 |
mov 16(vp), %r10 |
| 149 |
mov 24(vp), %r11 |
| 150 |
lea 32(vp), vp |
| 151 |
and cnd, %rdi |
| 152 |
and cnd, %r9 |
| 153 |
and cnd, %r10 |
| 154 |
and cnd, %r11 |
| 155 |
add R32(%rax), R32(%rax) C restore carry |
| 156 |
ADCSBB (up), %rdi |
| 157 |
mov %rdi, (rp) |
| 158 |
ADCSBB 8(up), %r9 |
| 159 |
mov %r9, 8(rp) |
| 160 |
ADCSBB 16(up), %r10 |
| 161 |
mov %r10, 16(rp) |
| 162 |
ADCSBB 24(up), %r11 |
| 163 |
lea 32(up), up |
| 164 |
mov %r11, 24(rp) |
| 165 |
lea 32(rp), rp |
| 166 |
sbb R32(%rax), R32(%rax) C save carry |
| 167 |
sub $4, n |
| 168 |
jnz L(top) |
| 169 |
|
| 170 |
L(end): neg R32(%rax) |
| 171 |
pop %rbx |
| 172 |
FUNC_EXIT() |
| 173 |
ret |
| 174 |
EPILOGUE() |