2016-11-26 17:35:25 -05:00
|
|
|
|
2016-11-27 09:06:56 -05:00
|
|
|
; AMD64 mpn_add_n
|
2016-12-13 09:10:48 -05:00
|
|
|
; Copyright 2008, 2016 Jason Moxham and Alexander Kruppa
|
2016-11-26 17:35:25 -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.
|
|
|
|
|
2016-11-27 09:06:56 -05:00
|
|
|
; (rdi,rcx) = (rsi,rcx)+(rdx,rcx)
|
|
|
|
; rax = carry
|
2016-11-26 17:35:25 -05:00
|
|
|
|
2016-11-27 09:06:56 -05:00
|
|
|
%define USE_WIN64
|
|
|
|
|
|
|
|
%include 'yasm_mac.inc'
|
|
|
|
|
|
|
|
%ifdef USE_WIN64
|
|
|
|
%define SumP rcx
|
|
|
|
%define Inp1P rdx
|
|
|
|
%define Inp2P r8
|
|
|
|
%define Size r9
|
2016-12-13 09:10:48 -05:00
|
|
|
%define LIMB1 rax
|
|
|
|
%define LIMB2 r10
|
|
|
|
%define SizeRest r11
|
2016-11-27 09:06:56 -05:00
|
|
|
%else
|
|
|
|
%define SumP rdi
|
|
|
|
%define Inp1P rsi
|
|
|
|
%define Inp2P rdx
|
|
|
|
%define Size rcx
|
2016-12-13 09:10:48 -05:00
|
|
|
%define LIMB1 rax
|
|
|
|
%define LIMB2 r9
|
|
|
|
%define SizeRest r10
|
2016-11-27 09:06:56 -05:00
|
|
|
%endif
|
|
|
|
|
2016-12-13 09:10:48 -05:00
|
|
|
%define ADCSBB adc
|
|
|
|
|
2016-11-27 09:06:56 -05:00
|
|
|
BITS 64
|
2016-11-26 17:35:25 -05:00
|
|
|
|
|
|
|
xalign 8
|
|
|
|
LEAF_PROC mpn_add_nc
|
|
|
|
mov r10,[rsp+40]
|
|
|
|
jmp entry
|
|
|
|
|
|
|
|
xalign 8
|
|
|
|
LEAF_PROC mpn_add_n
|
|
|
|
xor r10, r10
|
|
|
|
entry:
|
2016-12-13 09:10:48 -05:00
|
|
|
mov SizeRest, Size
|
|
|
|
and SizeRest, 7
|
|
|
|
shr Size, 3
|
2016-11-27 09:06:56 -05:00
|
|
|
lea Size, [r10 + 2*Size]
|
|
|
|
sar Size, 1
|
2016-12-13 09:10:48 -05:00
|
|
|
jnz .loop1
|
|
|
|
jmp .rest
|
|
|
|
|
|
|
|
align 16
|
|
|
|
.loop1:
|
2016-11-27 09:06:56 -05:00
|
|
|
mov LIMB1, [Inp1P]
|
2016-12-13 09:10:48 -05:00
|
|
|
mov LIMB2, [Inp1P+8]
|
|
|
|
ADCSBB LIMB1, [Inp2P]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov [SumP], LIMB1
|
2016-12-13 09:10:48 -05:00
|
|
|
ADCSBB LIMB2, [Inp2P+8]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov LIMB1, [Inp1P+16]
|
2016-12-13 09:10:48 -05:00
|
|
|
mov [SumP+8], LIMB2
|
|
|
|
ADCSBB LIMB1, [Inp2P+16]
|
|
|
|
mov LIMB2, [Inp1P+24]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov [SumP+16], LIMB1
|
2016-12-13 09:10:48 -05:00
|
|
|
mov LIMB1, [Inp1P+32]
|
|
|
|
ADCSBB LIMB2, [Inp2P+24]
|
|
|
|
mov [SumP+24], LIMB2
|
|
|
|
ADCSBB LIMB1, [Inp2P+32]
|
|
|
|
mov [SumP+32], LIMB1
|
|
|
|
mov LIMB2, [Inp1P+40]
|
|
|
|
ADCSBB LIMB2, [Inp2P+40]
|
|
|
|
mov [SumP+40], LIMB2
|
|
|
|
mov LIMB1, [Inp1P+48]
|
|
|
|
mov LIMB2, [Inp1P+56]
|
|
|
|
lea Inp1P, [Inp1P+64]
|
|
|
|
ADCSBB LIMB1, [Inp2P+48]
|
|
|
|
ADCSBB LIMB2, [Inp2P+56]
|
|
|
|
lea Inp2P, [Inp2P+64]
|
|
|
|
mov [SumP+48], LIMB1
|
|
|
|
mov [SumP+56], LIMB2
|
|
|
|
lea SumP, [SumP+64]
|
2016-11-27 09:06:56 -05:00
|
|
|
dec Size
|
2016-12-13 09:10:48 -05:00
|
|
|
jnz .loop1
|
|
|
|
inc SizeRest
|
|
|
|
dec SizeRest
|
|
|
|
jz .end
|
|
|
|
.rest:
|
2016-11-27 09:06:56 -05:00
|
|
|
mov LIMB1, [Inp1P]
|
2016-12-13 09:10:48 -05:00
|
|
|
ADCSBB LIMB1, [Inp2P]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov [SumP], LIMB1
|
2016-12-13 09:10:48 -05:00
|
|
|
dec SizeRest
|
|
|
|
jz .end
|
2016-11-27 09:06:56 -05:00
|
|
|
mov LIMB1, [Inp1P+8]
|
2016-12-13 09:10:48 -05:00
|
|
|
ADCSBB LIMB1, [Inp2P+8]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov [SumP+8], LIMB1
|
2016-12-13 09:10:48 -05:00
|
|
|
dec SizeRest
|
|
|
|
jz .end
|
2016-11-27 09:06:56 -05:00
|
|
|
mov LIMB1, [Inp1P+16]
|
2016-12-13 09:10:48 -05:00
|
|
|
ADCSBB LIMB1, [Inp2P+16]
|
2016-11-27 09:06:56 -05:00
|
|
|
mov [SumP+16], LIMB1
|
2016-12-13 09:10:48 -05:00
|
|
|
dec SizeRest
|
|
|
|
jz .end
|
|
|
|
mov LIMB1, [Inp1P+24]
|
|
|
|
ADCSBB LIMB1, [Inp2P+24]
|
|
|
|
mov [SumP+24], LIMB1
|
|
|
|
dec SizeRest
|
|
|
|
jz .end
|
|
|
|
lea Inp1P, [Inp1P+32]
|
|
|
|
lea Inp2P, [Inp2P+32]
|
|
|
|
lea SumP, [SumP+32]
|
|
|
|
jmp .rest
|
|
|
|
.end:
|
|
|
|
mov eax, 0
|
|
|
|
adc eax, eax
|
2016-11-27 09:06:56 -05:00
|
|
|
ret
|