dnl AMD K7 mpn_sqr_basecase -- square an mpn number.
dnl Copyright 1999-2002 Free Software Foundation, Inc.
dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of either:
dnl
dnl * the GNU Lesser General Public License as published by the Free
dnl Software Foundation; either version 3 of the License, or (at your
dnl option) any later version.
dnl
dnl or
dnl
dnl * the GNU General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option) any
dnl later version.
dnl
dnl or both in parallel, as here.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dnl for more details.
dnl
dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.
include(`../config.m4')
C K7: approx 2.3 cycles/crossproduct, or 4.55 cycles/triangular product
C (measured on the speed difference between 25 and 50 limbs, which is
C roughly the Karatsuba recursing range).
dnl These are the same as mpn/x86/k6/sqr_basecase.asm, see that codefor
dnl some comments.
C void mpn_sqr_basecase (mp_ptr dst, mp_srcptr src, mp_size_t size);
C
C With a SQR_TOOM2_THRESHOLD around 50 thiscode is about 1500 bytes,
C which is quite a bit, but is considered good value since squares big
C enough to use most of the code will be spending quite a few cycles in it.
movl PARAM_DST, %edx je L(two_limbs)
ja L(three_or_more)
C------------------------------------------------------------------------------
C one limb only
C eax src
C ecx size
C edx dst
movl (%eax), %eax
movl %edx, %ecx
mull %eax
movl %edx, 4(%ecx)
movl %eax, (%ecx) ret
C------------------------------------------------------------------------------
C
C Using the read/modify/write "add"s seems to be faster than saving and
C restoring registers. Perhaps the loads for the first set hide under the
C mul latency and the second gets store to load forwarding.
ALIGN(16)
L(two_limbs):
C eax src
C ebx
C ecx size
C edx dst
deflit(`FRAME',0)
C------------------------------------------------------------------------------
C Three limbs
C
C Writing out the loads and stores separately at the end of thiscode comes
C out about 10 cycles faster than using adcls to memory.
C Add products src[n]*src[n+1..size-1] at dst[2*n-1...], for each n=1..size-2.
C
C The last two products, which are the bottom right corner of the product
C triangle, are left to the end. These are src[size-3]*src[size-2,size-1]
C and src[size-2]*src[size-1]. If size is 4 then it's only these corner
C cases that need to be done.
C
C The unrolled code is the same as in mpn_addmul_1, see that routine for
C some comments.
C
C VAR_COUNTER is the outer loop, running from -size+4 to -1, inclusive.
C
C VAR_JMP is the computed jump into the unrolled code, stepped by one code
C chunk each outer loop.
C
C K7 does branch prediction on indirect jumps, which is bad since it's a
C different target each time. There seems no way to avoid this.
dnl This value also hard coded in some shifts and adds
deflit(CODE_BYTES_PER_LIMB, 17)
dnl With the unmodified &src[size] and &dst[size] pointers, the
dnl displacements in the unrolled code fit in a bytefor UNROLL_COUNT
dnl values up to 31, but above that an offset must be added to them.
dnl Because the last chunk of code is generated differently, a label placed
dnl at the end doesn't work. Instead calculate the implied end using the
dnl start and how many chunks of code there are.
C The calculated jump mustn't come out to before the start of the
C code available. This is the limit UNROLL_COUNT puts on the src
C operand size, but checked here directly using the jump address.
ASSERT(ae,
`movl_text_address(L(unroll_inner_start), %eax)
cmpl %eax, %ecx')
C------------------------------------------------------------------------------ ALIGN(16)
L(unroll_outer_top):
C eax
C ebx high limb to store
C ecx VAR_JMP
C edx VAR_COUNTER, limbs, negative
C esi &src[size], constant
C edi dst ptr, high of last addmul
C ebp
movl -12+OFFSET(%esi,%edx,4), %ebp C next multiplier
movl -8+OFFSET(%esi,%edx,4), %eax C first of multiplicand
C Must be an even address to preserve the significance of the low
C bit of the jump address indicating which way around ecx/ebx should
C start. ALIGN(2)
L(unroll_inner_start):
C eax next limb
C ebx carry high
C ecxcarry low
C edx scratch
C esi src
C edi dst
C ebp multiplier
movl PARAM_SRC, %esi
movl %eax, -4(%edi) C dst most significant limb
movl PARAM_SIZE, %ecx
C Now add in the squares on the diagonal, src[0]^2, src[1]^2, ...,
C src[size-1]^2. dst[0] hasn't yet been set at all yet, and just gets the
C low limb of src[0]^2.
movl (%esi), %eax C src[0]
mull %eax
leal (%esi,%ecx,4), %esi C src point just after last limb
negl %ecx
movl %eax, (%edi,%ecx,8) C dst[0]
incl %ecx
L(diag):
C eax scratch
C ebx scratch
C ecx counter, negative
C edxcarry
C esi src just after last limb
C edi dst just after last limb
C ebp
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.