Debian Codegraph @

mpi/i386/mpih-sub1.S

raw
1 /* i80386 sub_n -- Sub two limb vectors of the same length > 0 and store
2 * sum in a third limb vector.
3 *
4 * Copyright (C) 1992, 1994, 1995, 1998,
5 * 2001, 2002 Free Software Foundation, Inc.
6 *
7 * This file is part of Libgcrypt.
8 *
9 * Libgcrypt is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * Libgcrypt is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, see <https://www.gnu.org/licenses/>.
21 * SPDX-License-Identifier: LGPL-2.1-or-later
22 *
23 * Note: This code is heavily based on the GNU MP Library.
24 * Actually it's the same code with only minor changes in the
25 * way the data is stored; this is to support the abstraction
26 * of an optional secure memory allocation which may be used
27 * to avoid revealing of sensitive data due to paging etc.
28 */
29
30
31 #include "sysdep.h"
32 #include "asm-syntax.h"
33
34
35 /*******************
36 * mpi_limb_t
37 * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (sp + 4)
38 * mpi_ptr_t s1_ptr, (sp + 8)
39 * mpi_ptr_t s2_ptr, (sp + 12)
40 * mpi_size_t size) (sp + 16)
41 */
42
43
44 .text
45 ALIGN (3)
46 .globl C_SYMBOL_NAME(_gcry_mpih_sub_n)
47 C_SYMBOL_NAME(_gcry_mpih_sub_n:)
48 CFI_STARTPROC()
49 pushl %edi
50 CFI_PUSH(%edi)
51 pushl %esi
52 CFI_PUSH(%esi)
53
54 movl 12(%esp),%edi /* res_ptr */
55 movl 16(%esp),%esi /* s1_ptr */
56 movl 20(%esp),%edx /* s2_ptr */
57 movl 24(%esp),%ecx /* size */
58
59 #if defined __CET__ && (__CET__ & 1) != 0
60 pushl %ebx
61 CFI_PUSH(%ebx)
62 #endif
63
64 movl %ecx,%eax
65 shrl $3,%ecx /* compute count for unrolled loop */
66 negl %eax
67 andl $7,%eax /* get index where to start loop */
68 jz Loop /* necessary special case for 0 */
69 incl %ecx /* adjust loop count */
70 shll $2,%eax /* adjustment for pointers... */
71 subl %eax,%edi /* ... since they are offset ... */
72 subl %eax,%esi /* ... by a constant when we ... */
73 subl %eax,%edx /* ... enter the loop */
74 shrl $2,%eax /* restore previous value */
75 #if defined __CET__ && (__CET__ & 1) != 0
76 leal -4(,%eax,4),%ebx /* Count for 4-byte endbr32 */
77 #endif
78 #ifdef PIC
79 /* Calculate start address in loop for PIC. Due to limitations in some
80 assemblers, Loop-L0-3 cannot be put into the leal */
81 call L0
82 CFI_ADJUST_CFA_OFFSET(4)
83 L0: leal (%eax,%eax,8),%eax
84 addl (%esp),%eax
85 addl $(Loop-L0-3),%eax
86 addl $4,%esp
87 CFI_ADJUST_CFA_OFFSET(-4)
88 #else
89 /* Calculate start address in loop for non-PIC. */
90 leal (Loop - 3)(%eax,%eax,8),%eax
91 #endif
92 #if defined __CET__ && (__CET__ & 1) != 0
93 addl %ebx,%eax /* Adjust for endbr32 */
94 #endif
95 jmp *%eax /* jump into loop */
96 ALIGN (3)
97 Loop: movl (%esi),%eax
98 sbbl (%edx),%eax
99 movl %eax,(%edi)
100 #ifdef _CET_ENDBR
101 _CET_ENDBR
102 #endif
103 movl 4(%esi),%eax
104 sbbl 4(%edx),%eax
105 movl %eax,4(%edi)
106 #ifdef _CET_ENDBR
107 _CET_ENDBR
108 #endif
109 movl 8(%esi),%eax
110 sbbl 8(%edx),%eax
111 movl %eax,8(%edi)
112 #ifdef _CET_ENDBR
113 _CET_ENDBR
114 #endif
115 movl 12(%esi),%eax
116 sbbl 12(%edx),%eax
117 movl %eax,12(%edi)
118 #ifdef _CET_ENDBR
119 _CET_ENDBR
120 #endif
121 movl 16(%esi),%eax
122 sbbl 16(%edx),%eax
123 movl %eax,16(%edi)
124 #ifdef _CET_ENDBR
125 _CET_ENDBR
126 #endif
127 movl 20(%esi),%eax
128 sbbl 20(%edx),%eax
129 movl %eax,20(%edi)
130 #ifdef _CET_ENDBR
131 _CET_ENDBR
132 #endif
133 movl 24(%esi),%eax
134 sbbl 24(%edx),%eax
135 movl %eax,24(%edi)
136 #ifdef _CET_ENDBR
137 _CET_ENDBR
138 #endif
139 movl 28(%esi),%eax
140 sbbl 28(%edx),%eax
141 movl %eax,28(%edi)
142 leal 32(%edi),%edi
143 leal 32(%esi),%esi
144 leal 32(%edx),%edx
145 decl %ecx
146 jnz Loop
147
148 sbbl %eax,%eax
149 negl %eax
150
151 #if defined __CET__ && (__CET__ & 1) != 0
152 popl %ebx
153 CFI_POP(%ebx)
154 #endif
155
156 popl %esi
157 CFI_POP(%esi)
158 popl %edi
159 CFI_POP(%edi)
160 ret_spec_stop
161 CFI_ENDPROC()
162