Debian Codegraph @

mpi/i386/mpih-add1.S

raw
1 /* i80386 add_n -- Add 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_add_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 .text
44 ALIGN (3)
45 .globl C_SYMBOL_NAME(_gcry_mpih_add_n)
46 C_SYMBOL_NAME(_gcry_mpih_add_n:)
47 CFI_STARTPROC()
48 pushl %edi
49 CFI_PUSH(%edi)
50 pushl %esi
51 CFI_PUSH(%esi)
52
53 movl 12(%esp),%edi /* res_ptr */
54 movl 16(%esp),%esi /* s1_ptr */
55 movl 20(%esp),%edx /* s2_ptr */
56 movl 24(%esp),%ecx /* size */
57
58 #if defined __CET__ && (__CET__ & 1) != 0
59 pushl %ebx
60 CFI_PUSH(%ebx)
61 #endif
62
63 movl %ecx,%eax
64 shrl $3,%ecx /* compute count for unrolled loop */
65 negl %eax
66 andl $7,%eax /* get index where to start loop */
67 jz Loop /* necessary special case for 0 */
68 incl %ecx /* adjust loop count */
69 shll $2,%eax /* adjustment for pointers... */
70 subl %eax,%edi /* ... since they are offset ... */
71 subl %eax,%esi /* ... by a constant when we ... */
72 subl %eax,%edx /* ... enter the loop */
73 shrl $2,%eax /* restore previous value */
74 #if defined __CET__ && (__CET__ & 1) != 0
75 leal -4(,%eax,4),%ebx /* Count for 4-byte endbr32 */
76 #endif
77 #ifdef PIC
78 /* Calculate start address in loop for PIC. Due to limitations in some
79 assemblers, Loop-L0-3 cannot be put into the leal */
80 call L0
81 CFI_ADJUST_CFA_OFFSET(4)
82 L0: leal (%eax,%eax,8),%eax
83 addl (%esp),%eax
84 addl $(Loop-L0-3),%eax
85 addl $4,%esp
86 CFI_ADJUST_CFA_OFFSET(-4)
87 #else
88 /* Calculate start address in loop for non-PIC. */
89 leal (Loop - 3)(%eax,%eax,8),%eax
90 #endif
91 #if defined __CET__ && (__CET__ & 1) != 0
92 addl %ebx,%eax /* Adjust for endbr32 */
93 #endif
94 jmp *%eax /* jump into loop */
95 ALIGN (3)
96 Loop: movl (%esi),%eax
97 adcl (%edx),%eax
98 movl %eax,(%edi)
99 #ifdef _CET_ENDBR
100 _CET_ENDBR
101 #endif
102 movl 4(%esi),%eax
103 adcl 4(%edx),%eax
104 movl %eax,4(%edi)
105 #ifdef _CET_ENDBR
106 _CET_ENDBR
107 #endif
108 movl 8(%esi),%eax
109 adcl 8(%edx),%eax
110 movl %eax,8(%edi)
111 #ifdef _CET_ENDBR
112 _CET_ENDBR
113 #endif
114 movl 12(%esi),%eax
115 adcl 12(%edx),%eax
116 movl %eax,12(%edi)
117 #ifdef _CET_ENDBR
118 _CET_ENDBR
119 #endif
120 movl 16(%esi),%eax
121 adcl 16(%edx),%eax
122 movl %eax,16(%edi)
123 #ifdef _CET_ENDBR
124 _CET_ENDBR
125 #endif
126 movl 20(%esi),%eax
127 adcl 20(%edx),%eax
128 movl %eax,20(%edi)
129 #ifdef _CET_ENDBR
130 _CET_ENDBR
131 #endif
132 movl 24(%esi),%eax
133 adcl 24(%edx),%eax
134 movl %eax,24(%edi)
135 #ifdef _CET_ENDBR
136 _CET_ENDBR
137 #endif
138 movl 28(%esi),%eax
139 adcl 28(%edx),%eax
140 movl %eax,28(%edi)
141 leal 32(%edi),%edi
142 leal 32(%esi),%esi
143 leal 32(%edx),%edx
144 decl %ecx
145 jnz Loop
146
147 sbbl %eax,%eax
148 negl %eax
149
150 #if defined __CET__ && (__CET__ & 1) != 0
151 popl %ebx
152 CFI_POP(%ebx)
153 #endif
154
155 popl %esi
156 CFI_POP(%esi)
157 popl %edi
158 CFI_POP(%edi)
159 ret_spec_stop
160 CFI_ENDPROC()
161