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

« back to all changes in this revision

Viewing changes to mpi/i586/mpih-shift.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   rshift, lshift
 
2
 *      Copyright (C) 1998 Free Software Foundation, Inc.
 
3
 *      Copyright (C) 1992, 1994 Free Software Foundation, Inc.
 
4
 *
 
5
 * This file is part of GNUPG.
 
6
 *
 
7
 * GNUPG is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * GNUPG is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
20
 *
 
21
 * Note: This code is heavily based on the GNU MP Library.
 
22
 *       Actually it's the same code with only minor changes in the
 
23
 *       way the data is stored; this is to support the abstraction
 
24
 *       of an optional secure memory allocation which may be used
 
25
 *       to avoid revealing of sensitive data due to paging etc.
 
26
 *       The GNU MP Library itself is published under the LGPL;
 
27
 *       however I decided to publish this code under the plain GPL.
 
28
 */
 
29
 
 
30
 
 
31
#include "sysdep.h"
 
32
#include "asm-syntax.h"
 
33
 
 
34
 
 
35
/*******************
 
36
 * mpi_limb_t
 
37
 * mpihelp_lshift( mpi_ptr_t wp,        (sp + 4)
 
38
 *                 mpi_ptr_t up,        (sp + 8)
 
39
 *                 mpi_size_t usize,    (sp + 12)
 
40
 *                 unsigned cnt)        (sp + 16)
 
41
 */
 
42
 
 
43
.text
 
44
        ALIGN (3)
 
45
        .globl C_SYMBOL_NAME(mpihelp_lshift)
 
46
C_SYMBOL_NAME(mpihelp_lshift:)
 
47
 
 
48
        pushl   %edi
 
49
        pushl   %esi
 
50
        pushl   %ebx
 
51
        pushl   %ebp
 
52
 
 
53
        movl    20(%esp),%edi           /* res_ptr */
 
54
        movl    24(%esp),%esi           /* s_ptr */
 
55
        movl    28(%esp),%ebp           /* size */
 
56
        movl    32(%esp),%ecx           /* cnt */
 
57
 
 
58
/* We can use faster code for shift-by-1 under certain conditions.  */
 
59
        cmp     $1,%ecx
 
60
        jne     Lnormal
 
61
        leal    4(%esi),%eax
 
62
        cmpl    %edi,%eax
 
63
        jnc     Lspecial                /* jump if s_ptr + 1 >= res_ptr */
 
64
        leal    (%esi,%ebp,4),%eax
 
65
        cmpl    %eax,%edi
 
66
        jnc     Lspecial                /* jump if res_ptr >= s_ptr + size */
 
67
 
 
68
Lnormal:
 
69
        leal    -4(%edi,%ebp,4),%edi
 
70
        leal    -4(%esi,%ebp,4),%esi
 
71
 
 
72
        movl    (%esi),%edx
 
73
        subl    $4,%esi
 
74
        xorl    %eax,%eax
 
75
        shldl   %cl,%edx,%eax           /* compute carry limb */
 
76
        pushl   %eax                    /* push carry limb onto stack */
 
77
 
 
78
        decl    %ebp
 
79
        pushl   %ebp
 
80
        shrl    $3,%ebp
 
81
        jz      Lend
 
82
 
 
83
        movl    (%edi),%eax             /* fetch destination cache line */
 
84
 
 
85
        ALIGN   (2)
 
86
Loop:   movl    -28(%edi),%eax          /* fetch destination cache line */
 
87
        movl    %edx,%ebx
 
88
 
 
89
        movl    (%esi),%eax
 
90
        movl    -4(%esi),%edx
 
91
        shldl   %cl,%eax,%ebx
 
92
        shldl   %cl,%edx,%eax
 
93
        movl    %ebx,(%edi)
 
94
        movl    %eax,-4(%edi)
 
95
 
 
96
        movl    -8(%esi),%ebx
 
97
        movl    -12(%esi),%eax
 
98
        shldl   %cl,%ebx,%edx
 
99
        shldl   %cl,%eax,%ebx
 
100
        movl    %edx,-8(%edi)
 
101
        movl    %ebx,-12(%edi)
 
102
 
 
103
        movl    -16(%esi),%edx
 
104
        movl    -20(%esi),%ebx
 
105
        shldl   %cl,%edx,%eax
 
106
        shldl   %cl,%ebx,%edx
 
