~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to mpi/i586/mpih-lshift.S

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* i80586   lshift
 
2
 *
 
3
 *      Copyright (C) 1992, 1994, 1998, 
 
4
 *                    2001 Free Software Foundation, Inc.
 
5
 *
 
6
 * This file is part of GnuPG.
 
7
 *
 
8
 * GnuPG is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * GnuPG is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
21
 *
 
22
 * Note: This code is heavily based on the GNU MP Library.
 
23
 *       Actually it's the same code with only minor changes in the
 
24
 *       way the data is stored; this is to support the abstraction
 
25
 *       of an optional secure memory allocation which may be used
 
26
 *       to avoid revealing of sensitive data due to paging etc.
 
27
 *       The GNU MP Library itself is published under the LGPL;
 
28
 *       however I decided to publish this code under the plain GPL.
 
29
 */
 
30
 
 
31
 
 
32
#include "sysdep.h"
 
33
#include "asm-syntax.h"
 
34
 
 
35
 
 
36
/*******************
 
37
 * mpi_limb_t
 
38
 * mpihelp_lshift( mpi_ptr_t wp,        (sp + 4)
 
39
 *                 mpi_ptr_t up,        (sp + 8)
 
40
 *                 mpi_size_t usize,    (sp + 12)
 
41
 *                 unsigned cnt)        (sp + 16)
 
42
 */
 
43
 
 
44
.text
 
45
        ALIGN (3)
 
46
        .globl C_SYMBOL_NAME(mpihelp_lshift)
 
47
C_SYMBOL_NAME(mpihelp_lshift:)
 
48
 
 
49
        pushl   %edi
 
50
        pushl   %esi
 
51
        pushl   %ebx
 
52
        pushl   %ebp
 
53
 
 
54
        movl    20(%esp),%edi           /* res_ptr */
 
55
        movl    24(%esp),%esi           /* s_ptr */
 
56
        movl    28(%esp),%ebp           /* size */
 
57
        movl    32(%esp),%ecx           /* cnt */
 
58
 
 
59
/* We can use faster code for shift-by-1 under certain conditions.  */
 
60
        cmp     $1,%ecx
 
61
        jne     Lnormal
 
62
        leal    4(%esi),%eax
 
63
        cmpl    %edi,%eax
 
64
        jnc     Lspecial                /* jump if s_ptr + 1 >= res_ptr */
 
65
        leal    (%esi,%ebp,4),%eax
 
66
        cmpl    %eax,%edi
 
67
        jnc     Lspecial                /* jump if res_ptr >= s_ptr + size */
 
68
 
 
69
Lnormal:
 
70
        leal    -4(%edi,%ebp,4),%edi
 
71
        leal    -4(%esi,%ebp,4),%esi
 
72
 
 
73
        movl    (%esi),%edx
 
74
        subl    $4,%esi
 
75
        xorl    %eax,%eax
 
76
        shldl   %cl,%edx,%eax           /* compute carry limb */
 
77
        pushl   %eax                    /* push carry limb onto stack */
 
78
 
 
79
        decl    %ebp
 
80
        pushl   %ebp
 
81
        shrl    $3,%ebp
 
82
        jz      Lend
 
83
 
 
84
        movl    (%edi),%eax             /* fetch destination cache line */
 
85
 
 
86
        ALIGN   (2)
 
87
Loop:   movl    -28(%edi),%eax          /* fetch destination cache line */
 
88
        movl    %edx,%ebx
 
89
 
 
90
        movl    (%esi),%eax
 
91
        movl    -4(%esi),%edx
 
92
        shldl   %cl,%eax,%ebx
 
93
        shldl   %cl,%edx,%eax
 
94
        movl    %ebx,(%edi)
 
95
        movl    %eax,-4(%edi)
 
96
 
 
97
        movl    -8(%esi),%ebx
 
98
        movl    -12(%esi),%eax
 
99
        shldl   %cl,%ebx,%edx
 
100
        shldl   %cl,%eax,%ebx
 
101
        movl    %edx,-8(%edi)
 
102
        movl    %ebx,-12(%edi)
 
103
 
 
104
        movl    -16(%esi),%edx
 
105
        movl    -20(%esi),%ebx
 
106
        shldl   %cl,%edx,%eax
 
107
        shldl   %cl,%ebx,%edx
 
108
        movl    %eax,-16(%edi)
 
109
        movl    %edx,-20(%edi)
 
110
 
 
111
        movl    -24(%esi),%eax
 
112
        movl    -28(%esi),%edx
 
113
        shldl   %cl,%eax,%ebx
 
