version 1.1.1.1, 2000/09/09 14:12:44 |
version 1.1.1.2, 2003/08/25 16:06:29 |
|
|
dnl Intel Pentium-II mpn_divrem_1 -- mpn by limb division. |
dnl Intel Pentium-II mpn_divrem_1 -- mpn by limb division. |
dnl |
|
dnl P6MMX: 25.0 cycles/limb integer part, 17.5 cycles/limb fraction part. |
|
|
|
|
dnl Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
dnl Copyright (C) 1999, 2000 Free Software Foundation, Inc. |
|
dnl |
dnl |
dnl This file is part of the GNU MP Library. |
dnl This file is part of the GNU MP Library. |
dnl |
dnl |
Line 22 dnl License along with the GNU MP Library; see the fi |
|
Line 19 dnl License along with the GNU MP Library; see the fi |
|
dnl not, write to the Free Software Foundation, Inc., 59 Temple Place - |
dnl not, write to the Free Software Foundation, Inc., 59 Temple Place - |
dnl Suite 330, Boston, MA 02111-1307, USA. |
dnl Suite 330, Boston, MA 02111-1307, USA. |
|
|
|
|
include(`../config.m4') |
include(`../config.m4') |
|
|
|
|
|
C P6MMX: 25.0 cycles/limb integer part, 17.5 cycles/limb fraction part. |
|
|
|
|
C mp_limb_t mpn_divrem_1 (mp_ptr dst, mp_size_t xsize, |
C mp_limb_t mpn_divrem_1 (mp_ptr dst, mp_size_t xsize, |
C mp_srcptr src, mp_size_t size, |
C mp_srcptr src, mp_size_t size, |
C mp_limb_t divisor); |
C mp_limb_t divisor); |
C mp_limb_t mpn_divrem_1c (mp_ptr dst, mp_size_t xsize, |
C mp_limb_t mpn_divrem_1c (mp_ptr dst, mp_size_t xsize, |
C mp_srcptr src, mp_size_t size, |
C mp_srcptr src, mp_size_t size, |
C mp_limb_t divisor, mp_limb_t carry); |
C mp_limb_t divisor, mp_limb_t carry); |
|
C mp_limb_t mpn_preinv_divrem_1 (mp_ptr dst, mp_size_t xsize, |
|
C mp_srcptr src, mp_size_t size, |
|
C mp_limb_t divisor, mp_limb_t inverse, |
|
C unsigned shift); |
C |
C |
C This code is a lightly reworked version of mpn/x86/k7/mmx/divrem_1.asm, |
C This code is a lightly reworked version of mpn/x86/k7/mmx/divrem_1.asm, |
C see that file for some comments. It's likely what's here can be improved. |
C see that file for some comments. It's possible what's here can be improved. |
|
|
|
|
dnl MUL_THRESHOLD is the value of xsize+size at which the multiply by |
dnl MUL_THRESHOLD is the value of xsize+size at which the multiply by |
Line 52 dnl mul is much faster. |
|
Line 55 dnl mul is much faster. |
|
deflit(MUL_THRESHOLD, 4) |
deflit(MUL_THRESHOLD, 4) |
|
|
|
|
defframe(PARAM_CARRY, 24) |
defframe(PARAM_PREINV_SHIFT, 28) dnl mpn_preinv_divrem_1 |
|
defframe(PARAM_PREINV_INVERSE, 24) dnl mpn_preinv_divrem_1 |
|
defframe(PARAM_CARRY, 24) dnl mpn_divrem_1c |
defframe(PARAM_DIVISOR,20) |
defframe(PARAM_DIVISOR,20) |
defframe(PARAM_SIZE, 16) |
defframe(PARAM_SIZE, 16) |
defframe(PARAM_SRC, 12) |
defframe(PARAM_SRC, 12) |
Line 72 defframe(VAR_DST_STOP,-36) |
|
Line 77 defframe(VAR_DST_STOP,-36) |
|
|
|
deflit(STACK_SPACE, 36) |
deflit(STACK_SPACE, 36) |
|
|
.text |
TEXT |
ALIGN(16) |
ALIGN(16) |
|
|
|
PROLOGUE(mpn_preinv_divrem_1) |
|
deflit(`FRAME',0) |
|
movl PARAM_XSIZE, %ecx |
|
subl $STACK_SPACE, %esp FRAME_subl_esp(STACK_SPACE) |
|
|
|
movl %esi, SAVE_ESI |
|
movl PARAM_SRC, %esi |
|
|
|
movl %ebx, SAVE_EBX |
|
movl PARAM_SIZE, %ebx |
|
|
|
movl %ebp, SAVE_EBP |
|
movl PARAM_DIVISOR, %ebp |
|
|
|
movl %edi, SAVE_EDI |
|
movl PARAM_DST, %edx |
|
|
|
movl -4(%esi,%ebx,4), %eax C src high limb |
|
xorl %edi, %edi C initial carry (if can't skip a div) |
|
|
|
C |
|
|
|
leal 8(%edx,%ecx,4), %edx C &dst[xsize+2] |
|
xor %ecx, %ecx |
|
|
|
movl %edx, VAR_DST_STOP C &dst[xsize+2] |
|
cmpl %ebp, %eax C high cmp divisor |
|
|
|
cmovc( %eax, %edi) C high is carry if high<divisor |
|
|
|
cmovnc( %eax, %ecx) C 0 if skip div, src high if not |
|
C (the latter in case src==dst) |
|
|
|
movl %ecx, -12(%edx,%ebx,4) C dst high limb |
|
|
|
sbbl $0, %ebx C skip one division if high<divisor |
|
movl PARAM_PREINV_SHIFT, %ecx |
|
|
|
leal -8(%edx,%ebx,4), %edx C &dst[xsize+size] |
|
movl $32, %eax |
|
|
|
movl %edx, VAR_DST C &dst[xsize+size] |
|
|
|
shll %cl, %ebp C d normalized |
|
subl %ecx, %eax |
|
movl %ecx, VAR_NORM |
|
|
|
movd %eax, %mm7 C rshift |
|
movl PARAM_PREINV_INVERSE, %eax |
|
jmp L(start_preinv) |
|
|
|
EPILOGUE() |
|
|
|
|
|
|
|
ALIGN(16) |
|
|
PROLOGUE(mpn_divrem_1c) |
PROLOGUE(mpn_divrem_1c) |
deflit(`FRAME',0) |
deflit(`FRAME',0) |
movl PARAM_CARRY, %edx |
movl PARAM_CARRY, %edx |
Line 96 deflit(`FRAME',STACK_SPACE) |
|
Line 158 deflit(`FRAME',STACK_SPACE) |
|
movl PARAM_SRC, %esi |
movl PARAM_SRC, %esi |
|
|
leal -4(%edi,%ebx,4), %edi |
leal -4(%edi,%ebx,4), %edi |
jmp LF(mpn_divrem_1,start_1c) |
jmp L(start_1c) |
|
|
EPILOGUE() |
EPILOGUE() |
|
|
Line 118 deflit(`FRAME',STACK_SPACE) |
|
Line 180 deflit(`FRAME',STACK_SPACE) |
|
|
|
movl %esi, SAVE_ESI |
movl %esi, SAVE_ESI |
movl PARAM_SRC, %esi |
movl PARAM_SRC, %esi |
orl %ecx, %ecx |
orl %ecx, %ecx C size |
|
|
movl %edi, SAVE_EDI |
movl %edi, SAVE_EDI |
movl PARAM_DST, %edi |
movl PARAM_DST, %edi |
|
|
leal -4(%edi,%ebx,4), %edi C &dst[xsize-1] |
leal -4(%edi,%ebx,4), %edi C &dst[xsize-1] |
jz L(no_skip_div) |
jz L(no_skip_div) C if size==0 |
|
|
movl -4(%esi,%ecx,4), %eax C src high limb |
movl -4(%esi,%ecx,4), %eax C src high limb |
cmpl %ebp, %eax C one less div if high<divisor |
xorl %esi, %esi |
jnb L(no_skip_div) |
cmpl %ebp, %eax C high cmp divisor |
|
|
movl $0, (%edi,%ecx,4) C dst high limb |
cmovc( %eax, %edx) C high is carry if high<divisor |
decl %ecx C size-1 |
|
movl %eax, %edx C src high limb as initial carry |
cmovnc( %eax, %esi) C 0 if skip div, src high if not |
|
C (the latter in case src==dst) |
|
|
|
movl %esi, (%edi,%ecx,4) C dst high limb |
|
|
|
sbbl $0, %ecx C size-1 if high<divisor |
|
movl PARAM_SRC, %esi C reload |
L(no_skip_div): |
L(no_skip_div): |
|
|
|
|
Line 221 L(mul_by_inverse): |
|
Line 289 L(mul_by_inverse): |
|
C edi &dst[xsize-1] |
C edi &dst[xsize-1] |
C ebp divisor |
C ebp divisor |
|
|
leal 12(%edi), %ebx |
leal 12(%edi), %ebx C &dst[xsize+2], loop dst stop |
|
|
movl %ebx, VAR_DST_STOP |
movl %ebx, VAR_DST_STOP |
leal 4(%edi,%ecx,4), %edi C &dst[xsize+size] |
leal 4(%edi,%ecx,4), %edi C &dst[xsize+size] |
Line 246 L(mul_by_inverse): |
|
Line 314 L(mul_by_inverse): |
|
|
|
divl %ebp C floor (b*(b-d)-1) / d |
divl %ebp C floor (b*(b-d)-1) / d |
|
|
|
L(start_preinv): |
|
C eax inverse |
|
C ebx size |
|
C ecx shift |
|
C edx |
|
C esi src |
|
C edi carry |
|
C ebp divisor |
|
C |
|
C mm7 rshift |
|
|
movl %eax, VAR_INVERSE |
movl %eax, VAR_INVERSE |
orl %ebx, %ebx C size |
orl %ebx, %ebx C size |
leal -12(%esi,%ebx,4), %eax C &src[size-3] |
leal -12(%esi,%ebx,4), %eax C &src[size-3] |
|
|
|
|
|
|
L(start_zero): |
L(start_zero): |
|
C Can be here with xsize==0 if mpn_preinv_divrem_1 had size==1 and |
|
C skipped a division. |
|
|
shll %cl, %edi C n2 = carry << l |
shll %cl, %edi C n2 = carry << l |
movl $0, %esi C n10 = 0 |
movl %edi, %eax C return value for zero_done |
|
cmpl $0, PARAM_XSIZE |
|
|
C we're here because xsize+size>=MUL_THRESHOLD, so with size==0 then |
je L(zero_done) |
C must have xsize!=0 |
|
jmp L(fraction_some) |
jmp L(fraction_some) |
|
|
|
|
|
|
|
|
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
movl %ebp, %eax C d |
movl %ebp, %eax C d |
leal 1(%edi), %ebx C n2<<32 + m*(n2+n1)) |
leal 1(%edi), %ebx C n2+1 |
|
|
adcl %edx, %ebx C 1 + high(n2<<32 + m*(n2+n1) + nadj) = q1+1 |
adcl %edx, %ebx C 1 + high(n2<<32 + m*(n2+n1) + nadj) = q1+1 |
jz L(q1_ff) |
jz L(q1_ff) |
Line 407 L(integer_two_left): |
|
Line 489 L(integer_two_left): |
|
C edi n2 |
C edi n2 |
C ebp divisor |
C ebp divisor |
C |
C |
C mm0 src limb, shifted |
|
C mm7 rshift |
C mm7 rshift |
|
|
|
|
Line 434 L(integer_two_left): |
|
Line 515 L(integer_two_left): |
|
C |
C |
|
|
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
leal 1(%edi), %ebx C n2<<32 + m*(n2+n1)) |
leal 1(%edi), %ebx C n2+1 |
movl %ebp, %eax C d |
movl %ebp, %eax C d |
|
|
adcl %edx, %ebx C 1 + high(n2<<32 + m*(n2+n1) + nadj) = q1+1 |
adcl %edx, %ebx C 1 + high(n2<<32 + m*(n2+n1) + nadj) = q1+1 |
Line 475 L(integer_one_left): |
|
Line 556 L(integer_one_left): |
|
C edi n2 |
C edi n2 |
C ebp divisor |
C ebp divisor |
C |
C |
C mm0 src limb, shifted |
|
C mm7 rshift |
C mm7 rshift |
|
|
|
|
Line 500 L(integer_one_left): |
|
Line 580 L(integer_one_left): |
|
C |
C |
|
|
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
addl %ebx, %eax C m*(n2+n1) + nadj, low giving carry flag |
leal 1(%edi), %ebx C n2<<32 + m*(n2+n1)) |
leal 1(%edi), %ebx C n2+1 |
movl %ebp, %eax C d |
movl %ebp, %eax C d |
|
|
C |
C |
Line 541 L(integer_one_left): |
|
Line 621 L(integer_one_left): |
|
movl %edi, %eax |
movl %edi, %eax |
L(fraction_done): |
L(fraction_done): |
movl VAR_NORM, %ecx |
movl VAR_NORM, %ecx |
|
L(zero_done): |
movl SAVE_EBP, %ebp |
movl SAVE_EBP, %ebp |
|
|
movl SAVE_EDI, %edi |
movl SAVE_EDI, %edi |
Line 617 L(fraction_some): |
|
Line 698 L(fraction_some): |
|
C ebp divisor |
C ebp divisor |
|
|
movl PARAM_DST, %esi |
movl PARAM_DST, %esi |
movl VAR_DST_STOP, %ecx |
movl VAR_DST_STOP, %ecx C &dst[xsize+2] |
movl %edi, %eax |
movl %edi, %eax |
|
|
subl $8, %ecx |
subl $8, %ecx C &dst[xsize] |
|
|
|
|
ALIGN(16) |
ALIGN(16) |