107
        movl    %eax,-16(%edi)
 
108
        movl    %edx,-20(%edi)
 
109
 
 
110
        movl    -24(%esi),%eax
 
111
        movl    -28(%esi),%edx
 
112
        shldl   %cl,%eax,%ebx
 
113
        shldl   %cl,%edx,%eax
 
114
        movl    %ebx,-24(%edi)
 
115
        movl    %eax,-28(%edi)
 
116
 
 
117
        subl    $32,%esi
 
118
        subl    $32,%edi
 
119
        decl    %ebp
 
120
        jnz     Loop
 
121
 
 
122
Lend:   popl    %ebp
 
123
        andl    $7,%ebp
 
124
        jz      Lend2
 
125
Loop2:  movl    (%esi),%eax
 
126
        shldl   %cl,%eax,%edx
 
127
        movl    %edx,(%edi)
 
128
        movl    %eax,%edx
 
129
        subl    $4,%esi
 
130
        subl    $4,%edi
 
131
        decl    %ebp
 
132
        jnz     Loop2
 
133
 
 
134
Lend2:  shll    %cl,%edx                /* compute least significant limb */
 
135
        movl    %edx,(%edi)             /* store it */
 
136
 
 
137
        popl    %eax                    /* pop carry limb */
 
138
 
 
139
        popl    %ebp
 
140
        popl    %ebx
 
141
        popl    %esi
 
142
        popl    %edi
 
143
        ret
 
144
 
 
145
/* We loop from least significant end of the arrays, which is only
 
146
   permissable if the source and destination don't overlap, since the
 
147
   function is documented to work for overlapping source and destination.
 
148
*/
 
149
 
 
150
Lspecial:
 
151
        movl    (%esi),%edx
 
152
        addl    $4,%esi
 
153
 
 
154
        decl    %ebp
 
155
        pushl   %ebp
 
156
        shrl    $3,%ebp
 
157
 
 
158
        addl    %edx,%edx
 
159
        incl    %ebp
 
160
        decl    %ebp
 
161
        jz      LLend
 
162
 
 
163
        movl    (%edi),%eax             /* fetch destination cache line */
 
164
 
 
165
        ALIGN   (2)
 
166
LLoop:  movl    28(%edi),%eax           /* fetch destination cache line */
 
167
        movl    %edx,%ebx
 
168
 
 
169
        movl    (%esi),%eax
 
170
        movl    4(%esi),%edx
 
171
        adcl    %eax,%eax
 
172
        movl    %ebx,(%edi)
 
173
        adcl    %edx,%edx
 
174
        movl    %eax,4(%edi)
 
175
 
 
176
        movl    8(%esi),%ebx
 
177
        movl    12(%esi),%eax
 
178
        adcl    %ebx,%ebx
 
179
        movl    %edx,8(%edi)
 
180
        adcl    %eax,%eax
 
181
        movl    %ebx,12(%edi)
 
182
 
 
183
        movl    16(%esi),%edx
 
184
        movl    20(%esi),%ebx
 
185
        adcl    %edx,%edx
 
186
        movl    %eax,16(%edi)
 
187
        adcl    %ebx,%ebx
 
188
        movl    %edx,20(%edi)
 
189
 
 
190
        movl    24(%esi),%eax
 
191
        movl    28(%esi),%edx
 
192
        adcl    %eax,%eax
 
193
        movl    %ebx,24(%edi)
 
194
        adcl    %edx,%edx
 
195
        movl    %eax,28(%edi)
 
196
 
 
197
        leal    32(%esi),%esi           /* use leal not to clobber carry */
 
198
        leal    32(%edi),%edi
 
199
        decl    %ebp
 
200
        jnz     LLoop
 
201
 
 
202
LLend:  popl    %ebp
 
203
        sbbl    %eax,%eax               /* save carry in %eax */
 
204
        andl    $7,%ebp
 
205
        jz      LLend2
 
206
        addl    %eax,%eax               /* restore carry from eax */
 
207
LLoop2: movl    %edx,%ebx
 
208
        movl    (%esi),%edx
 
209
        adcl    %edx,%edx
 
210
        movl    %ebx,(%edi)
 
211
 
 
212
        leal    4(%esi),%esi            /* use leal not to clobber carry */
 
213
        leal    4(%edi),%edi
 
214
        decl    %ebp
 
215
        jnz     LLoop2
 
