1 dnl AMD K6 mpn_add
/sub_n
-- mpn addition
or subtraction.
3 dnl Copyright
1999-2002 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: normal 3.25 cycles/limb, in-place 2.75 cycles/limb.
37 ifdef(`OPERATION_add_n', `
39 define
(M4_function_n
, mpn_add_n
)
40 define
(M4_function_nc
, mpn_add_nc
)
41 define
(M4_description
, add)
42 ',`ifdef(`OPERATION_sub_n', `
44 define
(M4_function_n
, mpn_sub_n
)
45 define
(M4_function_nc
, mpn_sub_nc
)
46 define
(M4_description
, subtract
)
47 ',`m4_error(`Need OPERATION_add_n or OPERATION_sub_n
50 MULFUNC_PROLOGUE
(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc
)
53 C mp_limb_t M4_function_n
(mp_ptr dst
, mp_srcptr src1
, mp_srcptr src2
,
55 C mp_limb_t M4_function_nc
(mp_ptr dst
, mp_srcptr src1
, mp_srcptr src2
,
56 C mp_size_t
size, mp_limb_t carry
);
58 C Calculate src1
,size M4_description src2
,size, and store the result
in
59 C dst
,size. The return value is the carry bit from the top of the result
62 C The _nc version accepts
1 or 0 for an initial carry
into the
low limb of
63 C the calculation. Note values other than
1 or 0 here will lead to garbage
66 C Instruction decoding limits a normal dst
=src1
+src2 operation to
3 c
/l
, and
67 C an
in-place dst
+=src to
2.5 c
/l. The unrolled loops have
1 cycle
/loop of
68 C
loop control
, which with
4 limbs
/loop means an extra
0.25 c
/l.
70 define
(PARAM_CARRY
, `FRAME
+20(%esp)')
71 define(PARAM_SIZE, `FRAME+16(%esp)')
72 define
(PARAM_SRC2
, `FRAME
+12(%esp)')
73 define(PARAM_SRC1, `FRAME+8(%esp)')
74 define
(PARAM_DST
, `FRAME
+4(%esp)')
77 dnl minimum
5 because the unrolled code can
't handle less
78 deflit(UNROLL_THRESHOLD, 5)
83 PROLOGUE(M4_function_nc)
84 movl PARAM_CARRY, %eax
89 PROLOGUE(M4_function_n)
100 movl PARAM_SRC2, %edx
101 cmpl $UNROLL_THRESHOLD, %ecx
107 shrl %eax C initial carry flag
109 C offset 0x21 here, close enough to aligned
119 C The store to (%edi) could be done with a stosl; it'd be smaller
120 C code
, but there
's no speed gain and a cld would have to be added
121 C (per mpn/x86/README).
144 C -----------------------------------------------------------------------------
159 ifdef(`OPERATION_add_n',`
162 je L
(inplace_reverse
)
170 leal (%ebx,%ecx,4), %ebx
171 leal (%edx,%ecx,4), %edx
172 leal (%edi,%ecx,4), %edi
179 C eax counter, qwords, negative
187 movl (%ebx,%ecx,4), %eax
189 M4_inst -20(%edx,%ecx,4), %eax
190 movl %eax, -20(%edi,%ecx,4)
192 movl 4-20(%ebx,%ecx,4), %eax
193 M4_inst 4-20(%edx,%ecx,4), %eax
194 movl %eax, 4-20(%edi,%ecx,4)
196 movl 8-20(%ebx,%ecx,4), %eax
197 M4_inst 8-20(%edx,%ecx,4), %eax
198 movl %eax, 8-20(%edi,%ecx,4)
200 movl 12-20(%ebx,%ecx,4), %eax
201 M4_inst 12-20(%edx,%ecx,4), %eax
202 movl %eax, 12-20(%edi,%ecx,4)
208 jz L(normal_finish_one)
211 C two or three more limbs
218 M4_inst 4(%edx), %eax
225 L(normal_finish_one):
226 movl (%ebx,%ecx,4), %eax
227 M4_inst (%edx,%ecx,4), %eax
228 movl %eax, (%edi,%ecx,4)
242 C -----------------------------------------------------------------------------
244 ifdef(`OPERATION_add_n',`
266 movl (%edx), %ebx C src low limb
267 leal (%edx,%ecx,4), %edx
269 leal (%edi,%ecx,4), %edi
285 M4_inst %ebx, (%edi,%ecx,4)
287 movl 4(%edx,%ecx,4), %eax
290 M4_inst %eax, 4-20(%edi,%ecx,4)
292 movl 8-20(%edx,%ecx,4), %eax
293 movl 12-20(%edx,%ecx,4), %ebx
295 M4_inst %eax, 8-20(%edi,%ecx,4)
296 M4_inst %ebx, 12-20(%edi,%ecx,4)
298 movl 16-20(%edx,%ecx,4), %ebx
302 C now %esi is 0 to 3 representing respectively 1 to 4 limbs more
307 jz L(inplace_finish_one)
310 C two or three more limbs
314 M4_inst %eax, 4(%edi)
315 M4_inst %ebx, 8(%edi)
322 L(inplace_finish_one):
323 movl 4(%edx,%ecx,4), %eax
324 M4_inst %eax, 4(%edi,%ecx,4)