|
Packit |
5c3484 |
dnl AMD64 mpn_modexact_1_odd -- Hensel norm remainder.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl Copyright 2000-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
|
|
Packit |
5c3484 |
C Intel corei 14.5
|
|
Packit |
5c3484 |
C Intel atom 35
|
|
Packit |
5c3484 |
C VIA nano ?
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C The dependent chain in the main loop is
|
|
Packit |
5c3484 |
C
|
|
Packit |
5c3484 |
C cycles
|
|
Packit |
5c3484 |
C sub %rdx, %rax 1
|
|
Packit |
5c3484 |
C imul %r9, %rax 4
|
|
Packit |
5c3484 |
C mul %r8 5
|
|
Packit |
5c3484 |
C ----
|
|
Packit |
5c3484 |
C total 10
|
|
Packit |
5c3484 |
C
|
|
Packit |
5c3484 |
C The mov load from src seems to need to be scheduled back before the jz to
|
|
Packit |
5c3484 |
C achieve this speed, out-of-order execution apparently can't completely hide
|
|
Packit |
5c3484 |
C the latency otherwise.
|
|
Packit |
5c3484 |
C
|
|
Packit |
5c3484 |
C The l=src[i]-cbit step is rotated back too, since that allows us to avoid it
|
|
Packit |
5c3484 |
C for the first iteration (where there's no cbit).
|
|
Packit |
5c3484 |
C
|
|
Packit |
5c3484 |
C The code alignment used (32-byte) for the loop also seems necessary. Without
|
|
Packit |
5c3484 |
C that the non-PIC case has adc crossing the 0x60 offset, apparently making it
|
|
Packit |
5c3484 |
C run at 11 cycles instead of 10.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ABI_SUPPORT(DOS64)
|
|
Packit |
5c3484 |
ABI_SUPPORT(STD64)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ASM_START()
|
|
Packit |
5c3484 |
TEXT
|
|
Packit |
5c3484 |
ALIGN(32)
|
|
Packit |
5c3484 |
PROLOGUE(mpn_modexact_1_odd)
|
|
Packit |
5c3484 |
FUNC_ENTRY(3)
|
|
Packit |
5c3484 |
mov $0, R32(%rcx)
|
|
Packit |
5c3484 |
IFDOS(` jmp L(ent) ')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
PROLOGUE(mpn_modexact_1c_odd)
|
|
Packit |
5c3484 |
FUNC_ENTRY(4)
|
|
Packit |
5c3484 |
L(ent):
|
|
Packit |
5c3484 |
C rdi src
|
|
Packit |
5c3484 |
C rsi size
|
|
Packit |
5c3484 |
C rdx divisor
|
|
Packit |
5c3484 |
C rcx carry
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov %rdx, %r8 C d
|
|
Packit |
5c3484 |
shr R32(%rdx) C d/2
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
LEA( binvert_limb_table, %r9)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
and $127, R32(%rdx)
|
|
Packit |
5c3484 |
mov %rcx, %r10 C initial carry
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
movzbl (%r9,%rdx), R32(%rdx) C inv 8 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov (%rdi), %rax C src[0]
|
|
Packit |
5c3484 |
lea (%rdi,%rsi,8), %r11 C src end
|
|
Packit |
5c3484 |
mov %r8, %rdi C d, made available to imull
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rdx,%rdx), R32(%rcx) C 2*inv
|
|
Packit |
5c3484 |
imul R32(%rdx), R32(%rdx) C inv*inv
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
neg %rsi C -size
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
imul R32(%rdi), R32(%rdx) C inv*inv*d
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
sub R32(%rdx), R32(%rcx) C inv = 2*inv - inv*inv*d, 16 bits
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rcx,%rcx), R32(%rdx) C 2*inv
|
|
Packit |
5c3484 |
imul R32(%rcx), R32(%rcx) C inv*inv
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
imul R32(%rdi), R32(%rcx) C inv*inv*d
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
sub R32(%rcx), R32(%rdx) C inv = 2*inv - inv*inv*d, 32 bits
|
|
Packit |
5c3484 |
xor R32(%rcx), R32(%rcx) C initial cbit
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rdx,%rdx), %r9 C 2*inv
|
|
Packit |
5c3484 |
imul %rdx, %rdx C inv*inv
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
imul %r8, %rdx C inv*inv*d
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
sub %rdx, %r9 C inv = 2*inv - inv*inv*d, 64 bits
|
|
Packit |
5c3484 |
mov %r10, %rdx C initial climb
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ASSERT(e,` C d*inv == 1 mod 2^64
|
|
Packit |
5c3484 |
mov %r8, %r10
|
|
Packit |
5c3484 |
imul %r9, %r10
|
|
Packit |
5c3484 |
cmp $1, %r10')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
inc %rsi
|
|
Packit |
5c3484 |
jz L(one)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(16)
|
|
Packit |
5c3484 |
L(top):
|
|
Packit |
5c3484 |
C rax l = src[i]-cbit
|
|
Packit |
5c3484 |
C rcx new cbit, 0 or 1
|
|
Packit |
5c3484 |
C rdx climb, high of last product
|
|
Packit |
5c3484 |
C rsi counter, limbs, negative
|
|
Packit |
5c3484 |
C rdi
|
|
Packit |
5c3484 |
C r8 divisor
|
|
Packit |
5c3484 |
C r9 inverse
|
|
Packit |
5c3484 |
C r11 src end ptr
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
sub %rdx, %rax C l = src[i]-cbit - climb
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
adc $0, %rcx C more cbit
|
|
Packit |
5c3484 |
imul %r9, %rax C q = l * inverse
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mul %r8 C climb = high (q * d)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov (%r11,%rsi,8), %rax C src[i+1]
|
|
Packit |
5c3484 |
sub %rcx, %rax C next l = src[i+1] - cbit
|
|
Packit |
5c3484 |
setc R8(%rcx) C new cbit
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
inc %rsi
|
|
Packit |
5c3484 |
jnz L(top)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
L(one):
|
|
Packit |
5c3484 |
sub %rdx, %rax C l = src[i]-cbit - climb
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
adc $0, %rcx C more cbit
|
|
Packit |
5c3484 |
imul %r9, %rax C q = l * inverse
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mul %r8 C climb = high (q * d)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rcx,%rdx), %rax C climb+cbit
|
|
Packit |
5c3484 |
FUNC_EXIT()
|
|
Packit |
5c3484 |
ret
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
EPILOGUE(mpn_modexact_1c_odd)
|
|
Packit |
5c3484 |
EPILOGUE(mpn_modexact_1_odd)
|