1 dnl AMD K6 mpn_modexact_1_odd
-- exact division style remainder.
3 dnl Copyright
2000-2003, 2007 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: 10.0 cycles/limb
37 C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
39 C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
40 C mp_limb_t divisor, mp_limb_t carry);
42 C A special case for high<divisor at the end measured only about 4 cycles
43 C faster, and so isn't used.
45 C A special case for
size==1 using a divl rather than the inverse measured
46 C only about
5 cycles faster
, and so isn
't used. When size==1 and
47 C high<divisor it can skip a division and be a full 24 cycles faster, but
48 C this isn't an important case.
50 defframe
(PARAM_CARRY
, 16)
51 defframe
(PARAM_DIVISOR
,12)
52 defframe
(PARAM_SIZE
, 8)
53 defframe
(PARAM_SRC
, 4)
58 PROLOGUE
(mpn_modexact_1c_odd
)
61 movl PARAM_DIVISOR, %ecx
62 pushl %esi FRAME_pushl()
64 movl PARAM_CARRY, %edx
71 PROLOGUE(mpn_modexact_1_odd)
74 movl PARAM_DIVISOR
, %ecx
75 pushl
%esi FRAME_pushl
()
79 pushl
%edi FRAME_pushl
()
82 movl PARAM_DIVISOR
, %esi
84 andl
$127, %ecx C d
/2, 7 bits
85 pushl
%ebp FRAME_pushl
()
88 LEA( binvert_limb_table, %edi)
89 Zdisp( movzbl, 0,(%ecx,%edi), %edi) C inv 8 bits
91 movzbl binvert_limb_table
(%ecx), %edi C inv
8 bits
93 leal (%edi,%edi), %ecx C 2*inv
95 imull %edi, %edi C inv*inv
100 imull %esi, %edi C inv*inv*d
102 pushl %ebx FRAME_pushl()
103 leal (%eax,%ebp,4), %ebx C src end
105 subl %edi, %ecx C inv = 2*inv - inv*inv*d
106 leal (%ecx,%ecx), %edi C 2*inv
108 imull %ecx, %ecx C inv*inv
110 movl (%eax), %eax C src low limb
113 imull %esi, %ecx C inv*inv*d
115 subl %ecx, %edi C inv = 2*inv - inv*inv*d
117 ASSERT(e,` C d*inv == 1 mod 2^GMP_LIMB_BITS
127 C Rotating the
mul to the top of the
loop saves
1 cycle
, presumably by
128 C hiding the
loop control under the imul latency.
130 C The run time is
10 cycles
, but decoding is only
9 (and the dependent chain
131 C only
8). It
's not clear how to get down to 9 cycles.
133 C The xor and rcl to handle the carry bit could be an sbb instead, with the
134 C the carry bit add becoming a sub, but that doesn't save anything.
139 C
ecx carry bit
, 0 or 1
140 C
edx (high product
, being carry limb
)
143 C
ebp counter
, limbs
, negative
147 movl
(%ebx,%ebp,4), %eax
148 addl
%ecx, %edx C apply carry bit to carry limb
152 subl
%edx, %eax C apply carry limb
171 leal
(%ecx,%edx), %eax