Tizen 2.1 base
[external/gmp.git] / mpn / x86 / pentium4 / sse2 / add_n.asm
1 dnl  Intel Pentium-4 mpn_add_n -- mpn addition.
2
3 dnl  Copyright 2001, 2002 Free Software Foundation, Inc.
4 dnl
5 dnl  This file is part of the GNU MP Library.
6 dnl
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.
11 dnl
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.
16 dnl
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/.
19
20 include(`../config.m4')
21
22
23 C P4 Willamette, Northwood: 4.0 cycles/limb if dst!=src1 and dst!=src2
24 C                           6.0 cycles/limb if dst==src1 or dst==src2
25 C P4 Prescott:              >= 5 cycles/limb
26
27 C mp_limb_t mpn_add_n (mp_ptr dst, mp_srcptr src1, mp_srcptr src2,
28 C                      mp_size_t size);
29 C mp_limb_t mpn_add_nc (mp_ptr dst, mp_srcptr src1, mp_srcptr src2,
30 C                       mp_size_t size, mp_limb_t carry);
31 C
32 C The 4 c/l achieved here isn't particularly good, but is better than 9 c/l
33 C for a basic adc loop.
34
35 defframe(PARAM_CARRY,20)
36 defframe(PARAM_SIZE, 16)
37 defframe(PARAM_SRC2, 12)
38 defframe(PARAM_SRC1, 8)
39 defframe(PARAM_DST,  4)
40
41 dnl  re-use parameter space
42 define(SAVE_EBX,`PARAM_SRC1')
43
44         TEXT
45         ALIGN(8)
46
47 PROLOGUE(mpn_add_nc)
48 deflit(`FRAME',0)
49
50         movd    PARAM_CARRY, %mm0
51         jmp     L(start_nc)
52
53 EPILOGUE()
54
55         ALIGN(8)
56 PROLOGUE(mpn_add_n)
57 deflit(`FRAME',0)
58
59         pxor    %mm0, %mm0
60
61 L(start_nc):
62         movl    PARAM_SRC1, %eax
63         movl    %ebx, SAVE_EBX
64         movl    PARAM_SRC2, %ebx
65         movl    PARAM_DST, %edx
66         movl    PARAM_SIZE, %ecx
67
68         leal    (%eax,%ecx,4), %eax     C src1 end
69         leal    (%ebx,%ecx,4), %ebx     C src2 end
70         leal    (%edx,%ecx,4), %edx     C dst end
71         negl    %ecx                    C -size
72
73 L(top):
74         C eax   src1 end
75         C ebx   src2 end
76         C ecx   counter, limbs, negative
77         C edx   dst end
78         C mm0   carry bit
79
80         movd    (%eax,%ecx,4), %mm1
81         movd    (%ebx,%ecx,4), %mm2
82         paddq   %mm2, %mm1
83
84         paddq   %mm1, %mm0
85         movd    %mm0, (%edx,%ecx,4)
86
87         psrlq   $32, %mm0
88
89         addl    $1, %ecx
90         jnz     L(top)
91
92
93         movd    %mm0, %eax
94         movl    SAVE_EBX, %ebx
95         emms
96         ret
97
98 EPILOGUE()