Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / i386 / add_n.S
blob5223d685952d60931552f582c393149be60b98d0
1 /* Add two limb vectors of the same length > 0 and store sum in a third
2    limb vector.
3    Copyright (C) 1992,94,95,97,98,2000,2005 Free Software Foundation, Inc.
4    This file is part of the GNU MP Library.
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.
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.
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/>.  */
20 #include "sysdep.h"
21 #include "asm-syntax.h"
22 #include "bp-sym.h"
23 #include "bp-asm.h"
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
31         .text
32 ENTRY (BP_SYM (__mpn_add_n))
33         ENTER
35         pushl %edi
36         cfi_adjust_cfa_offset (4)
37         pushl %esi
38         cfi_adjust_cfa_offset (4)
40         movl RES(%esp),%edi
41         cfi_rel_offset (edi, 4)
42         movl S1(%esp),%esi
43         cfi_rel_offset (esi, 0)
44         movl S2(%esp),%edx
45         movl SIZE(%esp),%ecx
46 #if __BOUNDED_POINTERS__
47         shll    $2, %ecx        /* convert limbs to bytes */
48         CHECK_BOUNDS_BOTH_WIDE (%edi, RES(%esp), %ecx)
49         CHECK_BOUNDS_BOTH_WIDE (%esi, S1(%esp), %ecx)
50         CHECK_BOUNDS_BOTH_WIDE (%edx, S2(%esp), %ecx)
51         shrl    $2, %ecx
52 #endif
53         movl    %ecx,%eax
54         shrl    $3,%ecx                 /* compute count for unrolled loop */
55         negl    %eax
56         andl    $7,%eax                 /* get index where to start loop */
57         jz      L(oop)                  /* necessary special case for 0 */
58         incl    %ecx                    /* adjust loop count */
59         shll    $2,%eax                 /* adjustment for pointers... */
60         subl    %eax,%edi               /* ... since they are offset ... */
61         subl    %eax,%esi               /* ... by a constant when we ... */
62         subl    %eax,%edx               /* ... enter the loop */
63         shrl    $2,%eax                 /* restore previous value */
64 #ifdef PIC
65 /* Calculate start address in loop for PIC.  Due to limitations in some
66    assemblers, Loop-L0-3 cannot be put into the leal */
67         call    L(0)
68         cfi_adjust_cfa_offset (4)
69 L(0):   leal    (%eax,%eax,8),%eax
70         addl    (%esp),%eax
71         addl    $(L(oop)-L(0)-3),%eax
72         addl    $4,%esp
73         cfi_adjust_cfa_offset (-4)
74 #else
75 /* Calculate start address in loop for non-PIC.  */
76         leal    (L(oop) - 3)(%eax,%eax,8),%eax
77 #endif
78         jmp     *%eax                   /* jump into loop */
79         ALIGN (3)
80 L(oop): movl    (%esi),%eax
81         adcl    (%edx),%eax
82         movl    %eax,(%edi)
83         movl    4(%esi),%eax
84         adcl    4(%edx),%eax
85         movl    %eax,4(%edi)
86         movl    8(%esi),%eax
87         adcl    8(%edx),%eax
88         movl    %eax,8(%edi)
89         movl    12(%esi),%eax
90         adcl    12(%edx),%eax
91         movl    %eax,12(%edi)
92         movl    16(%esi),%eax
93         adcl    16(%edx),%eax
94         movl    %eax,16(%edi)
95         movl    20(%esi),%eax
96         adcl    20(%edx),%eax
97         movl    %eax,20(%edi)
98         movl    24(%esi),%eax
99         adcl    24(%edx),%eax
100         movl    %eax,24(%edi)
101         movl    28(%esi),%eax
102         adcl    28(%edx),%eax
103         movl    %eax,28(%edi)
104         leal    32(%edi),%edi
105         leal    32(%esi),%esi
106         leal    32(%edx),%edx
107         decl    %ecx
108         jnz     L(oop)
110         sbbl    %eax,%eax
111         negl    %eax
113         popl %esi
114         cfi_adjust_cfa_offset (-4)
115         cfi_restore (esi)
116         popl %edi
117         cfi_adjust_cfa_offset (-4)
118         cfi_restore (edi)
120         LEAVE
121         ret
122 END (BP_SYM (__mpn_add_n))