dnl AMD K6 mpn_divexact_1 -- mpn by limb exact division.
dnl Copyright 2000-2002, 2007 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 divisor
C odd even
C K6: 10.0 12.0 cycles/limb
C K6-2: 10.0 11.5
C void mpn_divexact_1 (mp_ptr dst, mp_srcptr src, mp_size_t size,
C mp_limb_t divisor);
C
C A simple divl is used for size==1. This is about 10 cycles faster for an
C odd divisor or 20 cycles for an even divisor.
C
C The loops are quite sensitive to code alignment, speeds should be
C rechecked (odd andeven divisor, pic and non-pic) if contemplating
C changing anything.
subl %eax, %ebp C inv = 2*inv - inv*inv*d
leal (%ebp,%ebp), %eax C 2*inv
imull %ebp, %ebp C inv*inv
movl %esi, PARAM_DIVISOR C d without twos
leal (%ebx,%ecx,4), %ebx C src end
imull %esi, %ebp C inv*inv*d
leal (%edi,%ecx,4), %edi C dst end
negl %ecx C -size
subl %ebp, %eax C inv = 2*inv - inv*inv*d
subl $1, %edx C shift amount, and clear carry
ASSERT(e,` C expect d*inv == 1 mod 2^GMP_LIMB_BITS
pushl %eax FRAME_pushl()
imull PARAM_DIVISOR, %eax
cmpl $1, %eax
popl %eax FRAME_popl()')
movl %eax, VAR_INVERSE jnz L(even)
movl (%ebx,%ecx,4), %esi C src low limb jmp L(odd_entry)
ALIGN(16) nop C code alignment
L(odd_top):
C eax scratch
C ebx src end
C ecx counter, limbs, negative
C edx inverse
C esi next limb, adjusted forcarry
C edi dst end
C ebpcarry bit, 0 or -1
L(even):
C eax
C ebx src end
C ecx -size
C edx twos
C esi
C edi dst end
C ebp
xorl %ebp, %ebp
Zdisp( movq, 0,(%ebx,%ecx,4), %mm0) C src[0,1]
movd %edx, %mm7
movl VAR_INVERSE, %edx
addl $2, %ecx
psrlq %mm7, %mm0
movd %mm0, %esi jz L(even_two) C if only two limbs
C Out-of-order execution is good enough to hide the load/rshift/movd
C latency. Having imul at the top of the loop gives 11.5 c/l instead of 12,
C on K6-2. In fact there's only 11 of decode, but nothing running at 11 has
C been found. Maybe the fact every second movq is unaligned costs the extra
C 0.5.
L(even_top):
C eax scratch
C ebx src end
C ecx counter, limbs, negative
C edx inverse
C esi next limb, adjusted forcarry
C edi dst end
C ebpcarry bit, 0 or -1
C
C mm0 scratch, source limbs
C mm7 twos
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.