Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / i386 / i586 / add_n.S
blob395c4b78f45f8c53131989cad72af4f615d1ee2f
1 /* Pentium __mpn_add_n -- Add two limb vectors of the same length > 0 and store
2    sum in a third limb vector.
3    Copyright (C) 1992-2013 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+16              /* space for 4 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)
39         pushl   %ebp
40         cfi_adjust_cfa_offset (4)
41         pushl   %ebx
42         cfi_adjust_cfa_offset (4)
44         movl    RES(%esp),%edi
45         cfi_rel_offset (edi, 12)
46         movl    S1(%esp),%esi
47         cfi_rel_offset (esi, 8)
48         movl    S2(%esp),%ebx
49         cfi_rel_offset (ebx, 0)
50         movl    SIZE(%esp),%ecx
51 #if __BOUNDED_POINTERS__
52         shll    $2, %ecx                /* convert limbs to bytes */
53         CHECK_BOUNDS_BOTH_WIDE (%edi, RES(%esp), %ecx)
54         CHECK_BOUNDS_BOTH_WIDE (%esi, S1(%esp), %ecx)
55         CHECK_BOUNDS_BOTH_WIDE (%ebx, S2(%esp), %ecx)
56         shrl    $2, %ecx
57 #endif
58         movl    (%ebx),%ebp
59         cfi_rel_offset (ebp, 4)
61         decl    %ecx
62         movl    %ecx,%edx
63         shrl    $3,%ecx
64         andl    $7,%edx
65         testl   %ecx,%ecx               /* zero carry flag */
66         jz      L(end)
67         pushl   %edx
68         cfi_adjust_cfa_offset (4)
70         ALIGN (3)
71 L(oop): movl    28(%edi),%eax           /* fetch destination cache line */
72         leal    32(%edi),%edi
74 L(1):   movl    (%esi),%eax
75         movl    4(%esi),%edx
76         adcl    %ebp,%eax
77         movl    4(%ebx),%ebp
78         adcl    %ebp,%edx
79         movl    8(%ebx),%ebp
80         movl    %eax,-32(%edi)
81         movl    %edx,-28(%edi)
83 L(2):   movl    8(%esi),%eax
84         movl    12(%esi),%edx
85         adcl    %ebp,%eax
86         movl    12(%ebx),%ebp
87         adcl    %ebp,%edx
88         movl    16(%ebx),%ebp
89         movl    %eax,-24(%edi)
90         movl    %edx,-20(%edi)
92 L(3):   movl    16(%esi),%eax
93         movl    20(%esi),%edx
94         adcl    %ebp,%eax
95         movl    20(%ebx),%ebp
96         adcl    %ebp,%edx
97         movl    24(%ebx),%ebp
98         movl    %eax,-16(%edi)
99         movl    %edx,-12(%edi)
101 L(4):   movl    24(%esi),%eax
102         movl    28(%esi),%edx
103         adcl    %ebp,%eax
104         movl    28(%ebx),%ebp
105         adcl    %ebp,%edx
106         movl    32(%ebx),%ebp
107         movl    %eax,-8(%edi)
108         movl    %edx,-4(%edi)
110         leal    32(%esi),%esi
111         leal    32(%ebx),%ebx
112         decl    %ecx
113         jnz     L(oop)
115         popl    %edx
116         cfi_adjust_cfa_offset (-4)
117 L(end):
118         decl    %edx                    /* test %edx w/o clobbering carry */
119         js      L(end2)
120         incl    %edx
121 L(oop2):
122         leal    4(%edi),%edi
123         movl    (%esi),%eax
124         adcl    %ebp,%eax
125         movl    4(%ebx),%ebp
126         movl    %eax,-4(%edi)
127         leal    4(%esi),%esi
128         leal    4(%ebx),%ebx
129         decl    %edx
130         jnz     L(oop2)
131 L(end2):
132         movl    (%esi),%eax
133         adcl    %ebp,%eax
134         movl    %eax,(%edi)
136         sbbl    %eax,%eax
137         negl    %eax
139         popl    %ebx
140         cfi_adjust_cfa_offset (-4)
141         cfi_restore (ebx)
142         popl    %ebp
143         cfi_adjust_cfa_offset (-4)
144         cfi_restore (ebp)
145         popl    %esi
146         cfi_adjust_cfa_offset (-4)
147         cfi_restore (esi)
148         popl    %edi
149         cfi_adjust_cfa_offset (-4)
150         cfi_restore (edi)
152         LEAVE
153         ret
154 END (BP_SYM (__mpn_add_n))