github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/x86/k6/k62mmx/copyd.asm (about) 1 dnl AMD K6-2 mpn_copyd -- copy limb vector, decrementing. 2 3 dnl Copyright 2001, 2002 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 K6-2: 1.0 cycles/limb 35 36 37 C void mpn_copyd (mp_ptr dst, mp_srcptr src, mp_size_t size); 38 C 39 C The loop here is no faster than a rep movsl at 1.0 c/l, but it avoids a 30 40 C cycle startup time, which amounts for instance to a 2x speedup at 15 41 C limbs. 42 C 43 C If dst is 4mod8 the loop would be 1.17 c/l, but that's avoided by 44 C processing one limb separately to make it aligned. This and a final odd 45 C limb are handled in a branch-free fashion, ending up re-copying if the 46 C special case isn't needed. 47 C 48 C Alternatives: 49 C 50 C There used to be a big unrolled version of this, running at 0.56 c/l if 51 C the destination was aligned, but that seemed rather excessive for the 52 C relative importance of copyd. 53 C 54 C If the destination alignment is ignored and just left to run at 1.17 c/l 55 C some code size and a fixed few cycles can be saved. Considering how few 56 C uses copyd finds perhaps that should be favoured. The current code has 57 C the attraction of being no slower than a basic rep movsl though. 58 59 defframe(PARAM_SIZE,12) 60 defframe(PARAM_SRC, 8) 61 defframe(PARAM_DST, 4) 62 63 dnl re-using parameter space 64 define(SAVE_EBX,`PARAM_SIZE') 65 66 TEXT 67 ALIGN(16) 68 69 PROLOGUE(mpn_copyd) 70 deflit(`FRAME',0) 71 72 movl PARAM_SIZE, %ecx 73 movl %ebx, SAVE_EBX 74 75 movl PARAM_SRC, %eax 76 movl PARAM_DST, %edx 77 78 subl $1, %ecx C better code alignment than decl 79 jb L(zero) 80 81 jz L(one_more) 82 leal 4(%edx,%ecx,4), %ebx 83 84 Zdisp( movd, 0,(%eax,%ecx,4), %mm0) C high limb 85 Zdisp( movd, %mm0, 0,(%edx,%ecx,4)) C Zdisp for good code alignment 86 87 cmpl $1, %ecx 88 je L(one_more) 89 90 shrl $2, %ebx 91 andl $1, %ebx C 1 if dst[size-2] unaligned 92 93 subl %ebx, %ecx 94 nop C code alignment 95 96 L(top): 97 C eax src 98 C ebx 99 C ecx counter 100 C edx dst 101 102 movq -4(%eax,%ecx,4), %mm0 103 subl $2, %ecx 104 105 movq %mm0, 4(%edx,%ecx,4) 106 ja L(top) 107 108 109 L(one_more): 110 movd (%eax), %mm0 111 movd %mm0, (%edx) 112 113 movl SAVE_EBX, %ebx 114 emms_or_femms 115 L(zero): 116 ret 117 118 EPILOGUE()