1 dnl AMD K6 mpn_preinv_mod_1
-- mpn by
1 remainder
, with pre
-inverted divisor.
3 dnl Copyright
2000, 2002, 2003 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
either:
10 dnl
* the GNU Lesser General
Public License as published by the Free
11 dnl Software Foundation
; either version 3 of the License, or (at your
12 dnl option
) any later version.
16 dnl
* the GNU General
Public License as published by the Free Software
17 dnl Foundation
; either version 2 of the License, or (at your option) any
20 dnl
or both
in parallel
, as here.
22 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
23 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
24 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
27 dnl You should have received copies of the GNU General
Public License
and the
28 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
29 dnl see
https://www.gnu.
org/licenses
/.
31 include(`..
/config.m4
')
34 C K6: 18.0 cycles/limb
37 C mp_limb_t mpn_preinv_mod_1 (mp_srcptr src, mp_size_t size, mp_limb_t divisor,
40 C This code is only 2 c/l faster than a simple divl, but that's
10% so it
's
41 C considered worthwhile (just).
43 defframe(PARAM_INVERSE,16)
44 defframe(PARAM_DIVISOR,12)
45 defframe(PARAM_SIZE, 8)
46 defframe(PARAM_SRC, 4)
50 PROLOGUE(mpn_preinv_mod_1)
53 ASSERT
(ae
,`cmpl
$1, PARAM_SIZE
')
54 ASSERT(nz,`testl $0x80000000, PARAM_DIVISOR')
57 pushl
%ebp FRAME_pushl
()
60 pushl
%edi FRAME_pushl
()
62 movl PARAM_DIVISOR
, %eax
63 pushl
%esi FRAME_pushl
()
65 movl
-4(%ebp,%ecx,4), %esi C src
high limb
66 pushl
%ebx FRAME_pushl
()
68 movl
%edx, %edi C first n2 to cancel
69 subl
%eax, %esi C first n1
= high-divisor
77 C
ecx counter
, size to
1
80 C
edi old
high, for underflow
test
83 sbbl
%edx, %edi C
high n
-(q1
+1)*d
, 0 or -1
86 andl PARAM_DIVISOR
, %edi
88 movl
-4(%ebp,%ecx,4), %ebx
90 addl
%esi, %edi C possible addback
93 sarl
$31, %ebx C
-n1
= 0 or -1
96 movl PARAM_INVERSE
, %edx
97 subl
%ebx, %eax C n2
+n1
101 andl PARAM_DIVISOR
, %ebx C
-n1
& d
102 addl
%esi, %ebx C nadj
= n10
+ (-n1
&d
), ignoring overflow
104 addl
%ebx, %eax C
low m
*(n2
+n1
) + nadj
, giving carry flag
105 leal
1(%edi), %ebx C n2
+1
107 adcl
%ebx, %edx C
1+high(n2
<<32+m
*(n2
+n1
)+nadj
) = q1
+1
109 movl PARAM_DIVISOR
, %eax C d
114 subl
%eax, %esi C
low n
-(q1
+1)*d
120 sbbl
%edx, %edi C
high n
-(q1
+1)*d
, 0 or -1
122 andl PARAM_DIVISOR
, %edi
126 leal
(%esi,%edi), %eax
135 C Special case for q1
=0xFFFFFFFF, giving q
=0xFFFFFFFF meaning the
low dword
136 C of q
*d is simply
-d
and the remainder n
-q
*d
= n10
+d.
This is rarely
140 movl PARAM_DIVISOR
, %edi