| 1 |
dnl X86-64 mpn_rsh1add_n, mpn_rsh1sub_n optimised for Intel Conroe/Penryn. |
| 2 |
|
| 3 |
dnl Copyright 2003, 2005, 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 ? |
| 35 |
C AMD K10 ? |
| 36 |
C Intel P4 ? |
| 37 |
C Intel core2 3.05 |
| 38 |
C Intel NHM 3.3 |
| 39 |
C Intel SBR 2.5 |
| 40 |
C Intel atom ? |
| 41 |
C VIA nano ? |
| 42 |
|
| 43 |
C TODO |
| 44 |
C * Loopmix to approach 2.5 c/l on NHM. |
| 45 |
|
| 46 |
C INPUT PARAMETERS |
| 47 |
define(`rp', `%rdi') |
| 48 |
define(`up', `%rsi') |
| 49 |
define(`vp', `%rdx') |
| 50 |
define(`n', `%rcx') |
| 51 |
|
| 52 |
ifdef(`OPERATION_rsh1add_n', ` |
| 53 |
define(ADDSUB, add) |
| 54 |
define(ADCSBB, adc) |
| 55 |
define(func_n, mpn_rsh1add_n) |
| 56 |
define(func_nc, mpn_rsh1add_nc)') |
| 57 |
ifdef(`OPERATION_rsh1sub_n', ` |
| 58 |
define(ADDSUB, sub) |
| 59 |
define(ADCSBB, sbb) |
| 60 |
define(func_n, mpn_rsh1sub_n) |
| 61 |
define(func_nc, mpn_rsh1sub_nc)') |
| 62 |
|
| 63 |
MULFUNC_PROLOGUE(mpn_rsh1add_n mpn_rsh1add_nc mpn_rsh1sub_n mpn_rsh1sub_nc) |
| 64 |
|
| 65 |
ABI_SUPPORT(DOS64) |
| 66 |
ABI_SUPPORT(STD64) |
| 67 |
|
| 68 |
ASM_START() |
| 69 |
TEXT |
| 70 |
ALIGN(16) |
| 71 |
PROLOGUE(func_nc) |
| 72 |
FUNC_ENTRY(4) |
| 73 |
IFDOS(` mov 56(%rsp), %r8 ') |
| 74 |
push %rbx |
| 75 |
push %rbp |
| 76 |
|
| 77 |
neg %r8 C set C flag from parameter |
| 78 |
mov (up), %r8 |
| 79 |
ADCSBB (vp), %r8 |
| 80 |
jmp L(ent) |
| 81 |
EPILOGUE() |
| 82 |
|
| 83 |
ALIGN(16) |
| 84 |
PROLOGUE(func_n) |
| 85 |
FUNC_ENTRY(4) |
| 86 |
push %rbx |
| 87 |
push %rbp |
| 88 |
|
| 89 |
mov (up), %r8 |
| 90 |
ADDSUB (vp), %r8 |
| 91 |
L(ent): sbb R32(%rbx), R32(%rbx) C save cy |
| 92 |
mov %r8, %rax |
| 93 |
and $1, R32(%rax) C return value |
| 94 |
|
| 95 |
lea (up,n,8), up |
| 96 |
lea (vp,n,8), vp |
| 97 |
lea (rp,n,8), rp |
| 98 |
mov R32(n), R32(%rbp) |
| 99 |
neg n |
| 100 |
and $3, R32(%rbp) |
| 101 |
jz L(b0) |
| 102 |
cmp $2, R32(%rbp) |
| 103 |
jae L(n1) |
| 104 |
|
| 105 |
L(b1): mov %r8, %rbp |
| 106 |
inc n |
| 107 |
js L(top) |
| 108 |
jmp L(end) |
| 109 |
|
| 110 |
L(n1): jnz L(b3) |
| 111 |
add R32(%rbx), R32(%rbx) C restore cy |
| 112 |
mov 8(up,n,8), %r11 |
| 113 |
ADCSBB 8(vp,n,8), %r11 |
| 114 |
sbb R32(%rbx), R32(%rbx) C save cy |
| 115 |
mov %r8, %r10 |
| 116 |
add $-2, n |
| 117 |
jmp L(2) |
| 118 |
|
| 119 |
L(b3): add R32(%rbx), R32(%rbx) C restore cy |
| 120 |
mov 8(up,n,8), %r10 |
| 121 |
mov 16(up,n,8), %r11 |
| 122 |
ADCSBB 8(vp,n,8), %r10 |
| 123 |
ADCSBB 16(vp,n,8), %r11 |
| 124 |
sbb R32(%rbx), R32(%rbx) C save cy |
| 125 |
mov %r8, %r9 |
| 126 |
dec n |
| 127 |
jmp L(3) |
| 128 |
|
| 129 |
L(b0): add R32(%rbx), R32(%rbx) C restore cy |
| 130 |
mov 8(up,n,8), %r9 |
| 131 |
mov 16(up,n,8), %r10 |
| 132 |
mov 24(up,n,8), %r11 |
| 133 |
ADCSBB 8(vp,n,8), %r9 |
| 134 |
ADCSBB 16(vp,n,8), %r10 |
| 135 |
ADCSBB 24(vp,n,8), %r11 |
| 136 |
sbb R32(%rbx), R32(%rbx) C save cy |
| 137 |
jmp L(4) |
| 138 |
|
| 139 |
ALIGN(16) |
| 140 |
|
| 141 |
L(top): add R32(%rbx), R32(%rbx) C restore cy |
| 142 |
mov (up,n,8), %r8 |
| 143 |
mov 8(up,n,8), %r9 |
| 144 |
mov 16(up,n,8), %r10 |
| 145 |
mov 24(up,n,8), %r11 |
| 146 |
ADCSBB (vp,n,8), %r8 |
| 147 |
ADCSBB 8(vp,n,8), %r9 |
| 148 |
ADCSBB 16(vp,n,8), %r10 |
| 149 |
ADCSBB 24(vp,n,8), %r11 |
| 150 |
sbb R32(%rbx), R32(%rbx) C save cy |
| 151 |
shrd $1, %r8, %rbp |
| 152 |
mov %rbp, -8(rp,n,8) |
| 153 |
L(4): shrd $1, %r9, %r8 |
| 154 |
mov %r8, (rp,n,8) |
| 155 |
L(3): shrd $1, %r10, %r9 |
| 156 |
mov %r9, 8(rp,n,8) |
| 157 |
L(2): shrd $1, %r11, %r10 |
| 158 |
mov %r10, 16(rp,n,8) |
| 159 |
L(1): add $4, n |
| 160 |
mov %r11, %rbp |
| 161 |
js L(top) |
| 162 |
|
| 163 |
L(end): shrd $1, %rbx, %rbp |
| 164 |
mov %rbp, -8(rp) |
| 165 |
pop %rbp |
| 166 |
pop %rbx |
| 167 |
FUNC_EXIT() |
| 168 |
ret |
| 169 |
EPILOGUE() |