2009-05-20 16:09:06 -04:00
|
|
|
|
2009-09-02 07:41:43 -04:00
|
|
|
; Copyright 2008 Jason Moxham
|
|
|
|
;
|
|
|
|
; Windows Conversion Copyright 2008 Brian Gladman
|
|
|
|
;
|
2009-05-20 16:09:06 -04:00
|
|
|
; This file is part of the MPIR Library.
|
2009-09-02 07:41:43 -04:00
|
|
|
;
|
2009-05-20 16:09:06 -04:00
|
|
|
; 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-09-02 07:41:43 -04:00
|
|
|
; mp_limb_t mpn_divrem_euclidean_qr_2(mp_ptr, mp_ptr, mp_size_t, mp_limb_t)
|
|
|
|
; rax rdi rsi rdx rcx
|
2010-07-02 07:52:24 -04:00
|
|
|
; rax rcx rdx r8 r9
|
2009-05-20 16:09:06 -04:00
|
|
|
|
|
|
|
%include "yasm_mac.inc"
|
|
|
|
|
2009-05-27 12:10:04 -04:00
|
|
|
%define reg_save_list rbx, rsi, rdi, rbp, r12, r13, r14, r15
|
2009-05-20 16:09:06 -04:00
|
|
|
|
|
|
|
BITS 64
|
|
|
|
|
|
|
|
FRAME_PROC mpn_divrem_euclidean_qr_2, 0, reg_save_list
|
|
|
|
mov rdi, rcx
|
|
|
|
mov rsi, rdx
|
2010-07-02 07:52:24 -04:00
|
|
|
mov rdx, r8
|
2009-05-20 16:09:06 -04:00
|
|
|
mov rcx, r9
|
2009-05-27 12:10:04 -04:00
|
|
|
|
2009-05-20 16:09:06 -04:00
|
|
|
mov rbx, rdx
|
2009-05-27 12:10:04 -04:00
|
|
|
dec rbx
|
|
|
|
mov r9, 0
|
2009-05-20 16:09:06 -04:00
|
|
|
mov rdx, [rcx+8]
|
|
|
|
not rdx
|
2009-05-27 12:10:04 -04:00
|
|
|
mov rax, -1
|
|
|
|
div qword[rcx+8]
|
2009-05-20 16:09:06 -04:00
|
|
|
mov rbp, rax
|
2009-05-27 12:10:04 -04:00
|
|
|
mov r8, [rsi+rbx*8]
|
|
|
|
dec rbx
|
|
|
|
mov r10, [rsi+rbx*8]
|
|
|
|
cmp r8, [rcx+8]
|
2009-12-02 11:24:00 -05:00
|
|
|
jae .1
|
2009-05-27 12:10:04 -04:00
|
|
|
mov rdx, r8
|
|
|
|
mov r9, r8
|
|
|
|
mov r10, [rsi+rbx*8]
|
2009-05-20 16:09:06 -04:00
|
|
|
mov r8, r10
|
2009-05-27 12:10:04 -04:00
|
|
|
mov r14, 0
|
2009-12-02 11:24:00 -05:00
|
|
|
jmp .3
|
2010-07-22 07:33:16 -04:00
|
|
|
.1: mov r14, 1
|
2009-05-27 12:10:04 -04:00
|
|
|
mov rdx, r8
|
|
|
|
sub rdx, [rcx+8]
|
|
|
|
sub r10, [rcx]
|
|
|
|
sbb rdx, 0
|
2009-12-02 11:24:00 -05:00
|
|
|
jnc .2
|
2009-05-27 12:10:04 -04:00
|
|
|
dec r14
|
|
|
|
add r10, [rcx]
|
|
|
|
adc rdx, [rcx+8]
|
2010-07-22 07:33:16 -04:00
|
|
|
.2: mov r9, rdx
|
2009-05-27 12:10:04 -04:00
|
|
|
mov r8, r10
|
2010-07-22 07:33:16 -04:00
|
|
|
.3: dec rbx
|
2009-05-27 12:10:04 -04:00
|
|
|
mov rax, r9
|
2009-12-02 11:24:00 -05:00
|
|
|
js .8
|
2009-05-20 16:09:06 -04:00
|
|
|
|
2009-05-27 12:10:04 -04:00
|
|
|
xalign 16
|
2010-07-22 07:33:16 -04:00
|
|
|
.4: cmp rax, [rcx+8]
|
2009-12-02 11:24:00 -05:00
|
|
|
jne .6
|
|
|
|
mov r10, [rsi+rbx*8]
|
|
|
|
mov r15, -1
|
|
|
|
mov rdx, r8
|
|
|
|
add r10, [rcx]
|
|
|
|
adc rdx, rax
|
|
|
|
sbb rax, rax
|
|
|
|
sub rdx, [rcx]
|
|
|
|
adc rax, 0
|
|
|
|
jz .5
|
|
|
|
dec r15
|
|
|
|
add r10, [rcx]
|
|
|
|
adc rdx, [rcx+8]
|
2010-07-22 07:33:16 -04:00
|
|
|
.5: mov rax, rdx
|
2009-12-02 11:24:00 -05:00
|
|
|
mov r8, r10
|
|
|
|
jmp .7
|
2010-07-22 07:33:16 -04:00
|
|
|
.6: mov r9, rax
|
2009-05-27 12:10:04 -04:00
|
|
|
bt r8, 63
|
|
|
|
adc rax, 0
|
|
|
|
mov r15, r8
|
|
|
|
mov r13, 0
|
|
|
|
sar r15, 63
|
|
|
|
and r15, [rcx+8]
|
|
|
|
add r15, r8
|
2009-05-20 16:09:06 -04:00
|
|
|
mul rbp
|
2009-05-27 12:10:04 -04:00
|
|
|
add rax, r15
|
2009-05-20 16:09:06 -04:00
|
|
|
mov rax, [rcx]
|
2009-05-27 12:10:04 -04:00
|
|
|
adc rdx, r9
|
|
|
|
mov r10, rdx
|
|
|
|
mul rdx
|
|
|
|
mov r12, [rcx]
|
|
|
|
add r12, rax
|
|
|
|
adc r13, rdx
|
|
|
|
mov rax, [rcx+8]
|
|
|
|
not r10
|
|
|
|
mul r10
|
|
|
|
sub r9, [rcx+8]
|
|
|
|
add rax, r8
|
|
|
|
adc rdx, r9
|
2009-05-20 16:09:06 -04:00
|
|
|
mov r9, rdx
|
2009-05-27 12:10:04 -04:00
|
|
|
and r9, [rcx+8]
|
|
|
|
; swapped r9,rax from here
|
|
|
|
add rax, r9
|
|
|
|
mov r15, rdx
|
|
|
|
sub r15, r10
|
|
|
|
and rdx, [rcx]
|
|
|
|
sub r12, rdx
|
|
|
|
sbb r13, 0
|
|
|
|
mov r8, [rsi+rbx*8]
|
|
|
|
sub r8, r12
|
|
|
|
sbb rax, r13
|
|
|
|
mov r10, [rcx]
|
|
|
|
mov r11, [rcx+8]
|
|
|
|
sbb r9, r9
|
|
|
|
and r10, r9
|
|
|
|
and r11, r9
|
|
|
|
add r15, r9
|
|
|
|
add r8, r10
|
|
|
|
adc rax, r11
|
|
|
|
adc r9, 0
|
|
|
|
and r10, r9
|
|
|
|
and r11, r9
|
|
|
|
add r15, r9
|
|
|
|
add r8, r10
|
|
|
|
adc rax, r11
|
2010-07-22 07:33:16 -04:00
|
|
|
.7: mov [rdi+rbx*8], r15
|
2009-05-20 16:09:06 -04:00
|
|
|
dec rbx
|
2009-12-02 11:24:00 -05:00
|
|
|
jns .4
|
2010-07-22 07:33:16 -04:00
|
|
|
.8: mov [rsi+8], rax
|
2009-05-20 16:09:06 -04:00
|
|
|
mov [rsi], r8
|
2009-05-27 12:10:04 -04:00
|
|
|
mov rax, r14
|
2009-05-20 16:09:06 -04:00
|
|
|
END_PROC reg_save_list
|
2009-05-27 12:10:04 -04:00
|
|
|
|
|
|
|
end
|