1 dnl AMD K7 mpn_modexact_1_odd -- exact division style remainder.
3 dnl Copyright 2000, 2001, 2002, 2004, 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
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public 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')
28 C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
30 C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
31 C mp_limb_t divisor, mp_limb_t carry);
33 C With the loop running at just 11 cycles it doesn't seem worth bothering to
34 C check for high<divisor to save one step.
36 C Using a divl for size==1 measures slower than the modexact method, which
37 C is not too surprising since for the latter it's only about 24 cycles to
38 C calculate the modular inverse.
40 defframe(PARAM_CARRY, 16)
41 defframe(PARAM_DIVISOR,12)
42 defframe(PARAM_SIZE, 8)
43 defframe(PARAM_SRC, 4)
45 defframe(SAVE_EBX, -4)
46 defframe(SAVE_ESI, -8)
47 defframe(SAVE_EDI, -12)
48 defframe(SAVE_EBP, -16)
50 deflit(STACK_SPACE, 16)
55 PROLOGUE(mpn_modexact_1c_odd)
58 movl PARAM_CARRY, %ecx
65 PROLOGUE(mpn_modexact_1_odd)
70 movl PARAM_DIVISOR, %eax
71 subl $STACK_SPACE, %esp FRAME_subl_esp(STACK_SPACE)
74 movl PARAM_DIVISOR, %esi
83 LEA( binvert_limb_table, %edi)
84 movzbl (%eax,%edi), %edi C inv 8 bits
86 movzbl binvert_limb_table(%eax), %edi C inv 8 bits
89 xorl %edx, %edx C initial extra carry
90 leal (%edi,%edi), %eax C 2*inv
92 imull %edi, %edi C inv*inv
100 imull %esi, %edi C inv*inv*d
102 subl %edi, %eax C inv = 2*inv - inv*inv*d
103 leal (%eax,%eax), %edi C 2*inv
105 imull %eax, %eax C inv*inv
107 imull %esi, %eax C inv*inv*d
109 leal (%ebx,%ebp,4), %ebx C src end
112 subl %eax, %edi C inv = 2*inv - inv*inv*d
114 ASSERT(e,` C d*inv == 1 mod 2^GMP_LIMB_BITS
120 C The dependent chain here is
125 C mull %esi 6 (high limb)
129 C Out of order execution hides the load latency for the source data, so no
130 C special scheduling is required.
135 C ecx next carry bit, 0 or 1 (or initial carry param)
136 C edx carry limb, high of last product
139 C ebp counter, limbs, negative
141 movl (%ebx,%ebp,4), %eax
143 subl %ecx, %eax C apply carry bit
146 setc %cl C new carry bit
148 subl %edx, %eax C apply carry limb
161 leal (%ecx,%edx), %eax
165 addl $STACK_SPACE, %esp