Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libgmp / mpn / x86 / pentium / sub_n.S
1 /* Pentium __mpn_sub_n -- Subtract two limb vectors of the same length > 0
2    and store difference in a third limb vector.
3
4 Copyright (C) 1992, 1994, 1995, 1996 Free Software Foundation, Inc.
5
6 This file is part of the GNU MP Library.
7
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
12
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
16 License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
22
23 /*
24    INPUT PARAMETERS
25    res_ptr      (sp + 4)
26    s1_ptr       (sp + 8)
27    s2_ptr       (sp + 12)
28    size         (sp + 16)
29 */
30
31 #include "sysdep.h"
32 #include "asm-syntax.h"
33
34 .text
35         ALIGN (3)
36         .globl C_SYMBOL_NAME(__mpn_sub_n)
37 C_SYMBOL_NAME(__mpn_sub_n:)
38         pushl   %edi
39         pushl   %esi
40         pushl   %ebx
41         pushl   %ebp
42
43         movl    20(%esp),%edi           /* res_ptr */
44         movl    24(%esp),%esi           /* s1_ptr */
45         movl    28(%esp),%ebp           /* s2_ptr */
46         movl    32(%esp),%ecx           /* size */
47
48         movl    (%ebp),%ebx
49
50         decl    %ecx
51         movl    %ecx,%edx
52         shrl    $3,%ecx
53         andl    $7,%edx
54         testl   %ecx,%ecx               /* zero carry flag */
55         jz      Lend
56         pushl   %edx
57
58         ALIGN (3)
59 Loop:   movl    28(%edi),%eax           /* fetch destination cache line */
60         leal    32(%edi),%edi
61
62 L1:     movl    (%esi),%eax
63         movl    4(%esi),%edx
64         sbbl    %ebx,%eax
65         movl    4(%ebp),%ebx
66         sbbl    %ebx,%edx
67         movl    8(%ebp),%ebx
68         movl    %eax,-32(%edi)
69         movl    %edx,-28(%edi)
70
71 L2:     movl    8(%esi),%eax
72         movl    12(%esi),%edx
73         sbbl    %ebx,%eax
74         movl    12(%ebp),%ebx
75         sbbl    %ebx,%edx
76         movl    16(%ebp),%ebx
77         movl    %eax,-24(%edi)
78         movl    %edx,-20(%edi)
79
80 L3:     movl    16(%esi),%eax
81         movl    20(%esi),%edx
82         sbbl    %ebx,%eax
83         movl    20(%ebp),%ebx
84         sbbl    %ebx,%edx
85         movl    24(%ebp),%ebx
86         movl    %eax,-16(%edi)
87         movl    %edx,-12(%edi)
88
89 L4:     movl    24(%esi),%eax
90         movl    28(%esi),%edx
91         sbbl    %ebx,%eax
92         movl    28(%ebp),%ebx
93         sbbl    %ebx,%edx
94         movl    32(%ebp),%ebx
95         movl    %eax,-8(%edi)
96         movl    %edx,-4(%edi)
97
98         leal    32(%esi),%esi
99         leal    32(%ebp),%ebp
100         decl    %ecx
101         jnz     Loop
102
103         popl    %edx
104 Lend:
105         decl    %edx                    /* test %edx w/o clobbering carry */
106         js      Lend2
107         incl    %edx
108 Loop2:
109         leal    4(%edi),%edi
110         movl    (%esi),%eax
111         sbbl    %ebx,%eax
112         movl    4(%ebp),%ebx
113         movl    %eax,-4(%edi)
114         leal    4(%esi),%esi
115         leal    4(%ebp),%ebp
116         decl    %edx
117         jnz     Loop2
118 Lend2:
119         movl    (%esi),%eax
120         sbbl    %ebx,%eax
121         movl    %eax,(%edi)
122
123         sbbl    %eax,%eax
124         negl    %eax
125
126         popl    %ebp
127         popl    %ebx
128         popl    %esi
129         popl    %edi
130         ret