Update.
[glibc.git] / sysdeps / i386 / add_n.S
bloba68fe2ed39e001cc7581183d9a1cfc09260afc89
1 /* Add two limb vectors of the same length > 0 and store sum in a third
2    limb vector.
3    Copyright (C) 1992, 1994, 1995, 1997 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 Library General Public License as published by
8    the Free Software Foundation; either version 2 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 Library General Public
14    License for more details.
16    You should have received a copy of the GNU Library 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. */
22   INPUT PARAMETERS
23   res_ptr       (sp + 4)
24   s1_ptr        (sp + 8)
25   s2_ptr        (sp + 12)
26   size          (sp + 16)
29 #include "sysdep.h"
30 #include "asm-syntax.h"
32 .text
33         ALIGN (3)
34         .globl C_SYMBOL_NAME(__mpn_add_n)
35 C_SYMBOL_NAME(__mpn_add_n:)
36         pushl %edi
37         pushl %esi
39         movl 12(%esp),%edi              /* res_ptr */
40         movl 16(%esp),%esi              /* s1_ptr */
41         movl 20(%esp),%edx              /* s2_ptr */
42         movl 24(%esp),%ecx              /* size */
44         movl    %ecx,%eax
45         shrl    $3,%ecx                 /* compute count for unrolled loop */
46         negl    %eax
47         andl    $7,%eax                 /* get index where to start loop */
48         jz      L(oop)                  /* necessary special case for 0 */
49         incl    %ecx                    /* adjust loop count */
50         shll    $2,%eax                 /* adjustment for pointers... */
51         subl    %eax,%edi               /* ... since they are offset ... */
52         subl    %eax,%esi               /* ... by a constant when we ... */
53         subl    %eax,%edx               /* ... enter the loop */
54         shrl    $2,%eax                 /* restore previous value */
55 #ifdef PIC
56 /* Calculate start address in loop for PIC.  Due to limitations in some
57    assemblers, Loop-L0-3 cannot be put into the leal */
58         call    L(0)
59 L(0):   leal    (%eax,%eax,8),%eax
60         addl    (%esp),%eax
61         addl    $(L(oop)-L(0)-3),%eax
62         addl    $4,%esp
63 #else
64 /* Calculate start address in loop for non-PIC.  */
65         leal    (L(oop) - 3)(%eax,%eax,8),%eax
66 #endif
67         jmp     *%eax                   /* jump into loop */
68         ALIGN (3)
69 L(oop): movl    (%esi),%eax
70         adcl    (%edx),%eax
71         movl    %eax,(%edi)
72         movl    4(%esi),%eax
73         adcl    4(%edx),%eax
74         movl    %eax,4(%edi)
75         movl    8(%esi),%eax
76         adcl    8(%edx),%eax
77         movl    %eax,8(%edi)
78         movl    12(%esi),%eax
79         adcl    12(%edx),%eax
80         movl    %eax,12(%edi)
81         movl    16(%esi),%eax
82         adcl    16(%edx),%eax
83         movl    %eax,16(%edi)
84         movl    20(%esi),%eax
85         adcl    20(%edx),%eax
86         movl    %eax,20(%edi)
87         movl    24(%esi),%eax
88         adcl    24(%edx),%eax
89         movl    %eax,24(%edi)
90         movl    28(%esi),%eax
91         adcl    28(%edx),%eax
92         movl    %eax,28(%edi)
93         leal    32(%edi),%edi
94         leal    32(%esi),%esi
95         leal    32(%edx),%edx
96         decl    %ecx
97         jnz     L(oop)
99         sbbl    %eax,%eax
100         negl    %eax
102         popl %esi
103         popl %edi
104         ret