2010-09-04 16:26:53 -04:00
|
|
|
dnl AMD64 mpn_sub_err1_n
|
2009-07-23 23:12:09 -04:00
|
|
|
|
|
|
|
dnl Copyright (C) 2009, David Harvey
|
|
|
|
|
|
|
|
dnl All rights reserved.
|
|
|
|
|
|
|
|
dnl Redistribution and use in source and binary forms, with or without
|
|
|
|
dnl modification, are permitted provided that the following conditions are
|
|
|
|
dnl met:
|
|
|
|
|
|
|
|
dnl 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
dnl this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
dnl 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
dnl notice, this list of conditions and the following disclaimer in the
|
|
|
|
dnl documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
dnl HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
dnl TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
include(`../config.m4')
|
|
|
|
|
|
|
|
C cycles/limb
|
|
|
|
C K8,K9: 3.166
|
|
|
|
C K10: ?
|
|
|
|
C P4: ?
|
|
|
|
C P6-15 (Core2): ?
|
|
|
|
C P6-28 (Atom): ?
|
|
|
|
|
|
|
|
C INPUT PARAMETERS
|
|
|
|
define(`rp', `%rdi')
|
|
|
|
define(`up', `%rsi')
|
|
|
|
define(`vp', `%rdx')
|
|
|
|
define(`ep', `%rcx')
|
|
|
|
define(`yp', `%r8')
|
|
|
|
define(`n', `%r9')
|
|
|
|
define(`cy_param', `8(%rsp)')
|
|
|
|
define(`el', `%rbx')
|
|
|
|
define(`eh', `%rbp')
|
|
|
|
define(`t0', `%r10')
|
|
|
|
define(`t1', `%r11')
|
|
|
|
define(`w', `%r12')
|
|
|
|
|
|
|
|
ASM_START()
|
|
|
|
TEXT
|
|
|
|
ALIGN(16)
|
2010-09-04 16:26:53 -04:00
|
|
|
PROLOGUE(mpn_sub_err1_n)
|
2014-02-07 08:05:55 -05:00
|
|
|
mov cy_param, %rax C cy
|
2009-07-23 23:12:09 -04:00
|
|
|
|
|
|
|
push %rbx
|
|
|
|
push %rbp
|
|
|
|
push %r12
|
|
|
|
|
2014-02-07 08:05:55 -05:00
|
|
|
xor el, el C zero el, eh
|
|
|
|
xor eh, eh
|
|
|
|
lea (rp,n,8), rp C rp += n, up += n, vp += n
|
2009-07-23 23:12:09 -04:00
|
|
|
lea (up,n,8), up
|
|
|
|
lea (vp,n,8), vp
|
|
|
|
|
2014-02-07 08:05:55 -05:00
|
|
|
test $1, n C if n is odd goto L(odd)
|
2009-07-23 23:12:09 -04:00
|
|
|
jnz L(odd)
|
|
|
|
|
|
|
|
L(even):
|
2014-02-07 08:05:55 -05:00
|
|
|
lea -8(yp,n,8), yp C yp += n - 1
|
|
|
|
neg n C { n = -n }
|
2009-07-23 23:12:09 -04:00
|
|
|
jmp L(top)
|
|
|
|
|
|
|
|
ALIGN(16)
|
2014-02-07 08:05:55 -05:00
|
|
|
L(odd): C n is odd, do extra iteration
|
|
|
|
lea -16(yp,n,8), yp C yp += n - 2
|
|
|
|
neg n C { n = -n }
|
|
|
|
shr $1, %rax C rp[0] = up[0] - vp[0] - (cy&1)
|
|
|
|
mov (up,n,8), w
|
2010-09-04 16:26:53 -04:00
|
|
|
sbb (vp,n,8), w
|
2014-02-07 08:05:55 -05:00
|
|
|
cmovc 8(yp), el C if borrow el = *yp
|
2009-07-23 23:12:09 -04:00
|
|
|
mov w, (rp,n,8)
|
2014-02-07 08:05:55 -05:00
|
|
|
setc %al C store borrow
|
|
|
|
inc n C n++
|
|
|
|
jz L(end) C goto end if we are done
|
2009-07-23 23:12:09 -04:00
|
|
|
|
|
|
|
ALIGN(16)
|
|
|
|
L(top):
|
2014-02-07 08:05:55 -05:00
|
|
|
mov (up,n,8), w C rp[n] = up[n] - vp[n] - borrow
|
|
|
|
shr $1, %rax C restore borrow
|
|
|
|
sbb (vp,n,8), w
|
|
|
|
mov $0, t1 C initialise t1
|
2009-07-23 23:12:09 -04:00
|
|
|
mov w, (rp,n,8)
|
2014-02-07 08:05:55 -05:00
|
|
|
mov $0, t0 C initialise t0
|
|
|
|
mov 8(up,n,8), w C rp[n+1] = up[n+1] - vp[n+1] - borrow
|
|
|
|
cmovc (yp), t0 C if borrow t0 = yp
|
|
|
|
sbb 8(vp,n,8), w
|
|
|
|
cmovc -8(yp), t1 C if next borrow t1 = *(yp-1)
|
2009-07-23 23:12:09 -04:00
|
|
|
setc %al C save carry
|
2014-02-07 08:05:55 -05:00
|
|
|
add t0, el C (eh:el) += borrow*yp limb
|
2009-07-23 23:12:09 -04:00
|
|
|
adc $0, eh
|
2014-02-07 08:05:55 -05:00
|
|
|
add t1, el C (eh:el) += next borrow*next yp limb
|
2009-07-23 23:12:09 -04:00
|
|
|
mov w, 8(rp,n,8)
|
|
|
|
adc $0, eh
|
|
|
|
add $2, n
|
2014-02-07 08:05:55 -05:00
|
|
|
lea -16(yp), yp C yp -= 2
|
|
|
|
jnz L(top) C if not done goto top
|
2009-07-23 23:12:09 -04:00
|
|
|
|
|
|
|
L(end):
|
2014-02-07 08:05:55 -05:00
|
|
|
mov el, (ep) C write out (eh:el)
|
2009-07-23 23:12:09 -04:00
|
|
|
mov eh, 8(ep)
|
|
|
|
|
|
|
|
pop %r12
|
|
|
|
pop %rbp
|
|
|
|
pop %rbx
|
|
|
|
ret
|
|
|
|
EPILOGUE()
|