|
Packit |
5c3484 |
dnl x86 mpn_bdiv_q_1 -- mpn by limb exact division.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl Rearranged from mpn/x86/dive_1.asm by Marco Bodrato.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl Copyright 2001, 2002, 2007, 2011 Free Software Foundation, Inc.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl This file is part of the GNU MP Library.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify
|
|
Packit |
5c3484 |
dnl it under the terms of either:
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl * the GNU Lesser General Public License as published by the Free
|
|
Packit |
5c3484 |
dnl Software Foundation; either version 3 of the License, or (at your
|
|
Packit |
5c3484 |
dnl option) any later version.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl or
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl * the GNU General Public License as published by the Free Software
|
|
Packit |
5c3484 |
dnl Foundation; either version 2 of the License, or (at your option) any
|
|
Packit |
5c3484 |
dnl later version.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl or both in parallel, as here.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but
|
|
Packit |
5c3484 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
5c3484 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit |
5c3484 |
dnl for more details.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl You should have received copies of the GNU General Public License and the
|
|
Packit |
5c3484 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
|
|
Packit |
5c3484 |
dnl see https://www.gnu.org/licenses/.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
include(`../config.m4')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C cycles/limb
|
|
Packit |
5c3484 |
C P54 30.0
|
|
Packit |
5c3484 |
C P55 29.0
|
|
Packit |
5c3484 |
C P6 13.0 odd divisor, 12.0 even (strangely)
|
|
Packit |
5c3484 |
C K6 14.0
|
|
Packit |
5c3484 |
C K7 12.0
|
|
Packit |
5c3484 |
C P4 42.0
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
MULFUNC_PROLOGUE(mpn_bdiv_q_1 mpn_pi1_bdiv_q_1)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
defframe(PARAM_SHIFT, 24)
|
|
Packit |
5c3484 |
defframe(PARAM_INVERSE,20)
|
|
Packit |
5c3484 |
defframe(PARAM_DIVISOR,16)
|
|
Packit |
5c3484 |
defframe(PARAM_SIZE, 12)
|
|
Packit |
5c3484 |
defframe(PARAM_SRC, 8)
|
|
Packit |
5c3484 |
defframe(PARAM_DST, 4)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl re-use parameter space
|
|
Packit |
5c3484 |
define(VAR_INVERSE,`PARAM_SRC')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
TEXT
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C mp_limb_t
|
|
Packit |
5c3484 |
C mpn_pi1_bdiv_q_1 (mp_ptr dst, mp_srcptr src, mp_size_t size, mp_limb_t divisor,
|
|
Packit |
5c3484 |
C mp_limb_t inverse, int shift)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(16)
|
|
Packit |
5c3484 |
PROLOGUE(mpn_pi1_bdiv_q_1)
|
|
Packit |
5c3484 |
deflit(`FRAME',0)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl PARAM_SHIFT, %ecx
|
|
Packit |
5c3484 |
pushl %ebp FRAME_pushl()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl PARAM_INVERSE, %eax
|
|
Packit |
5c3484 |
movl PARAM_SIZE, %ebp
|
|
Packit |
5c3484 |
pushl %ebx FRAME_pushl()
|
|
Packit |
5c3484 |
L(common):
|
|
Packit |
5c3484 |
pushl %edi FRAME_pushl()
|
|
Packit |
5c3484 |
pushl %esi FRAME_pushl()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl PARAM_SRC, %esi
|
|
Packit |
5c3484 |
movl PARAM_DST, %edi
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
leal (%esi,%ebp,4), %esi C src end
|
|
Packit |
5c3484 |
leal (%edi,%ebp,4), %edi C dst end
|
|
Packit |
5c3484 |
negl %ebp C -size
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl %eax, VAR_INVERSE
|
|
Packit |
5c3484 |
movl (%esi,%ebp,4), %eax C src[0]
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
xorl %ebx, %ebx
|
|
Packit |
5c3484 |
xorl %edx, %edx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
incl %ebp
|
|
Packit |
5c3484 |
jz L(one)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl (%esi,%ebp,4), %edx C src[1]
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
shrdl( %cl, %edx, %eax)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl VAR_INVERSE, %edx
|
|
Packit |
5c3484 |
jmp L(entry)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(8)
|
|
Packit |
5c3484 |
nop C k6 code alignment
|
|
Packit |
5c3484 |
nop
|
|
Packit |
5c3484 |
L(top):
|
|
Packit |
5c3484 |
C eax q
|
|
Packit |
5c3484 |
C ebx carry bit, 0 or -1
|
|
Packit |
5c3484 |
C ecx shift
|
|
Packit |
5c3484 |
C edx carry limb
|
|
Packit |
5c3484 |
C esi src end
|
|
Packit |
5c3484 |
C edi dst end
|
|
Packit |
5c3484 |
C ebp counter, limbs, negative
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl -4(%esi,%ebp,4), %eax
|
|
Packit |
5c3484 |
subl %ebx, %edx C accumulate carry bit
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl (%esi,%ebp,4), %ebx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
shrdl( %cl, %ebx, %eax)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
subl %edx, %eax C apply carry limb
|
|
Packit |
5c3484 |
movl VAR_INVERSE, %edx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
sbbl %ebx, %ebx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(entry):
|
|
Packit |
5c3484 |
imull %edx, %eax
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl %eax, -4(%edi,%ebp,4)
|
|
Packit |
5c3484 |
movl PARAM_DIVISOR, %edx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mull %edx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
incl %ebp
|
|
Packit |
5c3484 |
jnz L(top)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl -4(%esi), %eax C src high limb
|
|
Packit |
5c3484 |
L(one):
|
|
Packit |
5c3484 |
shrl %cl, %eax
|
|
Packit |
5c3484 |
popl %esi FRAME_popl()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
addl %ebx, %eax C apply carry bit
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
subl %edx, %eax C apply carry limb
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
imull VAR_INVERSE, %eax
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl %eax, -4(%edi)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
popl %edi
|
|
Packit |
5c3484 |
popl %ebx
|
|
Packit |
5c3484 |
popl %ebp
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ret
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
EPILOGUE()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C mp_limb_t mpn_bdiv_q_1 (mp_ptr dst, mp_srcptr src, mp_size_t size,
|
|
Packit |
5c3484 |
C mp_limb_t divisor);
|
|
Packit |
5c3484 |
C
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(16)
|
|
Packit |
5c3484 |
PROLOGUE(mpn_bdiv_q_1)
|
|
Packit |
5c3484 |
deflit(`FRAME',0)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl PARAM_DIVISOR, %eax
|
|
Packit |
5c3484 |
pushl %ebp FRAME_pushl()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movl $-1, %ecx C shift count
|
|
Packit |
5c3484 |
movl PARAM_SIZE, %ebp
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
pushl %ebx FRAME_pushl()
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(strip_twos):
|
|
Packit |
5c3484 |
incl %ecx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
shrl %eax
|
|
Packit |
5c3484 |
jnc L(strip_twos)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
leal 1(%eax,%eax), %ebx C d without twos
|
|
Packit |
5c3484 |
andl $127, %eax C d/2, 7 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ifdef(`PIC',`
|
|
Packit |
5c3484 |
LEA( binvert_limb_table, %edx)
|
|
Packit |
5c3484 |
movzbl (%eax,%edx), %eax C inv 8 bits
|
|
Packit |
5c3484 |
',`
|
|
Packit |
5c3484 |
movzbl binvert_limb_table(%eax), %eax C inv 8 bits
|
|
Packit |
5c3484 |
')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
leal (%eax,%eax), %edx C 2*inv
|
|
Packit |
5c3484 |
movl %ebx, PARAM_DIVISOR C d without twos
|
|
Packit |
5c3484 |
imull %eax, %eax C inv*inv
|
|
Packit |
5c3484 |
imull %ebx, %eax C inv*inv*d
|
|
Packit |
5c3484 |
subl %eax, %edx C inv = 2*inv - inv*inv*d
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
leal (%edx,%edx), %eax C 2*inv
|
|
Packit |
5c3484 |
imull %edx, %edx C inv*inv
|
|
Packit |
5c3484 |
imull %ebx, %edx C inv*inv*d
|
|
Packit |
5c3484 |
subl %edx, %eax C inv = 2*inv - inv*inv*d
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ASSERT(e,` C expect d*inv == 1 mod 2^GMP_LIMB_BITS
|
|
Packit |
5c3484 |
pushl %eax FRAME_pushl()
|
|
Packit |
5c3484 |
imull PARAM_DIVISOR, %eax
|
|
Packit |
5c3484 |
cmpl $1, %eax
|
|
Packit |
5c3484 |
popl %eax FRAME_popl()')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
jmp L(common)
|
|
Packit |
5c3484 |
EPILOGUE()
|
|
Packit |
5c3484 |
ASM_END()
|