114
        shldl   %cl,%edx,%eax
 
115
        movl    %ebx,-24(%edi)
 
116
        movl    %eax,-28(%edi)
 
117
 
 
118
        subl    $32,%esi
 
119
        subl    $32,%edi
 
120
        decl    %ebp
 
121
        jnz     Loop
 
122
 
 
123
Lend:   popl    %ebp
 
124
        andl    $7,%ebp
 
125
        jz      Lend2
 
126
Loop2:  movl    (%esi),%eax
 
127
        shldl   %cl,%eax,%edx
 
128
        movl    %edx,(%edi)
 
129
        movl    %eax,%edx
 
130
        subl    $4,%esi
 
131
        subl    $4,%edi
 
132
        decl    %ebp
 
133
        jnz     Loop2
 
134
 
 
135
Lend2:  shll    %cl,%edx                /* compute least significant limb */
 
136
        movl    %edx,(%edi)             /* store it */
 
137
 
 
138
        popl    %eax                    /* pop carry limb */
 
139
 
 
140
        popl    %ebp
 
141
        popl    %ebx
 
142
        popl    %esi
 
143
        popl    %edi
 
144
        ret
 
145
 
 
146
/* We loop from least significant end of the arrays, which is only
 
147
   permissable if the source and destination don't overlap, since the
 
148
   function is documented to work for overlapping source and destination.
 
149
*/
 
150
 
 
151
Lspecial:
 
152
        movl    (%esi),%edx
 
153
        addl    $4,%esi
 
154
 
 
155
        decl    %ebp
 
156
        pushl   %ebp
 
157
        shrl    $3,%ebp
 
158
 
 
159
        addl    %edx,%edx
 
160
        incl    %ebp
 
161
        decl    %ebp
 
162
        jz      LLend
 
163
 
 
164
        movl    (%edi),%eax             /* fetch destination cache line */
 
165
 
 
166
        ALIGN   (2)
 
167
LLoop:  movl    28(%edi),%eax           /* fetch destination cache line */
 
168
        movl    %edx,%ebx
 
169
 
 
170
        movl    (%esi),%eax
 
171
        movl    4(%esi),%edx
 
172
        adcl    %eax,%eax
 
173
        movl    %ebx,(%edi)
 
174
        adcl    %edx,%edx
 
175
        movl    %eax,4(%edi)
 
176
 
 
177
        movl    8(%esi),%ebx
 
178
        movl    12(%esi),%eax
 
179
        adcl    %ebx,%ebx
 
180
        movl    %edx,8(%edi)
 
181
        adcl    %eax,%eax
 
182
        movl    %ebx,12(%edi)
 
183
 
 
184
        movl    16(%esi),%edx
 
185
        movl    20(%esi),%ebx
 
186
        adcl    %edx,%edx
 
187
        movl    %eax,16(%edi)
 
188
        adcl    %ebx,%ebx
 
189
        movl    %edx,20(%edi)
 
190
 
 
191
        movl    24(%esi),%eax
 
192
        movl    28(%esi),%edx
 
193
        adcl    %eax,%eax
 
194
        movl    %ebx,24(%edi)
 
195
        adcl    %edx,%edx
 
196
        movl    %eax,28(%edi)
 
197
 
 
198
        leal    32(%esi),%esi           /* use leal not to clobber carry */
 
199
        leal    32(%edi),%edi
 
200
        decl    %ebp
 
201
        jnz     LLoop
 
202
 
 
203
LLend:  popl    %ebp
 
204
        sbbl    %eax,%eax               /* save carry in %eax */
 
205
        andl    $7,%ebp
 
206
        jz      LLend2
 
207
        addl    %eax,%eax               /* restore carry from eax */
 
208
LLoop2: movl    %edx,%ebx
 
209
        movl    (%esi),%edx
 
210
        adcl    %edx,%edx
 
211
        movl    %ebx,(%edi)
 
212
 
 
213
        leal    4(%esi),%esi            /* use leal not to clobber carry */
 
214
        leal    4(%edi),%edi
 
215
        decl    %ebp
 
216
        jnz     LLoop2
 
217
 
 
218
        jmp     LL1
 
219
LLend2: addl    %eax,%eax               /* restore carry from eax */
 
220
LL1:    movl    %edx,(%edi)             /* store last limb */
 
221
 
 
222
        sbbl    %eax,%eax
 
223
        negl    %eax
 
224
 
 
225
        popl    %ebp
 
226
        popl    %ebx
 
227
        popl    %esi
 
228
        popl    %edi
 
229
        ret
 
230
 
 
231