216
 
 
217
        jmp     LL1
 
218
LLend2: addl    %eax,%eax               /* restore carry from eax */
 
219
LL1:    movl    %edx,(%edi)             /* store last limb */
 
220
 
 
221
        sbbl    %eax,%eax
 
222
        negl    %eax
 
223
 
 
224
        popl    %ebp
 
225
        popl    %ebx
 
226
        popl    %esi
 
227
        popl    %edi
 
228
        ret
 
229
 
 
230
 
 
231
 
 
232
 
 
233
/*******************
 
234
 * mpi_limb_t
 
235
 * mpihelp_rshift( mpi_ptr_t wp,        (sp + 4)
 
236
 *                 mpi_ptr_t up,        (sp + 8)
 
237
 *                 mpi_size_t usize,    (sp + 12)
 
238
 *                 unsigned cnt)        (sp + 16)
 
239
 */
 
240
 
 
241
.text
 
242
        ALIGN (3)
 
243
        .globl C_SYMBOL_NAME(mpihelp_rshift)
 
244
C_SYMBOL_NAME(mpihelp_rshift:)
 
245
        pushl   %edi
 
246
        pushl   %esi
 
247
        pushl   %ebx
 
248
        pushl   %ebp
 
249
 
 
250
        movl    20(%esp),%edi           /* res_ptr */
 
251
        movl    24(%esp),%esi           /* s_ptr */
 
252
        movl    28(%esp),%ebp           /* size */
 
253
        movl    32(%esp),%ecx           /* cnt */
 
254
 
 
255
/* We can use faster code for shift-by-1 under certain conditions.  */
 
256
        cmp     $1,%ecx
 
257
        jne     Rnormal
 
258
        leal    4(%edi),%eax
 
259
        cmpl    %esi,%eax
 
260
        jnc     Rspecial                /* jump if res_ptr + 1 >= s_ptr */
 
261
        leal    (%edi,%ebp,4),%eax
 
262
        cmpl    %eax,%esi
 
263
        jnc     Rspecial                /* jump if s_ptr >= res_ptr + size */
 
264
 
 
265
Rnormal:
 
266
        movl    (%esi),%edx
 
267
        addl    $4,%esi
 
268
        xorl    %eax,%eax
 
269
        shrdl   %cl,%edx,%eax           /* compute carry limb */
 
270
        pushl   %eax                    /* push carry limb onto stack */
 
271
 
 
272
        decl    %ebp
 
273
        pushl   %ebp
 
274
        shrl    $3,%ebp
 
275
        jz      Rend
 
276
 
 
277
        movl    (%edi),%eax             /* fetch destination cache line */
 
278
 
 
279
        ALIGN   (2)
 
280
Roop:   movl    28(%edi),%eax           /* fetch destination cache line */
 
281
        movl    %edx,%ebx
 
282
 
 
283
        movl    (%esi),%eax
 
284
        movl    4(%esi),%edx
 
285
        shrdl   %cl,%eax,%ebx
 
286
        shrdl   %cl,%edx,%eax
 
287
        movl    %ebx,(%edi)
 
288
        movl    %eax,4(%edi)
 
289
 
 
290
        movl    8(%esi),%ebx
 
291
        movl    12(%esi),%eax
 
292
        shrdl   %cl,%ebx,%edx
 
293
        shrdl   %cl,%eax,%ebx
 
294
        movl    %edx,8(%edi)
 
295
        movl    %ebx,12(%edi)
 
296
 
 
297
        movl    16(%esi),%edx
 
298
        movl    20(%esi),%ebx
 
299
        shrdl   %cl,%edx,%eax
 
300
        shrdl   %cl,%ebx,%edx
 
301
        movl    %eax,16(%edi)
 
302
        movl    %edx,20(%edi)
 
303
 
 
304
        movl    24(%esi),%eax
 
305
        movl    28(%esi),%edx
 
306
        shrdl   %cl,%eax,%ebx
 
307
        shrdl   %cl,%edx,%eax
 
308
        movl    %ebx,24(%edi)
 
309
        movl    %eax,28(%edi)
 
310
 
 
311
        addl    $32,%esi
 
312
        addl    $32,%edi
 
313
        decl    %ebp
 
314
        jnz     Roop
 
315
 
 
316
Rend:   popl    %ebp
 
317
        andl    $7,%ebp
 
