~ubuntu-branches/ubuntu/feisty/gnupg2/feisty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-07-11 11:38:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060711113813-zaw7unlbuh7gyxtl
Tags: 1.9.21-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* i80586   rshift
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
 
/*******************
38
 
 * mpi_limb_t
39
 
 * mpihelp_rshift( mpi_ptr_t wp,        (sp + 4)
40
 
 *                 mpi_ptr_t up,        (sp + 8)
41
 
 *                 mpi_size_t usize,    (sp + 12)
42
 
 *                 unsigned cnt)        (sp + 16)
43
 
 */
44
 
 
45
 
.text
46
 
        ALIGN (3)
47
 
        .globl C_SYMBOL_NAME(mpihelp_rshift)
48
 
C_SYMBOL_NAME(mpihelp_rshift:)
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     Rnormal
62
 
        leal    4(%edi),%eax
63
 
        cmpl    %esi,%eax
64
 
        jnc     Rspecial                /* jump if res_ptr + 1 >= s_ptr */
65
 
        leal    (%edi,%ebp,4),%eax
66
 
        cmpl    %eax,%esi
67
 
        jnc     Rspecial                /* jump if s_ptr >= res_ptr + size */
68
 
 
69
 
Rnormal:
70
 
        movl    (%esi),%edx
71
 
        addl    $4,%esi
72
 
        xorl    %eax,%eax
73
 
        shrdl   %cl,%edx,%eax           /* compute carry limb */
74
 
        pushl   %eax                    /* push carry limb onto stack */
75
 
 
76
 
        decl    %ebp
77
 
        pushl   %ebp
78
 
        shrl    $3,%ebp
79
 
        jz      Rend
80
 
 
81
 
        movl    (%edi),%eax             /* fetch destination cache line */
82
 
 
83
 
        ALIGN   (2)
84
 
Roop:   movl    28(%edi),%eax           /* fetch destination cache line */
85
 
        movl    %edx,%ebx
86
 
 
87
 
        movl    (%esi),%eax
88
 
        movl    4(%esi),%edx
89
 
        shrdl   %cl,%eax,%ebx
90
 
        shrdl   %cl,%edx,%eax
91
 
        movl    %ebx,(%edi)
92
 
        movl    %eax,4(%edi)
93
 
 
94
 
        movl    8(%esi),%ebx
95
 
        movl    12(%esi),%eax
96
 
        shrdl   %cl,%ebx,%edx
97
 
        shrdl   %cl,%eax,%ebx
98
 
        movl    %edx,8(%edi)
99
 
        movl    %ebx,12(%edi)
100
 
 
101
 
        movl    16(%esi),%edx
102
 
        movl    20(%esi),%ebx
103
 
        shrdl   %cl,%edx,%eax
104
 
        shrdl   %cl,%ebx,%edx
105
 
        movl    %eax,16(%edi)
106
 
        movl    %edx,20(%edi)
107
 
 
108
 
        movl    24(%esi),%eax
109
 
        movl    28(%esi),%edx
110
 
        shrdl   %cl,%eax,%ebx
111
 
        shrdl   %cl,%edx,%eax
112
 
        movl    %ebx,24(%edi)
113
 
        movl    %eax,28(%edi)
114
 
 
115
 
        addl    $32,%esi
116
 
        addl    $32,%edi
117
 
        decl    %ebp
118
 
        jnz     Roop
119
 
 
120
 
Rend:   popl    %ebp
121
 
        andl    $7,%ebp
122
 
        jz      Rend2
123
 
Roop2:  movl    (%esi),%eax
124
 
        shrdl   %cl,%eax,%edx           /* compute result limb */
125
 
        movl    %edx,(%edi)
126
 
        movl    %eax,%edx
127
 
        addl    $4,%esi
128
 
        addl    $4,%edi
129
 
        decl    %ebp
130
 
        jnz     Roop2
131
 
 
132
 
Rend2:  shrl    %cl,%edx                /* compute most significant limb */
133
 
        movl    %edx,(%edi)             /* store it */
134
 
 
135
 
        popl    %eax                    /* pop carry limb */
136
 
 
137
 
        popl    %ebp
138
 
        popl    %ebx
139
 
        popl    %esi
140
 
        popl    %edi
141
 
        ret
142
 
 
143
 
/* We loop from least significant end of the arrays, which is only
144
 
   permissable if the source and destination don't overlap, since the
145
 
   function is documented to work for overlapping source and destination.
146
 
*/
147
 
 
148
 
Rspecial:
149
 
        leal    -4(%edi,%ebp,4),%edi
150
 
        leal    -4(%esi,%ebp,4),%esi
151
 
 
152
 
        movl    (%esi),%edx
153
 
        subl    $4,%esi
154
 
 
155
 
        decl    %ebp
156
 
        pushl   %ebp
157
 
        shrl    $3,%ebp
158
 
 
159
 
        shrl    $1,%edx
160
 
        incl    %ebp
161
 
        decl    %ebp
162
 
        jz      RLend
163
 
 
164
 
        movl    (%edi),%eax             /* fetch destination cache line */
165
 
 
166
 
        ALIGN   (2)
167
 
RLoop:  movl    -28(%edi),%eax          /* fetch destination cache line */
168
 
        movl    %edx,%ebx
169
 
 
170
 
        movl    (%esi),%eax
171
 
        movl    -4(%esi),%edx
172
 
        rcrl    $1,%eax
173
 
        movl    %ebx,(%edi)
174
 
        rcrl    $1,%edx
175
 
        movl    %eax,-4(%edi)
176
 
 
177
 
        movl    -8(%esi),%ebx
178
 
        movl    -12(%esi),%eax
179
 
        rcrl    $1,%ebx
180
 
        movl    %edx,-8(%edi)
181
 
        rcrl    $1,%eax
182
 
        movl    %ebx,-12(%edi)
183
 
 
184
 
        movl    -16(%esi),%edx
185
 
        movl    -20(%esi),%ebx
186
 
        rcrl    $1,%edx
187
 
        movl    %eax,-16(%edi)
188
 
        rcrl    $1,%ebx
189
 
        movl    %edx,-20(%edi)
190
 
 
191
 
        movl    -24(%esi),%eax
192
 
        movl    -28(%esi),%edx
193
 
        rcrl    $1,%eax
194
 
        movl    %ebx,-24(%edi)
195
 
        rcrl    $1,%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     RLoop
202
 
 
203
 
RLend:  popl    %ebp
204
 
        sbbl    %eax,%eax               /* save carry in %eax */
205
 
        andl    $7,%ebp
206
 
        jz      RLend2
207
 
        addl    %eax,%eax               /* restore carry from eax */
208
 
RLoop2: movl    %edx,%ebx
209
 
        movl    (%esi),%edx
210
 
        rcrl    $1,%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     RLoop2
217
 
 
218
 
        jmp     RL1
219
 
RLend2: addl    %eax,%eax               /* restore carry from eax */
220
 
RL1:    movl    %edx,(%edi)             /* store last limb */
221
 
 
222
 
        movl    $0,%eax
223
 
        rcrl    $1,%eax
224
 
 
225
 
        popl    %ebp
226
 
        popl    %ebx
227
 
        popl    %esi
228
 
        popl    %edi
229
 
        ret
230