Switched to GPLv3.
[gnupg.git] / mpi / hppa / udiv-qrnnd.S
1 /* HP-PA  __udiv_qrnnd division support, used from longlong.h.
2  *        This version runs fast on pre-PA7000 CPUs.
3  *
4  *      Copyright (C) 1993, 1994, 1998, 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 3 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, see <http://www.gnu.org/licenses/>.
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
32 /* INPUT PARAMETERS
33  *   rem_ptr       gr26
34  *   n1            gr25
35  *   n0            gr24
36  *   d             gr23
37  *
38  *   The code size is a bit excessive.  We could merge the last two ds;addc
39  *   sequences by simply moving the "bb,< Odd" instruction down.  The only
40  *   trouble is the FFFFFFFF code that would need some hacking.
41  */
42
43         .code
44         .export         __udiv_qrnnd
45         .label          __udiv_qrnnd
46         .proc
47         .callinfo       frame=0,no_calls
48         .entry
49
50         comb,<          %r23,0,L$largedivisor
51          sub            %r0,%r23,%r1            ; clear cy as side-effect
52         ds              %r0,%r1,%r0
53         addc            %r24,%r24,%r24
54         ds              %r25,%r23,%r25
55         addc            %r24,%r24,%r24
56         ds              %r25,%r23,%r25
57         addc            %r24,%r24,%r24
58         ds              %r25,%r23,%r25
59         addc            %r24,%r24,%r24
60         ds              %r25,%r23,%r25
61         addc            %r24,%r24,%r24
62         ds              %r25,%r23,%r25
63         addc            %r24,%r24,%r24
64         ds              %r25,%r23,%r25
65         addc            %r24,%r24,%r24
66         ds              %r25,%r23,%r25
67         addc            %r24,%r24,%r24
68         ds              %r25,%r23,%r25
69         addc            %r24,%r24,%r24
70         ds              %r25,%r23,%r25
71         addc            %r24,%r24,%r24
72         ds              %r25,%r23,%r25
73         addc            %r24,%r24,%r24
74         ds              %r25,%r23,%r25
75         addc            %r24,%r24,%r24
76         ds              %r25,%r23,%r25
77         addc            %r24,%r24,%r24
78         ds              %r25,%r23,%r25
79         addc            %r24,%r24,%r24
80         ds              %r25,%r23,%r25
81         addc            %r24,%r24,%r24
82         ds              %r25,%r23,%r25
83         addc            %r24,%r24,%r24
84         ds              %r25,%r23,%r25
85         addc            %r24,%r24,%r24
86         ds              %r25,%r23,%r25
87         addc            %r24,%r24,%r24
88         ds              %r25,%r23,%r25
89         addc            %r24,%r24,%r24
90         ds              %r25,%r23,%r25
91         addc            %r24,%r24,%r24
92         ds              %r25,%r23,%r25
93         addc            %r24,%r24,%r24
94         ds              %r25,%r23,%r25
95         addc            %r24,%r24,%r24
96         ds              %r25,%r23,%r25
97         addc            %r24,%r24,%r24
98         ds              %r25,%r23,%r25
99         addc            %r24,%r24,%r24
100         ds              %r25,%r23,%r25
101         addc            %r24,%r24,%r24
102         ds              %r25,%r23,%r25
103         addc            %r24,%r24,%r24
104         ds              %r25,%r23,%r25
105         addc            %r24,%r24,%r24
106         ds              %r25,%r23,%r25
107         addc            %r24,%r24,%r24
108         ds              %r25,%r23,%r25
109         addc            %r24,%r24,%r24
110         ds              %r25,%r23,%r25
111         addc            %r24,%r24,%r24
112         ds              %r25,%r23,%r25
113         addc            %r24,%r24,%r24
114         ds              %r25,%r23,%r25
115         addc            %r24,%r24,%r28
116         ds              %r25,%r23,%r25
117         comclr,>=       %r25,%r0,%r0
118         addl            %r25,%r23,%r25
119         stws            %r25,0(0,%r26)
120         bv              0(%r2)
121          addc           %r28,%r28,%r28
122
123         .label  L$largedivisor
124         extru           %r24,31,1,%r19          ; r19 = n0 & 1
125         bb,<            %r23,31,L$odd
126          extru          %r23,30,31,%r22         ; r22 = d >> 1
127         shd             %r25,%r24,1,%r24        ; r24 = new n0
128         extru           %r25,30,31,%r25         ; r25 = new n1
129         sub             %r0,%r22,%r21
130         ds              %r0,%r21,%r0
131         addc            %r24,%r24,%r24
132         ds              %r25,%r22,%r25
133         addc            %r24,%r24,%r24
134         ds              %r25,%r22,%r25
135         addc            %r24,%r24,%r24
136         ds              %r25,%r22,%r25
137         addc            %r24,%r24,%r24
138         ds              %r25,%r22,%r25
139         addc            %r24,%r24,%r24
140         ds              %r25,%r22,%r25
141         addc            %r24,%r24,%r24
142         ds              %r25,%r22,%r25
143         addc            %r24,%r24,%r24
144         ds              %r25,%r22,%r25
145         addc            %r24,%r24,%r24
146         ds              %r25,%r22,%r25
147         addc            %r24,%r24,%r24
148         ds              %r25,%r22,%r25
149         addc            %r24,%r24,%r24
150         ds              %r25,%r22,%r25
151         addc            %r24,%r24,%r24
152         ds              %r25,%r22,%r25
153         addc            %r24,%r24,%r24
154         ds              %r25,%r22,%r25
155         addc            %r24,%r24,%r24
156         ds              %r25,%r22,%r25
157         addc            %r24,%r24,%r24
158         ds              %r25,%r22,%r25
159         addc            %r24,%r24,%r24
160         ds              %r25,%r22,%r25
161         addc            %r24,%r24,%r24
162         ds              %r25,%r22,%r25
163         addc            %r24,%r24,%r24
164         ds              %r25,%r22,%r25
165         addc            %r24,%r24,%r24
166         ds              %r25,%r22,%r25
167         addc            %r24,%r24,%r24
168         ds              %r25,%r22,%r25
169         addc            %r24,%r24,%r24
170         ds              %r25,%r22,%r25
171         addc            %r24,%r24,%r24
172         ds              %r25,%r22,%r25
173         addc            %r24,%r24,%r24
174         ds              %r25,%r22,%r25
175         addc            %r24,%r24,%r24
176         ds              %r25,%r22,%r25
177         addc            %r24,%r24,%r24
178         ds              %r25,%r22,%r25
179         addc            %r24,%r24,%r24
180         ds              %r25,%r22,%r25
181         addc            %r24,%r24,%r24
182         ds              %r25,%r22,%r25
183         addc            %r24,%r24,%r24
184         ds              %r25,%r22,%r25
185         addc            %r24,%r24,%r24
186         ds              %r25,%r22,%r25
187         addc            %r24,%r24,%r24
188         ds              %r25,%r22,%r25
189         addc            %r24,%r24,%r24
190         ds              %r25,%r22,%r25
191         addc            %r24,%r24,%r24
192         ds              %r25,%r22,%r25
193         addc            %r24,%r24,%r24
194         ds              %r25,%r22,%r25
195         comclr,>=       %r25,%r0,%r0
196         addl            %r25,%r22,%r25
197         sh1addl         %r25,%r19,%r25
198         stws            %r25,0(0,%r26)
199         bv              0(%r2)
200          addc           %r24,%r24,%r28
201
202         .label  L$odd
203         addib,sv,n      1,%r22,L$FF..           ; r22 = (d / 2 + 1)
204         shd             %r25,%r24,1,%r24        ; r24 = new n0
205         extru           %r25,30,31,%r25         ; r25 = new n1
206         sub             %r0,%r22,%r21
207         ds              %r0,%r21,%r0
208         addc            %r24,%r24,%r24
209         ds              %r25,%r22,%r25
210         addc            %r24,%r24,%r24
211         ds              %r25,%r22,%r25
212         addc            %r24,%r24,%r24
213         ds              %r25,%r22,%r25
214         addc            %r24,%r24,%r24
215         ds              %r25,%r22,%r25
216         addc            %r24,%r24,%r24
217         ds              %r25,%r22,%r25
218         addc            %r24,%r24,%r24
219         ds              %r25,%r22,%r25
220         addc            %r24,%r24,%r24
221         ds              %r25,%r22,%r25
222         addc            %r24,%r24,%r24
223         ds              %r25,%r22,%r25
224         addc            %r24,%r24,%r24
225         ds              %r25,%r22,%r25
226         addc            %r24,%r24,%r24
227         ds              %r25,%r22,%r25
228         addc            %r24,%r24,%r24
229         ds              %r25,%r22,%r25
230         addc            %r24,%r24,%r24
231         ds              %r25,%r22,%r25
232         addc            %r24,%r24,%r24
233         ds              %r25,%r22,%r25
234         addc            %r24,%r24,%r24
235         ds              %r25,%r22,%r25
236         addc            %r24,%r24,%r24
237         ds              %r25,%r22,%r25
238         addc            %r24,%r24,%r24
239         ds              %r25,%r22,%r25
240         addc            %r24,%r24,%r24
241         ds              %r25,%r22,%r25
242         addc            %r24,%r24,%r24
243         ds              %r25,%r22,%r25
244         addc            %r24,%r24,%r24
245         ds              %r25,%r22,%r25
246         addc            %r24,%r24,%r24
247         ds              %r25,%r22,%r25
248         addc            %r24,%r24,%r24
249         ds              %r25,%r22,%r25
250         addc            %r24,%r24,%r24
251         ds              %r25,%r22,%r25
252         addc            %r24,%r24,%r24
253         ds              %r25,%r22,%r25
254         addc            %r24,%r24,%r24
255         ds              %r25,%r22,%r25
256         addc            %r24,%r24,%r24
257         ds              %r25,%r22,%r25
258         addc            %r24,%r24,%r24
259         ds              %r25,%r22,%r25
260         addc            %r24,%r24,%r24
261         ds              %r25,%r22,%r25
262         addc            %r24,%r24,%r24
263         ds              %r25,%r22,%r25
264         addc            %r24,%r24,%r24
265         ds              %r25,%r22,%r25
266         addc            %r24,%r24,%r24
267         ds              %r25,%r22,%r25
268         addc            %r24,%r24,%r24
269         ds              %r25,%r22,%r25
270         addc            %r24,%r24,%r24
271         ds              %r25,%r22,%r25
272         addc            %r24,%r24,%r28
273         comclr,>=       %r25,%r0,%r0
274         addl            %r25,%r22,%r25
275         sh1addl         %r25,%r19,%r25
276 ; We have computed (n1,,n0) / (d + 1), q' = r28, r' = r25
277         add,nuv         %r28,%r25,%r25
278         addl            %r25,%r1,%r25
279         addc            %r0,%r28,%r28
280         sub,<<          %r25,%r23,%r0
281         addl            %r25,%r1,%r25
282         stws            %r25,0(0,%r26)
283         bv              0(%r2)
284          addc           %r0,%r28,%r28
285
286 ; This is just a special case of the code above.
287 ; We come here when d == 0xFFFFFFFF
288         .label  L$FF..
289         add,uv          %r25,%r24,%r24
290         sub,<<          %r24,%r23,%r0
291         ldo             1(%r24),%r24
292         stws            %r24,0(0,%r26)
293         bv              0(%r2)
294          addc           %r0,%r25,%r28
295
296         .exit
297         .procend