318
        jz      Rend2
 
319
Roop2:  movl    (%esi),%eax
 
320
        shrdl   %cl,%eax,%edx           /* compute result limb */
 
321
        movl    %edx,(%edi)
 
322
        movl    %eax,%edx
 
323
        addl    $4,%esi
 
324
        addl    $4,%edi
 
325
        decl    %ebp
 
326
        jnz     Roop2
 
327
 
 
328
Rend2:  shrl    %cl,%edx                /* compute most significant limb */
 
329
        movl    %edx,(%edi)             /* store it */
 
330
 
 
331
        popl    %eax                    /* pop carry limb */
 
332
 
 
333
        popl    %ebp
 
334
        popl    %ebx
 
335
        popl    %esi
 
336
        popl    %edi
 
337
        ret
 
338
 
 
339
/* We loop from least significant end of the arrays, which is only
 
340
   permissable if the source and destination don't overlap, since the
 
341
   function is documented to work for overlapping source and destination.
 
342
*/
 
343
 
 
344
Rspecial:
 
345
        leal    -4(%edi,%ebp,4),%edi
 
346
        leal    -4(%esi,%ebp,4),%esi
 
347
 
 
348
        movl    (%esi),%edx
 
349
        subl    $4,%esi
 
350
 
 
351
        decl    %ebp
 
352
        pushl   %ebp
 
353
        shrl    $3,%ebp
 
354
 
 
355
        shrl    $1,%edx
 
356
        incl    %ebp
 
357
        decl    %ebp
 
358
        jz      RLend
 
359
 
 
360
        movl    (%edi),%eax             /* fetch destination cache line */
 
361
 
 
362
        ALIGN   (2)
 
363
RLoop:  movl    -28(%edi),%eax          /* fetch destination cache line */
 
364
        movl    %edx,%ebx
 
365
 
 
366
        movl    (%esi),%eax
 
367
        movl    -4(%esi),%edx
 
368
        rcrl    $1,%eax
 
369
        movl    %ebx,(%edi)
 
370
        rcrl    $1,%edx
 
371
        movl    %eax,-4(%edi)
 
372
 
 
373
        movl    -8(%esi),%ebx
 
374
        movl    -12(%esi),%eax
 
375
        rcrl    $1,%ebx
 
376
        movl    %edx,-8(%edi)
 
377
        rcrl    $1,%eax
 
378
        movl    %ebx,-12(%edi)
 
379
 
 
380
        movl    -16(%esi),%edx
 
381
        movl    -20(%esi),%ebx
 
382
        rcrl    $1,%edx
 
383
        movl    %eax,-16(%edi)
 
384
        rcrl    $1,%ebx
 
385
        movl    %edx,-20(%edi)
 
386
 
 
387
        movl    -24(%esi),%eax
 
388
        movl    -28(%esi),%edx
 
389
        rcrl    $1,%eax
 
390
        movl    %ebx,-24(%edi)
 
391
        rcrl    $1,%edx
 
392
        movl    %eax,-28(%edi)
 
393
 
 
394
        leal    -32(%esi),%esi          /* use leal not to clobber carry */
 
395
        leal    -32(%edi),%edi
 
396
        decl    %ebp
 
397
        jnz     RLoop
 
398
 
 
399
RLend:  popl    %ebp
 
400
        sbbl    %eax,%eax               /* save carry in %eax */
 
401
        andl    $7,%ebp
 
402
        jz      RLend2
 
403
        addl    %eax,%eax               /* restore carry from eax */
 
404
RLoop2: movl    %edx,%ebx
 
405
        movl    (%esi),%edx
 
406
        rcrl    $1,%edx
 
407
        movl    %ebx,(%edi)
 
408
 
 
409
        leal    -4(%esi),%esi           /* use leal not to clobber carry */
 
410
        leal    -4(%edi),%edi
 
411
        decl    %ebp
 
412
        jnz     RLoop2
 
413
 
 
414
        jmp     RL1
 
415
RLend2: addl    %eax,%eax               /* restore carry from eax */
 
416
RL1:    movl    %edx,(%edi)             /* store last limb */
 
417
 
 
418
        movl    $0,%eax
 
419
        rcrl    $1,%eax
 
420
 
 
421
        popl    %ebp
 
422
        popl    %ebx
 
423
        popl    %esi
 
424
        popl    %edi
 
425
        ret
 
426