1 dnl AMD K6 mpn_mul_1 -- mpn by limb multiply.
3 dnl Copyright 1999, 2000, 2002, 2005 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')
25 C P6 model 0-8,10-12) 5.5
27 C P6 model 13 (Dothan) 4.87
28 C P4 model 0 (Willamette)
30 C P4 model 2 (Northwood)
31 C P4 model 3 (Prescott)
38 C mp_limb_t mpn_mul_1 (mp_ptr dst, mp_srcptr src, mp_size_t size,
39 C mp_limb_t multiplier);
40 C mp_limb_t mpn_mul_1c (mp_ptr dst, mp_srcptr src, mp_size_t size,
41 C mp_limb_t multiplier, mp_limb_t carry);
43 C Multiply src,size by mult and store the result in dst,size.
44 C Return the carry limb from the top of the result.
46 C mpn_mul_1c() accepts an initial carry for the calculation, it's added into
47 C the low limb of the result.
49 defframe(PARAM_CARRY, 20)
50 defframe(PARAM_MULTIPLIER,16)
51 defframe(PARAM_SIZE, 12)
52 defframe(PARAM_SRC, 8)
53 defframe(PARAM_DST, 4)
55 dnl minimum 5 because the unrolled code can't handle less
56 deflit(UNROLL_THRESHOLD, 5)
64 movl PARAM_CARRY, %esi
72 xorl %esi, %esi C initial carry
87 cmpl $UNROLL_THRESHOLD, %ecx
88 movl PARAM_MULTIPLIER, %ebp
93 C code offset 0x22 here, close enough to aligned
103 C this loop 8 cycles/limb
132 C -----------------------------------------------------------------------------
133 C The code for each limb is 6 cycles, with instruction decoding being the
134 C limiting factor. At 4 limbs/loop and 1 cycle/loop of overhead it's 6.25
135 C cycles/limb in total.
137 C The secret ingredient to get 6.25 is to start the loop with the mul and
138 C have the load/store pair at the end. Rotating the load/store to the top
139 C is an 0.5 c/l slowdown. (Some address generation effect probably.)
141 C The whole unrolled loop fits nicely in exactly 80 bytes.
144 ALIGN(16) C already aligned to 16 here actually
147 leal -16(%ebx,%ecx,4), %ebx
149 leal -16(%edi,%ecx,4), %edi
155 ALIGN(16) C one byte nop for this alignment
172 movl %eax, (%edi,%ecx,4)
173 movl 4(%ebx,%ecx,4), %eax
183 movl %eax, 4(%edi,%ecx,4)
184 movl 8(%ebx,%ecx,4), %eax
194 movl %eax, 8(%edi,%ecx,4)
195 movl 12(%ebx,%ecx,4), %eax
205 movl %eax, 12(%edi,%ecx,4)
206 movl 16(%ebx,%ecx,4), %eax
216 C ecx 0 to 3 representing respectively 4 to 1 further limbs
222 jnz L(finish_not_two)
231 movl %eax, (%edi,%ecx,4)
232 movl 4(%ebx,%ecx,4), %eax
242 movl %eax, 4(%edi,%ecx,4)
243 movl 8(%ebx,%ecx,4), %eax
250 jnz L(finish_not_one)