1 dnl AMD64 mpn_divexact_1 -- mpn by limb exact division.
3 dnl Copyright 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU Lesser General Public License as published
9 dnl by the Free Software Foundation; either version 3 of the License, or (at
10 dnl your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 dnl License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
31 C A quick adoption of the 32-bit K7 code.
43 PROLOGUE(mpn_divexact_1)
47 xor R32(%rcx), R32(%rcx) C shift count
51 jnc L(evn) C skip bsfq unless divisor is even
53 L(odd): mov %rax, %rbx
55 and $127, R32(%rax) C d/2, 7 bits
58 mov binvert_limb_table@GOTPCREL(%rip), %rdx
60 movabs $binvert_limb_table, %rdx
63 movzbl (%rdx,%rax), R32(%rax) C inv 8 bits
65 mov %rbx, %r11 C d without twos
67 lea (%rax,%rax), R32(%rdx) C 2*inv
68 imul R32(%rax), R32(%rax) C inv*inv
69 imul R32(%rbx), R32(%rax) C inv*inv*d
70 sub R32(%rax), R32(%rdx) C inv = 2*inv - inv*inv*d, 16 bits
72 lea (%rdx,%rdx), R32(%rax) C 2*inv
73 imul R32(%rdx), R32(%rdx) C inv*inv
74 imul R32(%rbx), R32(%rdx) C inv*inv*d
75 sub R32(%rdx), R32(%rax) C inv = 2*inv - inv*inv*d, 32 bits
77 lea (%rax,%rax), %r10 C 2*inv
78 imul %rax, %rax C inv*inv
79 imul %rbx, %rax C inv*inv*d
80 sub %rax, %r10 C inv = 2*inv - inv*inv*d, 64 bits
82 lea (%rsi,%r8,8), %rsi C up end
83 lea -8(%rdi,%r8,8), %rdi C rp end
86 mov (%rsi,%r8,8), %rax C up[0]
91 mov (%rsi,%r8,8), %rdx C up[1]
93 shrd R8(%rcx), %rdx, %rax
95 xor R32(%rbx), R32(%rbx)
98 L(evn): bsf %rax, %rcx
105 C rbx carry bit, 0 or 1
110 C r8 counter, limbs, negative
111 C r10 d^(-1) mod 2^64
112 C r11 d, shifted down
114 mul %r11 C carry limb in rdx 0 10
115 mov -8(%rsi,%r8,8), %rax C
116 mov (%rsi,%r8,8), %r9 C
117 shrd R8(%rcx), %r9, %rax C
119 sub %rbx, %rax C apply carry bit
121 sub %rdx, %rax C apply carry limb 5
123 L(ent): imul %r10, %rax C 6
124 mov %rax, (%rdi,%r8,8) C
128 mul %r11 C carry limb in rdx
129 mov -8(%rsi), %rax C up high limb
131 sub %rbx, %rax C apply carry bit
132 sub %rdx, %rax C apply carry limb
138 L(one): shr R8(%rcx), %rax