1 dnl AMD K6 mpn_modexact_1_odd -- exact division style remainder.
3 dnl Copyright 2000, 2001, 2002, 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
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')
23 C K6: 10.0 cycles/limb
26 C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
28 C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
29 C mp_limb_t divisor, mp_limb_t carry);
31 C A special case for high<divisor at the end measured only about 4 cycles
32 C faster, and so isn't used.
34 C A special case for size==1 using a divl rather than the inverse measured
35 C only about 5 cycles faster, and so isn't used. When size==1 and
36 C high<divisor it can skip a division and be a full 24 cycles faster, but
37 C this isn't an important case.
39 defframe(PARAM_CARRY, 16)
40 defframe(PARAM_DIVISOR,12)
41 defframe(PARAM_SIZE, 8)
42 defframe(PARAM_SRC, 4)
47 PROLOGUE(mpn_modexact_1c_odd)
50 movl PARAM_DIVISOR, %ecx
51 pushl %esi FRAME_pushl()
53 movl PARAM_CARRY, %edx
60 PROLOGUE(mpn_modexact_1_odd)
63 movl PARAM_DIVISOR, %ecx
64 pushl %esi FRAME_pushl()
68 pushl %edi FRAME_pushl()
71 movl PARAM_DIVISOR, %esi
73 andl $127, %ecx C d/2, 7 bits
74 pushl %ebp FRAME_pushl()
77 LEA( binvert_limb_table, %edi)
78 Zdisp( movzbl, 0,(%ecx,%edi), %edi) C inv 8 bits
80 movzbl binvert_limb_table(%ecx), %edi C inv 8 bits
82 leal (%edi,%edi), %ecx C 2*inv
84 imull %edi, %edi C inv*inv
89 imull %esi, %edi C inv*inv*d
91 pushl %ebx FRAME_pushl()
92 leal (%eax,%ebp,4), %ebx C src end
94 subl %edi, %ecx C inv = 2*inv - inv*inv*d
95 leal (%ecx,%ecx), %edi C 2*inv
97 imull %ecx, %ecx C inv*inv
99 movl (%eax), %eax C src low limb
102 imull %esi, %ecx C inv*inv*d
104 subl %ecx, %edi C inv = 2*inv - inv*inv*d
106 ASSERT(e,` C d*inv == 1 mod 2^GMP_LIMB_BITS
116 C Rotating the mul to the top of the loop saves 1 cycle, presumably by
117 C hiding the loop control under the imul latency.
119 C The run time is 10 cycles, but decoding is only 9 (and the dependent chain
120 C only 8). It's not clear how to get down to 9 cycles.
122 C The xor and rcl to handle the carry bit could be an sbb instead, with the
123 C the carry bit add becoming a sub, but that doesn't save anything.
128 C ecx carry bit, 0 or 1
129 C edx (high product, being carry limb)
132 C ebp counter, limbs, negative
136 movl (%ebx,%ebp,4), %eax
137 addl %ecx, %edx C apply carry bit to carry limb
141 subl %edx, %eax C apply carry limb
160 leal (%ecx,%edx), %eax