d651bf91d06e46da615127c89deb7f9ffc6526da
[platform/upstream/glibc.git] / sysdeps / i386 / add_n.S
1 /* Add two limb vectors of the same length > 0 and store sum in a third
2    limb vector.
3    Copyright (C) 1992-2013 Free Software Foundation, Inc.
4    This file is part of the GNU MP Library.
5
6    The GNU MP Library is free software; you can redistribute it and/or modify
7    it under the terms of the GNU Lesser General Public License as published by
8    the Free Software Foundation; either version 2.1 of the License, or (at your
9    option) any later version.
10
11    The GNU MP Library is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14    License for more details.
15
16    You should have received a copy of the GNU Lesser General Public License
17    along with the GNU MP Library; see the file COPYING.LIB.  If not,
18    see <http://www.gnu.org/licenses/>.  */
19
20 #include "sysdep.h"
21 #include "asm-syntax.h"
22 #include "bp-sym.h"
23 #include "bp-asm.h"
24
25 #define PARMS   LINKAGE+8       /* space for 2 saved regs */
26 #define RES     PARMS
27 #define S1      RES+PTR_SIZE
28 #define S2      S1+PTR_SIZE
29 #define SIZE    S2+PTR_SIZE
30
31         .text
32 ENTRY (BP_SYM (__mpn_add_n))
33
34         pushl %edi
35         cfi_adjust_cfa_offset (4)
36         pushl %esi
37         cfi_adjust_cfa_offset (4)
38
39         movl RES(%esp),%edi
40         cfi_rel_offset (edi, 4)
41         movl S1(%esp),%esi
42         cfi_rel_offset (esi, 0)
43         movl S2(%esp),%edx
44         movl SIZE(%esp),%ecx
45         movl    %ecx,%eax
46         shrl    $3,%ecx                 /* compute count for unrolled loop */
47         negl    %eax
48         andl    $7,%eax                 /* get index where to start loop */
49         jz      L(oop)                  /* necessary special case for 0 */
50         incl    %ecx                    /* adjust loop count */
51         shll    $2,%eax                 /* adjustment for pointers... */
52         subl    %eax,%edi               /* ... since they are offset ... */
53         subl    %eax,%esi               /* ... by a constant when we ... */
54         subl    %eax,%edx               /* ... enter the loop */
55         shrl    $2,%eax                 /* restore previous value */
56 #ifdef PIC
57 /* Calculate start address in loop for PIC.  Due to limitations in some
58    assemblers, Loop-L0-3 cannot be put into the leal */
59         call    L(0)
60         cfi_adjust_cfa_offset (4)
61 L(0):   leal    (%eax,%eax,8),%eax
62         addl    (%esp),%eax
63         addl    $(L(oop)-L(0)-3),%eax
64         addl    $4,%esp
65         cfi_adjust_cfa_offset (-4)
66 #else
67 /* Calculate start address in loop for non-PIC.  */
68         leal    (L(oop) - 3)(%eax,%eax,8),%eax
69 #endif
70         jmp     *%eax                   /* jump into loop */
71         ALIGN (3)
72 L(oop): movl    (%esi),%eax
73         adcl    (%edx),%eax
74         movl    %eax,(%edi)
75         movl    4(%esi),%eax
76         adcl    4(%edx),%eax
77         movl    %eax,4(%edi)
78         movl    8(%esi),%eax
79         adcl    8(%edx),%eax
80         movl    %eax,8(%edi)
81         movl    12(%esi),%eax
82         adcl    12(%edx),%eax
83         movl    %eax,12(%edi)
84         movl    16(%esi),%eax
85         adcl    16(%edx),%eax
86         movl    %eax,16(%edi)
87         movl    20(%esi),%eax
88         adcl    20(%edx),%eax
89         movl    %eax,20(%edi)
90         movl    24(%esi),%eax
91         adcl    24(%edx),%eax
92         movl    %eax,24(%edi)
93         movl    28(%esi),%eax
94         adcl    28(%edx),%eax
95         movl    %eax,28(%edi)
96         leal    32(%edi),%edi
97         leal    32(%esi),%esi
98         leal    32(%edx),%edx
99         decl    %ecx
100         jnz     L(oop)
101
102         sbbl    %eax,%eax
103         negl    %eax
104
105         popl %esi
106         cfi_adjust_cfa_offset (-4)
107         cfi_restore (esi)
108         popl %edi
109         cfi_adjust_cfa_offset (-4)
110         cfi_restore (edi)
111
112         ret
113 END (BP_SYM (__mpn_add_n))