1 dnl AMD K6 mpn_mul_1 -- mpn by limb multiply.
3 dnl K6: 6.25 cycles/limb.
6 dnl Copyright (C) 1999, 2000 Free Software Foundation, Inc.
8 dnl This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU Lesser General Public License as
12 dnl published by the Free Software Foundation; either version 2.1 of the
13 dnl License, or (at your option) any later version.
15 dnl The GNU MP Library is distributed in the hope that it will be useful,
16 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 dnl Lesser General Public License for more details.
20 dnl You should have received a copy of the GNU Lesser General Public
21 dnl License along with the GNU MP Library; see the file COPYING.LIB. If
22 dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
23 dnl Suite 330, Boston, MA 02111-1307, USA.
26 include(`../config.m4')
29 C mp_limb_t mpn_mul_1 (mp_ptr dst, mp_srcptr src, mp_size_t size,
30 C mp_limb_t multiplier);
31 C mp_limb_t mpn_mul_1c (mp_ptr dst, mp_srcptr src, mp_size_t size,
32 C mp_limb_t multiplier, mp_limb_t carry);
34 C Multiply src,size by mult and store the result in dst,size.
35 C Return the carry limb from the top of the result.
37 C mpn_mul_1c() accepts an initial carry for the calculation, it's added into
38 C the low limb of the result.
40 defframe(PARAM_CARRY, 20)
41 defframe(PARAM_MULTIPLIER,16)
42 defframe(PARAM_SIZE, 12)
43 defframe(PARAM_SRC, 8)
44 defframe(PARAM_DST, 4)
46 dnl minimum 5 because the unrolled code can't handle less
47 deflit(UNROLL_THRESHOLD, 5)
55 movl PARAM_CARRY, %esi
56 jmp LF(mpn_mul_1,start_nc)
63 xorl %esi, %esi C initial carry
78 cmpl $UNROLL_THRESHOLD, %ecx
79 movl PARAM_MULTIPLIER, %ebp
84 C code offset 0x22 here, close enough to aligned
94 C this loop 8 cycles/limb
123 C -----------------------------------------------------------------------------
124 C The code for each limb is 6 cycles, with instruction decoding being the
125 C limiting factor. At 4 limbs/loop and 1 cycle/loop of overhead it's 6.25
126 C cycles/limb in total.
128 C The secret ingredient to get 6.25 is to start the loop with the mul and
129 C have the load/store pair at the end. Rotating the load/store to the top
130 C is an 0.5 c/l slowdown. (Some address generation effect probably.)
132 C The whole unrolled loop fits nicely in exactly 80 bytes.
135 ALIGN(16) C already aligned to 16 here actually
138 leal -16(%ebx,%ecx,4), %ebx
140 leal -16(%edi,%ecx,4), %edi
146 ALIGN(16) C one byte nop for this alignment
163 movl %eax, (%edi,%ecx,4)
164 movl 4(%ebx,%ecx,4), %eax
174 movl %eax, 4(%edi,%ecx,4)
175 movl 8(%ebx,%ecx,4), %eax
185 movl %eax, 8(%edi,%ecx,4)
186 movl 12(%ebx,%ecx,4), %eax
196 movl %eax, 12(%edi,%ecx,4)
197 movl 16(%ebx,%ecx,4), %eax
207 C ecx 0 to 3 representing respectively 4 to 1 further limbs
213 jnz L(finish_not_two)
222 movl %eax, (%edi,%ecx,4)
223 movl 4(%ebx,%ecx,4), %eax
233 movl %eax, 4(%edi,%ecx,4)
234 movl 8(%ebx,%ecx,4), %eax
241 jnz L(finish_not_one)