2009-02-19 18:22:30 -05:00
|
|
|
|
|
|
|
; AMD64 mpn_add_n/mpn_sub_n -- mpn add or subtract
|
|
|
|
; Version 1.0.3.
|
|
|
|
;
|
|
|
|
; Copyright 2008 Jason Moxham
|
2009-02-22 16:03:08 -05:00
|
|
|
;
|
|
|
|
; Windows Conversion Copyright 2008 Brian Gladman
|
|
|
|
;
|
2009-02-19 18:22:30 -05:00
|
|
|
; This file is part of the MPIR Library.
|
|
|
|
; The MPIR Library is free software; you can redistribute it and/or modify
|
|
|
|
; it under the terms of the GNU Lesser General Public License as published
|
|
|
|
; by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
; your option) any later version.
|
|
|
|
; The MPIR Library is distributed in the hope that it will be useful, but
|
|
|
|
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
; License for more details.
|
|
|
|
; You should have received a copy of the GNU Lesser General Public License
|
|
|
|
; along with the MPIR Library; see the file COPYING.LIB. If not, write
|
|
|
|
; to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
; Boston, MA 02110-1301, USA.
|
2009-02-22 16:03:08 -05:00
|
|
|
;
|
2009-02-19 18:22:30 -05:00
|
|
|
; Calling interface:
|
|
|
|
;
|
|
|
|
; mp_limb_t __gmpn_<op>_n( <op> = add OR sub
|
|
|
|
; mp_ptr dst, rcx
|
|
|
|
; mp_srcptr src1, rdx
|
|
|
|
; mp_srcptr src2, r8
|
|
|
|
; mp_size_t len r9
|
|
|
|
; )
|
|
|
|
;
|
|
|
|
; mp_limb_t __gmpn_<op>_nc( <op> = add OR sub
|
|
|
|
; mp_ptr dst, rcx
|
|
|
|
; mp_srcptr src1, rdx
|
|
|
|
; mp_srcptr src2, r8
|
|
|
|
; mp_size_t len, r9
|
|
|
|
; mp_limb_t carry [rsp+0x28]
|
|
|
|
; )
|
|
|
|
;
|
|
|
|
; Calculate src1[size] plus(minus) src2[size] and store the result in
|
|
|
|
; dst[size]. The return value is the carry bit from the top of the result
|
|
|
|
; (1 or 0). The _nc version accepts 1 or 0 for an initial carry into the
|
|
|
|
; low limb of the calculation. Note values other than 1 or 0 here will
|
|
|
|
; lead to garbage results.
|
|
|
|
;
|
|
|
|
; This is an SEH leaf function (no unwind support needed)
|
|
|
|
|
2009-03-07 10:00:35 -05:00
|
|
|
%include "..\yasm_mac.inc"
|
2009-02-19 18:22:30 -05:00
|
|
|
|
2009-03-07 10:00:35 -05:00
|
|
|
BITS 64
|
|
|
|
|
2009-03-02 15:03:30 -05:00
|
|
|
alignb 8, nop
|
2009-03-07 10:00:35 -05:00
|
|
|
LEAF_PROC mpn_sub_nc
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10,[rsp+0x28]
|
2009-03-07 10:00:35 -05:00
|
|
|
jmp entry
|
2009-03-02 15:03:30 -05:00
|
|
|
|
|
|
|
alignb 8, nop
|
2009-03-07 10:00:35 -05:00
|
|
|
LEAF_PROC mpn_sub_n
|
2009-02-19 18:22:30 -05:00
|
|
|
xor r10, r10
|
2009-03-07 10:00:35 -05:00
|
|
|
entry:
|
|
|
|
mov eax, r9d
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r9, rax
|
|
|
|
and rax, 3
|
|
|
|
shr r9, 2
|
|
|
|
lea r9,[r10+r9*2]
|
|
|
|
shr r9, 1
|
2009-03-07 10:00:35 -05:00
|
|
|
jnz .2
|
2009-02-19 18:22:30 -05:00
|
|
|
|
|
|
|
mov r10, [rdx]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
jz .1
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10, [rdx+8]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8+8]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx+8], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
jz .1
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10, [rdx+16]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8+16]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx+16], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
.1: adc rax, rax
|
2009-02-19 18:22:30 -05:00
|
|
|
ret
|
|
|
|
|
2009-02-26 06:11:27 -05:00
|
|
|
alignb 8, nop
|
2009-03-07 10:00:35 -05:00
|
|
|
.2: mov r10, [rdx]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r11, [rdx+8]
|
|
|
|
lea rdx, [rdx+32]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8]
|
|
|
|
sbb r11, [r8+8]
|
2009-02-19 18:22:30 -05:00
|
|
|
lea r8, [r8+32]
|
|
|
|
mov [rcx], r10
|
|
|
|
mov [rcx+8], r11
|
|
|
|
lea rcx, [rcx+32]
|
|
|
|
mov r10, [rdx-16]
|
|
|
|
mov r11, [rdx-8]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8-16]
|
|
|
|
sbb r11, [r8-8]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx-16], r10
|
|
|
|
dec r9
|
|
|
|
mov [rcx-8], r11
|
2009-03-07 10:00:35 -05:00
|
|
|
jnz .2
|
2009-02-19 18:22:30 -05:00
|
|
|
|
|
|
|
inc rax
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
jz .3
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10, [rdx]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
jz .3
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10, [rdx+8]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8+8]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx+8], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
jz .3
|
2009-02-19 18:22:30 -05:00
|
|
|
mov r10, [rdx+16]
|
2009-03-07 10:00:35 -05:00
|
|
|
sbb r10, [r8+16]
|
2009-02-19 18:22:30 -05:00
|
|
|
mov [rcx+16], r10
|
|
|
|
dec rax
|
2009-03-07 10:00:35 -05:00
|
|
|
.3: adc rax, rax
|
2009-02-19 18:22:30 -05:00
|
|
|
ret
|
|
|
|
|
|
|
|
end
|