Remove header files from .cvsignore.
[openssl.git] / crypto / bn / bn_comba.c
1 /* crypto/bn/bn_comba.c */
2 #include <stdio.h>
3 #include "bn_lcl.h"
4 /* Auto generated from crypto/bn/comba.pl
5  */
6
7 #undef bn_mul_comba8
8 #undef bn_mul_comba4
9 #undef bn_sqr_comba8
10 #undef bn_sqr_comba4
11
12 #ifdef BN_LLONG
13 #define mul_add_c(a,b,c0,c1,c2) \
14         t=(BN_ULLONG)a*b; \
15         t1=(BN_ULONG)Lw(t); \
16         t2=(BN_ULONG)Hw(t); \
17         c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
18         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
19
20 #define mul_add_c2(a,b,c0,c1,c2) \
21         t=(BN_ULLONG)a*b; \
22         tt=(t+t)&BN_MASK; \
23         if (tt < t) c2++; \
24         t1=(BN_ULONG)Lw(tt); \
25         t2=(BN_ULONG)Hw(tt); \
26         c0=(c0+t1)&BN_MASK2;  \
27         if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
28         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
29
30 #define sqr_add_c(a,i,c0,c1,c2) \
31         t=(BN_ULLONG)a[i]*a[i]; \
32         t1=(BN_ULONG)Lw(t); \
33         t2=(BN_ULONG)Hw(t); \
34         c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
35         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
36
37 #define sqr_add_c2(a,i,j,c0,c1,c2) \
38         mul_add_c2((a)[i],(a)[j],c0,c1,c2)
39 #else
40 #define mul_add_c(a,b,c0,c1,c2) \
41         t1=LBITS(a); t2=HBITS(a); \
42         bl=LBITS(b); bh=HBITS(b); \
43         mul64(t1,t2,bl,bh); \
44         c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
45         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
46
47 #define mul_add_c2(a,b,c0,c1,c2) \
48         t1=LBITS(a); t2=HBITS(a); \
49         bl=LBITS(b); bh=HBITS(b); \
50         mul64(t1,t2,bl,bh); \
51         if (t2 & BN_TBIT) c2++; \
52         t2=(t2+t2)&BN_MASK2; \
53         if (t1 & BN_TBIT) t2++; \
54         t1=(t1+t1)&BN_MASK2; \
55         c0=(c0+t1)&BN_MASK2;  \
56         if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
57         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
58
59 #define sqr_add_c(a,i,c0,c1,c2) \
60         sqr64(t1,t2,(a)[i]); \
61         c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
62         c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
63
64 #define sqr_add_c2(a,i,j,c0,c1,c2) \
65         mul_add_c2((a)[i],(a)[j],c0,c1,c2)
66 #endif
67
68 void bn_mul_comba88(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
69 void bn_mul_comba44(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
70 void bn_sqr_comba88(BN_ULONG *r,BN_ULONG *a);
71 void bn_sqr_comba44(BN_ULONG *r,BN_ULONG *a);
72
73 void bn_mul_comba88(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
74         {
75 #ifdef BN_LLONG
76         BN_ULLONG t;
77 #else
78         BN_ULONG bl,bh;
79 #endif
80         BN_ULONG t1,t2;
81         BN_ULONG c1,c2,c3;
82
83         c1=0;
84         c2=0;
85         c3=0;
86         mul_add_c(a[0],b[0],c1,c2,c3);
87         r[0]=c1;
88         c1=0;
89         mul_add_c(a[0],b[1],c2,c3,c1);
90         mul_add_c(a[1],b[0],c2,c3,c1);
91         r[1]=c2;
92         c2=0;
93         mul_add_c(a[2],b[0],c3,c1,c2);
94         mul_add_c(a[1],b[1],c3,c1,c2);
95         mul_add_c(a[0],b[2],c3,c1,c2);
96         r[2]=c3;
97         c3=0;
98         mul_add_c(a[0],b[3],c1,c2,c3);
99         mul_add_c(a[1],b[2],c1,c2,c3);
100         mul_add_c(a[2],b[1],c1,c2,c3);
101         mul_add_c(a[3],b[0],c1,c2,c3);
102         r[3]=c1;
103         c1=0;
104         mul_add_c(a[4],b[0],c2,c3,c1);
105         mul_add_c(a[3],b[1],c2,c3,c1);
106         mul_add_c(a[2],b[2],c2,c3,c1);
107         mul_add_c(a[1],b[3],c2,c3,c1);
108         mul_add_c(a[0],b[4],c2,c3,c1);
109         r[4]=c2;
110         c2=0;
111         mul_add_c(a[0],b[5],c3,c1,c2);
112         mul_add_c(a[1],b[4],c3,c1,c2);
113         mul_add_c(a[2],b[3],c3,c1,c2);
114         mul_add_c(a[3],b[2],c3,c1,c2);
115         mul_add_c(a[4],b[1],c3,c1,c2);
116         mul_add_c(a[5],b[0],c3,c1,c2);
117         r[5]=c3;
118         c3=0;
119         mul_add_c(a[6],b[0],c1,c2,c3);
120         mul_add_c(a[5],b[1],c1,c2,c3);
121         mul_add_c(a[4],b[2],c1,c2,c3);
122         mul_add_c(a[3],b[3],c1,c2,c3);
123         mul_add_c(a[2],b[4],c1,c2,c3);
124         mul_add_c(a[1],b[5],c1,c2,c3);
125         mul_add_c(a[0],b[6],c1,c2,c3);
126         r[6]=c1;
127         c1=0;
128         mul_add_c(a[0],b[7],c2,c3,c1);
129         mul_add_c(a[1],b[6],c2,c3,c1);
130         mul_add_c(a[2],b[5],c2,c3,c1);
131         mul_add_c(a[3],b[4],c2,c3,c1);
132         mul_add_c(a[4],b[3],c2,c3,c1);
133         mul_add_c(a[5],b[2],c2,c3,c1);
134         mul_add_c(a[6],b[1],c2,c3,c1);
135         mul_add_c(a[7],b[0],c2,c3,c1);
136         r[7]=c2;
137         c2=0;
138         mul_add_c(a[7],b[1],c3,c1,c2);
139         mul_add_c(a[6],b[2],c3,c1,c2);
140         mul_add_c(a[5],b[3],c3,c1,c2);
141         mul_add_c(a[4],b[4],c3,c1,c2);
142         mul_add_c(a[3],b[5],c3,c1,c2);
143         mul_add_c(a[2],b[6],c3,c1,c2);
144         mul_add_c(a[1],b[7],c3,c1,c2);
145         r[8]=c3;
146         c3=0;
147         mul_add_c(a[2],b[7],c1,c2,c3);
148         mul_add_c(a[3],b[6],c1,c2,c3);
149         mul_add_c(a[4],b[5],c1,c2,c3);
150         mul_add_c(a[5],b[4],c1,c2,c3);
151         mul_add_c(a[6],b[3],c1,c2,c3);
152         mul_add_c(a[7],b[2],c1,c2,c3);
153         r[9]=c1;
154         c1=0;
155         mul_add_c(a[7],b[3],c2,c3,c1);
156         mul_add_c(a[6],b[4],c2,c3,c1);
157         mul_add_c(a[5],b[5],c2,c3,c1);
158         mul_add_c(a[4],b[6],c2,c3,c1);
159         mul_add_c(a[3],b[7],c2,c3,c1);
160         r[10]=c2;
161         c2=0;
162         mul_add_c(a[4],b[7],c3,c1,c2);
163         mul_add_c(a[5],b[6],c3,c1,c2);
164         mul_add_c(a[6],b[5],c3,c1,c2);
165         mul_add_c(a[7],b[4],c3,c1,c2);
166         r[11]=c3;
167         c3=0;
168         mul_add_c(a[7],b[5],c1,c2,c3);
169         mul_add_c(a[6],b[6],c1,c2,c3);
170         mul_add_c(a[5],b[7],c1,c2,c3);
171         r[12]=c1;
172         c1=0;
173         mul_add_c(a[6],b[7],c2,c3,c1);
174         mul_add_c(a[7],b[6],c2,c3,c1);
175         r[13]=c2;
176         c2=0;
177         mul_add_c(a[7],b[7],c3,c1,c2);
178         r[14]=c3;
179         r[15]=c1;
180         }
181
182 void bn_mul_comba44(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
183         {
184 #ifdef BN_LLONG
185         BN_ULLONG t;
186 #else
187         BN_ULONG bl,bh;
188 #endif
189         BN_ULONG t1,t2;
190         BN_ULONG c1,c2,c3;
191
192         c1=0;
193         c2=0;
194         c3=0;
195         mul_add_c(a[0],b[0],c1,c2,c3);
196         r[0]=c1;
197         c1=0;
198         mul_add_c(a[0],b[1],c2,c3,c1);
199         mul_add_c(a[1],b[0],c2,c3,c1);
200         r[1]=c2;
201         c2=0;
202         mul_add_c(a[2],b[0],c3,c1,c2);
203         mul_add_c(a[1],b[1],c3,c1,c2);
204         mul_add_c(a[0],b[2],c3,c1,c2);
205         r[2]=c3;
206         c3=0;
207         mul_add_c(a[0],b[3],c1,c2,c3);
208         mul_add_c(a[1],b[2],c1,c2,c3);
209         mul_add_c(a[2],b[1],c1,c2,c3);
210         mul_add_c(a[3],b[0],c1,c2,c3);
211         r[3]=c1;
212         c1=0;
213         mul_add_c(a[3],b[1],c2,c3,c1);
214         mul_add_c(a[2],b[2],c2,c3,c1);
215         mul_add_c(a[1],b[3],c2,c3,c1);
216         r[4]=c2;
217         c2=0;
218         mul_add_c(a[2],b[3],c3,c1,c2);
219         mul_add_c(a[3],b[2],c3,c1,c2);
220         r[5]=c3;
221         c3=0;
222         mul_add_c(a[3],b[3],c1,c2,c3);
223         r[6]=c1;
224         r[7]=c2;
225         }
226
227 void bn_sqr_comba88(BN_ULONG *r, BN_ULONG *a)
228         {
229 #ifdef BN_LLONG
230         BN_ULLONG t,tt;
231 #else
232         BN_ULONG bl,bh;
233 #endif
234         BN_ULONG t1,t2;
235         BN_ULONG c1,c2,c3;
236
237         c1=0;
238         c2=0;
239         c3=0;
240         sqr_add_c(a,0,c1,c2,c3);
241         r[0]=c1;
242         c1=0;
243         sqr_add_c2(a,1,0,c2,c3,c1);
244         r[1]=c2;
245         c2=0;
246         sqr_add_c(a,1,c3,c1,c2);
247         sqr_add_c2(a,2,0,c3,c1,c2);
248         r[2]=c3;
249         c3=0;
250         sqr_add_c2(a,3,0,c1,c2,c3);
251         sqr_add_c2(a,2,1,c1,c2,c3);
252         r[3]=c1;
253         c1=0;
254         sqr_add_c(a,2,c2,c3,c1);
255         sqr_add_c2(a,3,1,c2,c3,c1);
256         sqr_add_c2(a,4,0,c2,c3,c1);
257         r[4]=c2;
258         c2=0;
259         sqr_add_c2(a,5,0,c3,c1,c2);
260         sqr_add_c2(a,4,1,c3,c1,c2);
261         sqr_add_c2(a,3,2,c3,c1,c2);
262         r[5]=c3;
263         c3=0;
264         sqr_add_c(a,3,c1,c2,c3);
265         sqr_add_c2(a,4,2,c1,c2,c3);
266         sqr_add_c2(a,5,1,c1,c2,c3);
267         sqr_add_c2(a,6,0,c1,c2,c3);
268         r[6]=c1;
269         c1=0;
270         sqr_add_c2(a,7,0,c2,c3,c1);
271         sqr_add_c2(a,6,1,c2,c3,c1);
272         sqr_add_c2(a,5,2,c2,c3,c1);
273         sqr_add_c2(a,4,3,c2,c3,c1);
274         r[7]=c2;
275         c2=0;
276         sqr_add_c(a,4,c3,c1,c2);
277         sqr_add_c2(a,5,3,c3,c1,c2);
278         sqr_add_c2(a,6,2,c3,c1,c2);
279         sqr_add_c2(a,7,1,c3,c1,c2);
280         r[8]=c3;
281         c3=0;
282         sqr_add_c2(a,7,2,c1,c2,c3);
283         sqr_add_c2(a,6,3,c1,c2,c3);
284         sqr_add_c2(a,5,4,c1,c2,c3);
285         r[9]=c1;
286         c1=0;
287         sqr_add_c(a,5,c2,c3,c1);
288         sqr_add_c2(a,6,4,c2,c3,c1);
289         sqr_add_c2(a,7,3,c2,c3,c1);
290         r[10]=c2;
291         c2=0;
292         sqr_add_c2(a,7,4,c3,c1,c2);
293         sqr_add_c2(a,6,5,c3,c1,c2);
294         r[11]=c3;
295         c3=0;
296         sqr_add_c(a,6,c1,c2,c3);
297         sqr_add_c2(a,7,5,c1,c2,c3);
298         r[12]=c1;
299         c1=0;
300         sqr_add_c2(a,7,6,c2,c3,c1);
301         r[13]=c2;
302         c2=0;
303         sqr_add_c(a,7,c3,c1,c2);
304         r[14]=c3;
305         r[15]=c1;
306         }
307
308 void bn_sqr_comba44(BN_ULONG *r, BN_ULONG *a)
309         {
310 #ifdef BN_LLONG
311         BN_ULLONG t,tt;
312 #else
313         BN_ULONG bl,bh;
314 #endif
315         BN_ULONG t1,t2;
316         BN_ULONG c1,c2,c3;
317
318         c1=0;
319         c2=0;
320         c3=0;
321         sqr_add_c(a,0,c1,c2,c3);
322         r[0]=c1;
323         c1=0;
324         sqr_add_c2(a,1,0,c2,c3,c1);
325         r[1]=c2;
326         c2=0;
327         sqr_add_c(a,1,c3,c1,c2);
328         sqr_add_c2(a,2,0,c3,c1,c2);
329         r[2]=c3;
330         c3=0;
331         sqr_add_c2(a,3,0,c1,c2,c3);
332         sqr_add_c2(a,2,1,c1,c2,c3);
333         r[3]=c1;
334         c1=0;
335         sqr_add_c(a,2,c2,c3,c1);
336         sqr_add_c2(a,3,1,c2,c3,c1);
337         r[4]=c2;
338         c2=0;
339         sqr_add_c2(a,3,2,c3,c1,c2);
340         r[5]=c3;
341         c3=0;
342         sqr_add_c(a,3,c1,c2,c3);
343         r[6]=c1;
344         r[7]=c2;
345         }