|
Packit |
5c3484 |
dnl AMD64 mpn_divexact_1 -- mpn by limb exact division.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl Copyright 2001, 2002, 2004-2006, 2011, 2012 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 AMD K8,K9 10
|
|
Packit |
5c3484 |
C AMD K10 10
|
|
Packit |
5c3484 |
C Intel P4 33
|
|
Packit |
5c3484 |
C Intel core2 13.25
|
|
Packit |
5c3484 |
C Intel corei 14
|
|
Packit |
5c3484 |
C Intel atom 42
|
|
Packit |
5c3484 |
C VIA nano 43
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C A quick adoption of the 32-bit K7 code.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C INPUT PARAMETERS
|
|
Packit |
5c3484 |
C rp rdi
|
|
Packit |
5c3484 |
C up rsi
|
|
Packit |
5c3484 |
C n rdx
|
|
Packit |
5c3484 |
C divisor rcx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ABI_SUPPORT(DOS64)
|
|
Packit |
5c3484 |
ABI_SUPPORT(STD64)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ASM_START()
|
|
Packit |
5c3484 |
TEXT
|
|
Packit |
5c3484 |
ALIGN(16)
|
|
Packit |
5c3484 |
PROLOGUE(mpn_divexact_1)
|
|
Packit |
5c3484 |
FUNC_ENTRY(4)
|
|
Packit |
5c3484 |
push %rbx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov %rcx, %rax
|
|
Packit |
5c3484 |
xor R32(%rcx), R32(%rcx) C shift count
|
|
Packit |
5c3484 |
mov %rdx, %r8
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
bt $0, R32(%rax)
|
|
Packit |
5c3484 |
jnc L(evn) C skip bsfq unless divisor is even
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(odd): mov %rax, %rbx
|
|
Packit |
5c3484 |
shr R32(%rax)
|
|
Packit |
5c3484 |
and $127, R32(%rax) C d/2, 7 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
LEA( binvert_limb_table, %rdx)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movzbl (%rdx,%rax), R32(%rax) C inv 8 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov %rbx, %r11 C d without twos
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rax,%rax), R32(%rdx) C 2*inv
|
|
Packit |
5c3484 |
imul R32(%rax), R32(%rax) C inv*inv
|
|
Packit |
5c3484 |
imul R32(%rbx), R32(%rax) C inv*inv*d
|
|
Packit |
5c3484 |
sub R32(%rax), R32(%rdx) C inv = 2*inv - inv*inv*d, 16 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rdx,%rdx), R32(%rax) C 2*inv
|
|
Packit |
5c3484 |
imul R32(%rdx), R32(%rdx) C inv*inv
|
|
Packit |
5c3484 |
imul R32(%rbx), R32(%rdx) C inv*inv*d
|
|
Packit |
5c3484 |
sub R32(%rdx), R32(%rax) C inv = 2*inv - inv*inv*d, 32 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rax,%rax), %r10 C 2*inv
|
|
Packit |
5c3484 |
imul %rax, %rax C inv*inv
|
|
Packit |
5c3484 |
imul %rbx, %rax C inv*inv*d
|
|
Packit |
5c3484 |
sub %rax, %r10 C inv = 2*inv - inv*inv*d, 64 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rsi,%r8,8), %rsi C up end
|
|
Packit |
5c3484 |
lea -8(%rdi,%r8,8), %rdi C rp end
|
|
Packit |
5c3484 |
neg %r8 C -n
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov (%rsi,%r8,8), %rax C up[0]
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
inc %r8
|
|
Packit |
5c3484 |
jz L(one)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov (%rsi,%r8,8), %rdx C up[1]
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
shrd R8(%rcx), %rdx, %rax
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
xor R32(%rbx), R32(%rbx)
|
|
Packit |
5c3484 |
jmp L(ent)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(evn): bsf %rax, %rcx
|
|
Packit |
5c3484 |
shr R8(%rcx), %rax
|
|
Packit |
5c3484 |
jmp L(odd)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(8)
|
|
Packit |
5c3484 |
L(top):
|
|
Packit |
5c3484 |
C rax q
|
|
Packit |
5c3484 |
C rbx carry bit, 0 or 1
|
|
Packit |
5c3484 |
C rcx shift
|
|
Packit |
5c3484 |
C rdx
|
|
Packit |
5c3484 |
C rsi up end
|
|
Packit |
5c3484 |
C rdi rp end
|
|
Packit |
5c3484 |
C r8 counter, limbs, negative
|
|
Packit |
5c3484 |
C r10 d^(-1) mod 2^64
|
|
Packit |
5c3484 |
C r11 d, shifted down
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mul %r11 C carry limb in rdx 0 10
|
|
Packit |
5c3484 |
mov -8(%rsi,%r8,8), %rax C
|
|
Packit |
5c3484 |
mov (%rsi,%r8,8), %r9 C
|
|
Packit |
5c3484 |
shrd R8(%rcx), %r9, %rax C
|
|
Packit |
5c3484 |
nop C
|
|
Packit |
5c3484 |
sub %rbx, %rax C apply carry bit
|
|
Packit |
5c3484 |
setc %bl C
|
|
Packit |
5c3484 |
sub %rdx, %rax C apply carry limb 5
|
|
Packit |
5c3484 |
adc $0, %rbx C 6
|
|
Packit |
5c3484 |
L(ent): imul %r10, %rax C 6
|
|
Packit |
5c3484 |
mov %rax, (%rdi,%r8,8) C
|
|
Packit |
5c3484 |
inc %r8 C
|
|
Packit |
5c3484 |
jnz L(top)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mul %r11 C carry limb in rdx
|
|
Packit |
5c3484 |
mov -8(%rsi), %rax C up high limb
|
|
Packit |
5c3484 |
shr R8(%rcx), %rax
|
|
Packit |
5c3484 |
sub %rbx, %rax C apply carry bit
|
|
Packit |
5c3484 |
sub %rdx, %rax C apply carry limb
|
|
Packit |
5c3484 |
imul %r10, %rax
|
|
Packit |
5c3484 |
mov %rax, (%rdi)
|
|
Packit |
5c3484 |
pop %rbx
|
|
Packit |
5c3484 |
FUNC_EXIT()
|
|
Packit |
5c3484 |
ret
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(one): shr R8(%rcx), %rax
|
|
Packit |
5c3484 |
imul %r10, %rax
|
|
Packit |
5c3484 |
mov %rax, (%rdi)
|
|
Packit |
5c3484 |
pop %rbx
|
|
Packit |
5c3484 |
FUNC_EXIT()
|
|
Packit |
5c3484 |
ret
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
EPILOGUE()
|