| 1 |
dnl x86-64 mpn_divrem_1 -- mpn by limb division. |
| 2 |
|
| 3 |
dnl Copyright 2004, 2005, 2007-2010, 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 |
|
| 34 |
C norm unorm frac |
| 35 |
C AMD K8,K9 15 15 12 |
| 36 |
C AMD K10 15 15 12 |
| 37 |
C Intel P4 44 44 43 |
| 38 |
C Intel core2 24 24 19.5 |
| 39 |
C Intel corei 19 19 18 |
| 40 |
C Intel atom 51 51 36 |
| 41 |
C VIA nano 46 44 22.5 |
| 42 |
|
| 43 |
C mp_limb_t |
| 44 |
C mpn_divrem_1 (mp_ptr qp, mp_size_t fn, |
| 45 |
C mp_srcptr np, mp_size_t nn, mp_limb_t d) |
| 46 |
|
| 47 |
C mp_limb_t |
| 48 |
C mpn_preinv_divrem_1 (mp_ptr qp, mp_size_t fn, |
| 49 |
C mp_srcptr np, mp_size_t nn, mp_limb_t d, |
| 50 |
C mp_limb_t dinv, int cnt) |
| 51 |
|
| 52 |
C INPUT PARAMETERS |
| 53 |
define(`qp', `%rdi') |
| 54 |
define(`fn_param', `%rsi') |
| 55 |
define(`up_param', `%rdx') |
| 56 |
define(`un_param', `%rcx') |
| 57 |
define(`d', `%r8') |
| 58 |
define(`dinv', `%r9') C only for mpn_preinv_divrem_1 |
| 59 |
C shift passed on stack C only for mpn_preinv_divrem_1 |
| 60 |
|
| 61 |
define(`cnt', `%rcx') |
| 62 |
define(`up', `%rsi') |
| 63 |
define(`fn', `%r12') |
| 64 |
define(`un', `%rbx') |
| 65 |
|
| 66 |
|
| 67 |
C rax rbx rcx rdx rsi rdi rbp r8 r9 r10 r11 r12 r13 r14 r15 |
| 68 |
C cnt qp d dinv |
| 69 |
|
| 70 |
ABI_SUPPORT(DOS64) |
| 71 |
ABI_SUPPORT(STD64) |
| 72 |
|
| 73 |
IFSTD(`define(`CNTOFF', `40($1)')') |
| 74 |
IFDOS(`define(`CNTOFF', `104($1)')') |
| 75 |
|
| 76 |
ASM_START() |
| 77 |
TEXT |
| 78 |
ALIGN(16) |
| 79 |
PROLOGUE(mpn_preinv_divrem_1) |
| 80 |
FUNC_ENTRY(4) |
| 81 |
IFDOS(` mov 56(%rsp), %r8 ') |
| 82 |
IFDOS(` mov 64(%rsp), %r9 ') |
| 83 |
xor R32(%rax), R32(%rax) |
| 84 |
push %r13 |
| 85 |
push %r12 |
| 86 |
push %rbp |
| 87 |
push %rbx |
| 88 |
|
| 89 |
mov fn_param, fn |
| 90 |
mov un_param, un |
| 91 |
add fn_param, un_param |
| 92 |
mov up_param, up |
| 93 |
|
| 94 |
lea -8(qp,un_param,8), qp |
| 95 |
|
| 96 |
mov CNTOFF(%rsp), R8(cnt) |
| 97 |
shl R8(cnt), d |
| 98 |
jmp L(ent) |
| 99 |
EPILOGUE() |
| 100 |
|
| 101 |
ALIGN(16) |
| 102 |
PROLOGUE(mpn_divrem_1) |
| 103 |
FUNC_ENTRY(4) |
| 104 |
IFDOS(` mov 56(%rsp), %r8 ') |
| 105 |
xor R32(%rax), R32(%rax) |
| 106 |
push %r13 |
| 107 |
push %r12 |
| 108 |
push %rbp |
| 109 |
push %rbx |
| 110 |
|
| 111 |
mov fn_param, fn |
| 112 |
mov un_param, un |
| 113 |
add fn_param, un_param |
| 114 |
mov up_param, up |
| 115 |
je L(ret) |
| 116 |
|
| 117 |
lea -8(qp,un_param,8), qp |
| 118 |
xor R32(%rbp), R32(%rbp) |
| 119 |
|
| 120 |
L(unnormalized): |
| 121 |
test un, un |
| 122 |
je L(44) |
| 123 |
mov -8(up,un,8), %rax |
| 124 |
cmp d, %rax |
| 125 |
jae L(44) |
| 126 |
mov %rbp, (qp) |
| 127 |
mov %rax, %rbp |
| 128 |
lea -8(qp), qp |
| 129 |
je L(ret) |
| 130 |
dec un |
| 131 |
L(44): |
| 132 |
bsr d, %rcx |
| 133 |
not R32(%rcx) |
| 134 |
sal R8(%rcx), d |
| 135 |
sal R8(%rcx), %rbp |
| 136 |
|
| 137 |
push %rcx |
| 138 |
IFSTD(` push %rdi ') |
| 139 |
IFSTD(` push %rsi ') |
| 140 |
push %r8 |
| 141 |
IFSTD(` mov d, %rdi ') |
| 142 |
IFDOS(` mov d, %rcx ') |
| 143 |
CALL( mpn_invert_limb) |
| 144 |
pop %r8 |
| 145 |
IFSTD(` pop %rsi ') |
| 146 |
IFSTD(` pop %rdi ') |
| 147 |
pop %rcx |
| 148 |
|
| 149 |
mov %rax, dinv |
| 150 |
mov %rbp, %rax |
| 151 |
test un, un |
| 152 |
je L(frac) |
| 153 |
L(ent): mov -8(up,un,8), %rbp |
| 154 |
shr R8(%rcx), %rax |
| 155 |
shld R8(%rcx), %rbp, %rax |
| 156 |
sub $2, un |
| 157 |
js L(end) |
| 158 |
|
| 159 |
ALIGN(16) |
| 160 |
L(top): lea 1(%rax), %r11 |
| 161 |
mul dinv |
| 162 |
mov (up,un,8), %r10 |
| 163 |
shld R8(%rcx), %r10, %rbp |
| 164 |
mov %rbp, %r13 |
| 165 |
add %rax, %r13 |
| 166 |
adc %r11, %rdx |
| 167 |
mov %rdx, %r11 |
| 168 |
imul d, %rdx |
| 169 |
sub %rdx, %rbp |
| 170 |
lea (d,%rbp), %rax |
| 171 |
sub $8, qp |
| 172 |
cmp %r13, %rbp |
| 173 |
cmovc %rbp, %rax |
| 174 |
adc $-1, %r11 |
| 175 |
cmp d, %rax |
| 176 |
jae L(ufx) |
| 177 |
L(uok): dec un |
| 178 |
mov %r11, 8(qp) |
| 179 |
mov %r10, %rbp |
| 180 |
jns L(top) |
| 181 |
|
| 182 |
L(end): lea 1(%rax), %r11 |
| 183 |
sal R8(%rcx), %rbp |
| 184 |
mul dinv |
| 185 |
add %rbp, %rax |
| 186 |
adc %r11, %rdx |
| 187 |
mov %rax, %r11 |
| 188 |
mov %rdx, %r13 |
| 189 |
imul d, %rdx |
| 190 |
sub %rdx, %rbp |
| 191 |
mov d, %rax |
| 192 |
add %rbp, %rax |
| 193 |
cmp %r11, %rbp |
| 194 |
cmovc %rbp, %rax |
| 195 |
adc $-1, %r13 |
| 196 |
cmp d, %rax |
| 197 |
jae L(efx) |
| 198 |
L(eok): mov %r13, (qp) |
| 199 |
sub $8, qp |
| 200 |
jmp L(frac) |
| 201 |
|
| 202 |
L(ufx): sub d, %rax |
| 203 |
inc %r11 |
| 204 |
jmp L(uok) |
| 205 |
L(efx): sub d, %rax |
| 206 |
inc %r13 |
| 207 |
jmp L(eok) |
| 208 |
|
| 209 |
L(frac):mov d, %rbp |
| 210 |
neg %rbp |
| 211 |
jmp L(fent) |
| 212 |
|
| 213 |
ALIGN(16) C K8-K10 P6-CNR P6-NHM P4 |
| 214 |
L(ftop):mul dinv C 0,12 0,17 0,17 |
| 215 |
add %r11, %rdx C 5 8 10 |
| 216 |
mov %rax, %r11 C 4 8 3 |
| 217 |
mov %rdx, %r13 C 6 9 11 |
| 218 |
imul %rbp, %rdx C 6 9 11 |
| 219 |
mov d, %rax C |
| 220 |
add %rdx, %rax C 10 14 14 |
| 221 |
cmp %r11, %rdx C 10 14 14 |
| 222 |
cmovc %rdx, %rax C 11 15 15 |
| 223 |
adc $-1, %r13 C |
| 224 |
mov %r13, (qp) C |
| 225 |
sub $8, qp C |
| 226 |
L(fent):lea 1(%rax), %r11 C |
| 227 |
dec fn C |
| 228 |
jns L(ftop) C |
| 229 |
|
| 230 |
shr R8(%rcx), %rax |
| 231 |
L(ret): pop %rbx |
| 232 |
pop %rbp |
| 233 |
pop %r12 |
| 234 |
pop %r13 |
| 235 |
FUNC_EXIT() |
| 236 |
ret |
| 237 |
EPILOGUE() |