2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / i586 / add_n.S
blob57706b23b457b602f226b2bbf8da9b30206197be
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,94,95,96,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, write to
18    the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19    MA 02111-1307, USA. */
21 #include "sysdep.h"
22 #include "asm-syntax.h"
23 #include "bp-sym.h"
24 #include "bp-asm.h"
26 #define PARMS   LINKAGE+16              /* space for 4 saved regs */
27 #define RES     PARMS
28 #define S1      RES+PTR_SIZE
29 #define S2      S1+PTR_SIZE
30 #define SIZE    S2+PTR_SIZE
32         .text
33 ENTRY (BP_SYM (__mpn_add_n))
34         ENTER
36         pushl   %edi
37         cfi_adjust_cfa_offset (4)
38         pushl   %esi
39         cfi_adjust_cfa_offset (4)
40         pushl   %ebp
41         cfi_adjust_cfa_offset (4)
42         pushl   %ebx
43         cfi_adjust_cfa_offset (4)
45         movl    RES(%esp),%edi
46         cfi_rel_offset (edi, 12)
47         movl    S1(%esp),%esi
48         cfi_rel_offset (esi, 8)
49         movl    S2(%esp),%ebx
50         cfi_rel_offset (ebx, 0)
51         movl    SIZE(%esp),%ecx
52 #if __BOUNDED_POINTERS__
53         shll    $2, %ecx                /* convert limbs to bytes */
54         CHECK_BOUNDS_BOTH_WIDE (%edi, RES(%esp), %ecx)
55         CHECK_BOUNDS_BOTH_WIDE (%esi, S1(%esp), %ecx)
56         CHECK_BOUNDS_BOTH_WIDE (%ebx, S2(%esp), %ecx)
57         shrl    $2, %ecx
58 #endif
59         movl    (%ebx),%ebp
60         cfi_rel_offset (ebp, 4)
62         decl    %ecx
63         movl    %ecx,%edx
64         shrl    $3,%ecx
65         andl    $7,%edx
66         testl   %ecx,%ecx               /* zero carry flag */
67         jz      L(end)
68         pushl   %edx
69         cfi_adjust_cfa_offset (4)
71         ALIGN (3)
72 L(oop): movl    28(%edi),%eax           /* fetch destination cache line */
73         leal    32(%edi),%edi
75 L(1):   movl    (%esi),%eax
76         movl    4(%esi),%edx
77         adcl    %ebp,%eax
78         movl    4(%ebx),%ebp
79         adcl    %ebp,%edx
80         movl    8(%ebx),%ebp
81         movl    %eax,-32(%edi)
82         movl    %edx,-28(%edi)
84 L(2):   movl    8(%esi),%eax
85         movl    12(%esi),%edx
86         adcl    %ebp,%eax
87         movl    12(%ebx),%ebp
88         adcl    %ebp,%edx
89         movl    16(%ebx),%ebp
90         movl    %eax,-24(%edi)
91         movl    %edx,-20(%edi)
93 L(3):   movl    16(%esi),%eax
94         movl    20(%esi),%edx
95         adcl    %ebp,%eax
96         movl    20(%ebx),%ebp
97         adcl    %ebp,%edx
98         movl    24(%ebx),%ebp
99         movl    %eax,-16(%edi)
100         movl    %edx,-12(%edi)
102 L(4):   movl    24(%esi),%eax
103         movl    28(%esi),%edx
104         adcl    %ebp,%eax
105         movl    28(%ebx),%ebp
106         adcl    %ebp,%edx
107         movl    32(%ebx),%ebp
108         movl    %eax,-8(%edi)
109         movl    %edx,-4(%edi)
111         leal    32(%esi),%esi
112         leal    32(%ebx),%ebx
113         decl    %ecx
114         jnz     L(oop)
116         popl    %edx
117         cfi_adjust_cfa_offset (-4)
118 L(end):
119         decl    %edx                    /* test %edx w/o clobbering carry */
120         js      L(end2)
121         incl    %edx
122 L(oop2):
123         leal    4(%edi),%edi
124         movl    (%esi),%eax
125         adcl    %ebp,%eax
126         movl    4(%ebx),%ebp
127         movl    %eax,-4(%edi)
128         leal    4(%esi),%esi
129         leal    4(%ebx),%ebx
130         decl    %edx
131         jnz     L(oop2)
132 L(end2):
133         movl    (%esi),%eax
134         adcl    %ebp,%eax
135         movl    %eax,(%edi)
137         sbbl    %eax,%eax
138         negl    %eax
140         popl    %ebx
141         cfi_adjust_cfa_offset (-4)
142         cfi_restore (ebx)
143         popl    %ebp
144         cfi_adjust_cfa_offset (-4)
145         cfi_restore (ebp)
146         popl    %esi
147         cfi_adjust_cfa_offset (-4)
148         cfi_restore (esi)
149         popl    %edi
150         cfi_adjust_cfa_offset (-4)
151         cfi_restore (edi)
153         LEAVE
154         ret
155 END (BP_SYM (__mpn_add_n))