dnl AMD K7 mpn_mul_basecase -- multiply two mpn numbers.
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 4.42 cycles per cross product at around 20x20 limbs (16
C limbs/loop unrolling).
dnl K7 UNROLL_COUNT cycles/product (at around 20x20)
dnl 8 4.67
dnl 16 4.59
dnl 32 4.42
dnl Maximum possible with the current code is 32.
dnl
dnl At 32 the typical 13-26 limb sizes from the karatsuba code will get
dnl done with a straight run through a block of code, no inner loop. Using
dnl 32 gives 1k of code, but the k7 has a 64k L1 code cache.
deflit(UNROLL_COUNT, 32)
C void mpn_mul_basecase (mp_ptr wp,
C mp_srcptr xp, mp_size_t xsize,
C mp_srcptr yp, mp_size_t ysize);
C
C Calculate xp,xsize multiplied by yp,ysize, storing the result in
C wp,xsize+ysize.
C
C This routine is essentially the same as mpn/generic/mul_basecase.c, but
C it's faster because it does most of the mpn_addmul_1() startup
C calculations only once. The saving is 15-25% on typical sizes coming from
C the Karatsuba multiply code.
C ----------------------------------------------------------------------------- ALIGN(16)
L(xsize_more_than_two):
C The first limb of yp is processed with a simple mpn_mul_1 style loop
C inline. Unrolling this doesn't seem worthwhile since it's only run once
C (whereas the addmul below is run ysize-1 many times). A call to the
C actual mpn_mul_1 will be slowed down by the calland parameter pushing and
C popping, and doesn't seem likely to be worthwhile on the typical 13-26
C limb operations the Karatsuba code calls here with.
C eax yp[0]
C ebx
C ecx xsize
C edx xp
C esi
C edi
C ebp
dnl FRAME doesn't carry on from previous, no pushes yet here
defframe(`SAVE_EBX',-4)
defframe(`SAVE_ESI',-8)
defframe(`SAVE_EDI',-12)
defframe(`SAVE_EBP',-16)
deflit(`FRAME',0)
C -----------------------------------------------------------------------------
C simple addmul looping
C
C eax yp
C ebx
C ecx xsize
C edx ysize-1
C esi xp end
C edi wp end of mul1
C ebp
leal 4(%eax,%edx,4), %ebp C yp end
negl %ecx
negl %edx
movl (%esi,%ecx,4), %eax C xp low limb
movl %edx, PARAM_YSIZE C -(ysize-1)
incl %ecx
xorl %ebx, %ebx C initial carry
movl %ecx, PARAM_XSIZE C -(xsize-1)
movl %ebp, PARAM_YP
movl (%ebp,%edx,4), %ebp C yp second lowest limb - multiplier jmp L(simple_outer_entry)
C this is offset 0x121 so close enough to aligned
L(simple_outer_top):
C ebp ysize counter, negative
movl PARAM_YP, %edx
movl PARAM_XSIZE, %ecx C -(xsize-1)
xorl %ebx, %ebx C carry
movl %ebp, PARAM_YSIZE
addl $4, %edi C next position in wp
movl (%edx,%ebp,4), %ebp C yp limb - multiplier
movl -4(%esi,%ecx,4), %eax C xp low limb
L(simple_outer_entry):
L(simple_inner):
C eax xp limb
C ebx carry limb
C ecx loop counter (negative)
C edx scratch
C esi xp end
C edi wp end
C ebp multiplier
C -----------------------------------------------------------------------------
C
C The unrolled loop is the same as in mpn_addmul_1(), see that codefor some
C comments.
C
C VAR_ADJUST is the negative of how many limbs the leals in the inner loop
C increment xp and wp. This is used to adjust back xp and wp, and rshifted
C to given an initial VAR_COUNTER at the top of the outer loop.
C
C VAR_COUNTER is for the unrolled loop, running from VAR_ADJUST/UNROLL_COUNT
C up to -1, inclusive.
C
C VAR_JMP is the computed jump into the unrolled loop.
C
C VAR_XP_LOW is the least significant limb of xp, which is needed at the
C start of the unrolled loop.
C
C PARAM_YSIZE is the outer loop counter, going from -(ysize-1) up to -1,
C inclusive.
C
C PARAM_YP is offset appropriately so that the PARAM_YSIZE counter can be
C added to give the location of the next limb of yp, which is the multiplier
C in the unrolled loop.
C
C The trick with VAR_ADJUST means it's only necessary to do one fetch in the
C outer loop to take care of xp, wp and the inner loop counter.
C 17 code bytes per limb ifdef(`PIC',` call L(pic_calc)
L(unroll_here): ',`
leal L(unroll_entry) (%ecx,%edx,1), %ecx ')
negl %edx
movl %eax, VAR_XP_LOW
movl %ecx, VAR_JMP
leal 4(%edi,%edx,4), %edi C wp and xp, adjust for unrolling,
leal 4(%esi,%edx,4), %esi C and start at second limb jmp L(unroll_outer_entry)
ifdef(`PIC',`
L(pic_calc):
C See mpn/x86/README about old gas bugs
leal (%ecx,%edx,1), %ecx
addl $L(unroll_entry)-L(unroll_here), %ecx
addl (%esp), %ecx
ret_internal ')
C -------------------------------------------------------------------------- ALIGN(32)
L(unroll_outer_top):
C ebp ysize counter, negative
movl VAR_ADJUST, %ebx
movl PARAM_YP, %edx
movl VAR_XP_LOW, %eax
movl %ebp, PARAM_YSIZE C store incremented ysize counter
movl (%edx,%ebp,4), %ebp C yp next multiplier
movl VAR_JMP, %ecx
L(unroll_outer_entry):
mull %ebp
testb $1, %cl C and clear carry bit
movl %ebx, VAR_COUNTER
movl $0, %ebx
movl $0, %ecx
cmovz( %eax, %ecx) C eax into low carry, zero into high carry limb
cmovnz( %eax, %ebx)
C Extra fetch of VAR_JMP is bad, but registers are tight jmp *VAR_JMP
C ----------------------------------------------------------------------------- ALIGN(32)
L(unroll_top):
C eax xp limb
C ebx carry high
C ecxcarry low
C edx scratch
C esi xp+8
C edi wp
C ebp yp multiplier limb
C
C VAR_COUNTER loop counter, negative
C
C 17 bytes each limb
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.