| 1 |
dnl AMD64 mpn_com optimised for CPUs with fast SSE. |
| 2 |
|
| 3 |
dnl Copyright 2003, 2005, 2007, 2011, 2012 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
dnl Contributed to the GNU project by Torbjorn Granlund. |
| 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 cycles/limb cycles/limb good |
| 36 |
C aligned unaligned best seen for cpu? |
| 37 |
C AMD K8,K9 2.0 2.0 N |
| 38 |
C AMD K10 0.85 1.3 Y/N |
| 39 |
C AMD bd1 1.40 1.40 Y |
| 40 |
C AMD bobcat 3.1 3.1 N |
| 41 |
C Intel P4 2.28 illop Y |
| 42 |
C Intel core2 1.02 1.02 N |
| 43 |
C Intel NHM 0.53 0.68 Y |
| 44 |
C Intel SBR 0.51 0.75 Y |
| 45 |
C Intel atom 3.68 3.68 N |
| 46 |
C VIA nano 1.17 5.09 Y/N |
| 47 |
|
| 48 |
C We try to do as many 16-byte operations as possible. The top-most and |
| 49 |
C bottom-most writes might need 8-byte operations. We can always write using |
| 50 |
C aligned 16-byte operations, we read with both aligned and unaligned 16-byte |
| 51 |
C operations. |
| 52 |
|
| 53 |
C Instead of having separate loops for reading aligned and unaligned, we read |
| 54 |
C using MOVDQU. This seems to work great except for core2; there performance |
| 55 |
C doubles when reading using MOVDQA (for aligned source). It is unclear how to |
| 56 |
C best handle the unaligned case there. |
| 57 |
|
| 58 |
C INPUT PARAMETERS |
| 59 |
define(`rp', `%rdi') |
| 60 |
define(`up', `%rsi') |
| 61 |
define(`n', `%rdx') |
| 62 |
|
| 63 |
ABI_SUPPORT(DOS64) |
| 64 |
ABI_SUPPORT(STD64) |
| 65 |
|
| 66 |
ASM_START() |
| 67 |
TEXT |
| 68 |
ALIGN(16) |
| 69 |
PROLOGUE(mpn_com) |
| 70 |
FUNC_ENTRY(3) |
| 71 |
|
| 72 |
test n, n |
| 73 |
jz L(don) |
| 74 |
|
| 75 |
pcmpeqb %xmm7, %xmm7 C set to 111...111 |
| 76 |
|
| 77 |
test $8, R8(rp) C is rp 16-byte aligned? |
| 78 |
jz L(ali) C jump if rp aligned |
| 79 |
mov (up), %rax |
| 80 |
lea 8(up), up |
| 81 |
not %rax |
| 82 |
mov %rax, (rp) |
| 83 |
lea 8(rp), rp |
| 84 |
dec n |
| 85 |
|
| 86 |
sub $14, n |
| 87 |
jc L(sma) |
| 88 |
|
| 89 |
ALIGN(16) |
| 90 |
L(top): movdqu (up), %xmm0 |
| 91 |
movdqu 16(up), %xmm1 |
| 92 |
movdqu 32(up), %xmm2 |
| 93 |
movdqu 48(up), %xmm3 |
| 94 |
movdqu 64(up), %xmm4 |
| 95 |
movdqu 80(up), %xmm5 |
| 96 |
movdqu 96(up), %xmm6 |
| 97 |
lea 112(up), up |
| 98 |
pxor %xmm7, %xmm0 |
| 99 |
pxor %xmm7, %xmm1 |
| 100 |
pxor %xmm7, %xmm2 |
| 101 |
pxor %xmm7, %xmm3 |
| 102 |
pxor %xmm7, %xmm4 |
| 103 |
pxor %xmm7, %xmm5 |
| 104 |
pxor %xmm7, %xmm6 |
| 105 |
movdqa %xmm0, (rp) |
| 106 |
movdqa %xmm1, 16(rp) |
| 107 |
movdqa %xmm2, 32(rp) |
| 108 |
movdqa %xmm3, 48(rp) |
| 109 |
movdqa %xmm4, 64(rp) |
| 110 |
movdqa %xmm5, 80(rp) |
| 111 |
movdqa %xmm6, 96(rp) |
| 112 |
lea 112(rp), rp |
| 113 |
L(ali): sub $14, n |
| 114 |
jnc L(top) |
| 115 |
|
| 116 |
L(sma): add $14, n |
| 117 |
test $8, R8(n) |
| 118 |
jz 1f |
| 119 |
movdqu (up), %xmm0 |
| 120 |
movdqu 16(up), %xmm1 |
| 121 |
movdqu 32(up), %xmm2 |
| 122 |
movdqu 48(up), %xmm3 |
| 123 |
lea 64(up), up |
| 124 |
pxor %xmm7, %xmm0 |
| 125 |
pxor %xmm7, %xmm1 |
| 126 |
pxor %xmm7, %xmm2 |
| 127 |
pxor %xmm7, %xmm3 |
| 128 |
movdqa %xmm0, (rp) |
| 129 |
movdqa %xmm1, 16(rp) |
| 130 |
movdqa %xmm2, 32(rp) |
| 131 |
movdqa %xmm3, 48(rp) |
| 132 |
lea 64(rp), rp |
| 133 |
1: |
| 134 |
test $4, R8(n) |
| 135 |
jz 1f |
| 136 |
movdqu (up), %xmm0 |
| 137 |
movdqu 16(up), %xmm1 |
| 138 |
lea 32(up), up |
| 139 |
pxor %xmm7, %xmm0 |
| 140 |
pxor %xmm7, %xmm1 |
| 141 |
movdqa %xmm0, (rp) |
| 142 |
movdqa %xmm1, 16(rp) |
| 143 |
lea 32(rp), rp |
| 144 |
1: |
| 145 |
test $2, R8(n) |
| 146 |
jz 1f |
| 147 |
movdqu (up), %xmm0 |
| 148 |
lea 16(up), up |
| 149 |
pxor %xmm7, %xmm0 |
| 150 |
movdqa %xmm0, (rp) |
| 151 |
lea 16(rp), rp |
| 152 |
1: |
| 153 |
test $1, R8(n) |
| 154 |
jz 1f |
| 155 |
mov (up), %rax |
| 156 |
not %rax |
| 157 |
mov %rax, (rp) |
| 158 |
1: |
| 159 |
L(don): FUNC_EXIT() |
| 160 |
ret |
| 161 |
EPILOGUE() |