1 /* crypto/bn/bn_comba.c */
4 /* Auto generated from crypto/bn/comba.pl
13 #define mul_add_c(a,b,c0,c1,c2) \
17 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
18 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
20 #define mul_add_c2(a,b,c0,c1,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++;
30 #define sqr_add_c(a,i,c0,c1,c2) \
31 t=(BN_ULLONG)a[i]*a[i]; \
34 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
35 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
37 #define sqr_add_c2(a,i,j,c0,c1,c2) \
38 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
40 #define mul_add_c(a,b,c0,c1,c2) \
41 t1=LBITS(a); t2=HBITS(a); \
42 bl=LBITS(b); bh=HBITS(b); \
44 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
45 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
47 #define mul_add_c2(a,b,c0,c1,c2) \
48 t1=LBITS(a); t2=HBITS(a); \
49 bl=LBITS(b); bh=HBITS(b); \
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++;
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++;
64 #define sqr_add_c2(a,i,j,c0,c1,c2) \
65 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
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);
73 void bn_mul_comba88(r,a,b)
87 mul_add_c(a[0],b[0],c1,c2,c3);
90 mul_add_c(a[0],b[1],c2,c3,c1);
91 mul_add_c(a[1],b[0],c2,c3,c1);
94 mul_add_c(a[2],b[0],c3,c1,c2);
95 mul_add_c(a[1],b[1],c3,c1,c2);
96 mul_add_c(a[0],b[2],c3,c1,c2);
99 mul_add_c(a[0],b[3],c1,c2,c3);
100 mul_add_c(a[1],b[2],c1,c2,c3);
101 mul_add_c(a[2],b[1],c1,c2,c3);
102 mul_add_c(a[3],b[0],c1,c2,c3);
105 mul_add_c(a[4],b[0],c2,c3,c1);
106 mul_add_c(a[3],b[1],c2,c3,c1);
107 mul_add_c(a[2],b[2],c2,c3,c1);
108 mul_add_c(a[1],b[3],c2,c3,c1);
109 mul_add_c(a[0],b[4],c2,c3,c1);
112 mul_add_c(a[0],b[5],c3,c1,c2);
113 mul_add_c(a[1],b[4],c3,c1,c2);
114 mul_add_c(a[2],b[3],c3,c1,c2);
115 mul_add_c(a[3],b[2],c3,c1,c2);
116 mul_add_c(a[4],b[1],c3,c1,c2);
117 mul_add_c(a[5],b[0],c3,c1,c2);
120 mul_add_c(a[6],b[0],c1,c2,c3);
121 mul_add_c(a[5],b[1],c1,c2,c3);
122 mul_add_c(a[4],b[2],c1,c2,c3);
123 mul_add_c(a[3],b[3],c1,c2,c3);
124 mul_add_c(a[2],b[4],c1,c2,c3);
125 mul_add_c(a[1],b[5],c1,c2,c3);
126 mul_add_c(a[0],b[6],c1,c2,c3);
129 mul_add_c(a[0],b[7],c2,c3,c1);
130 mul_add_c(a[1],b[6],c2,c3,c1);
131 mul_add_c(a[2],b[5],c2,c3,c1);
132 mul_add_c(a[3],b[4],c2,c3,c1);
133 mul_add_c(a[4],b[3],c2,c3,c1);
134 mul_add_c(a[5],b[2],c2,c3,c1);
135 mul_add_c(a[6],b[1],c2,c3,c1);
136 mul_add_c(a[7],b[0],c2,c3,c1);
139 mul_add_c(a[7],b[1],c3,c1,c2);
140 mul_add_c(a[6],b[2],c3,c1,c2);
141 mul_add_c(a[5],b[3],c3,c1,c2);
142 mul_add_c(a[4],b[4],c3,c1,c2);
143 mul_add_c(a[3],b[5],c3,c1,c2);
144 mul_add_c(a[2],b[6],c3,c1,c2);
145 mul_add_c(a[1],b[7],c3,c1,c2);
148 mul_add_c(a[2],b[7],c1,c2,c3);
149 mul_add_c(a[3],b[6],c1,c2,c3);
150 mul_add_c(a[4],b[5],c1,c2,c3);
151 mul_add_c(a[5],b[4],c1,c2,c3);
152 mul_add_c(a[6],b[3],c1,c2,c3);
153 mul_add_c(a[7],b[2],c1,c2,c3);
156 mul_add_c(a[7],b[3],c2,c3,c1);
157 mul_add_c(a[6],b[4],c2,c3,c1);
158 mul_add_c(a[5],b[5],c2,c3,c1);
159 mul_add_c(a[4],b[6],c2,c3,c1);
160 mul_add_c(a[3],b[7],c2,c3,c1);
163 mul_add_c(a[4],b[7],c3,c1,c2);
164 mul_add_c(a[5],b[6],c3,c1,c2);
165 mul_add_c(a[6],b[5],c3,c1,c2);
166 mul_add_c(a[7],b[4],c3,c1,c2);
169 mul_add_c(a[7],b[5],c1,c2,c3);
170 mul_add_c(a[6],b[6],c1,c2,c3);
171 mul_add_c(a[5],b[7],c1,c2,c3);
174 mul_add_c(a[6],b[7],c2,c3,c1);
175 mul_add_c(a[7],b[6],c2,c3,c1);
178 mul_add_c(a[7],b[7],c3,c1,c2);
183 void bn_mul_comba44(r,a,b)
197 mul_add_c(a[0],b[0],c1,c2,c3);
200 mul_add_c(a[0],b[1],c2,c3,c1);
201 mul_add_c(a[1],b[0],c2,c3,c1);
204 mul_add_c(a[2],b[0],c3,c1,c2);
205 mul_add_c(a[1],b[1],c3,c1,c2);
206 mul_add_c(a[0],b[2],c3,c1,c2);
209 mul_add_c(a[0],b[3],c1,c2,c3);
210 mul_add_c(a[1],b[2],c1,c2,c3);
211 mul_add_c(a[2],b[1],c1,c2,c3);
212 mul_add_c(a[3],b[0],c1,c2,c3);
215 mul_add_c(a[3],b[1],c2,c3,c1);
216 mul_add_c(a[2],b[2],c2,c3,c1);
217 mul_add_c(a[1],b[3],c2,c3,c1);
220 mul_add_c(a[2],b[3],c3,c1,c2);
221 mul_add_c(a[3],b[2],c3,c1,c2);
224 mul_add_c(a[3],b[3],c1,c2,c3);
229 void bn_sqr_comba88(r,a)
243 sqr_add_c(a,0,c1,c2,c3);
246 sqr_add_c2(a,1,0,c2,c3,c1);
249 sqr_add_c(a,1,c3,c1,c2);
250 sqr_add_c2(a,2,0,c3,c1,c2);
253 sqr_add_c2(a,3,0,c1,c2,c3);
254 sqr_add_c2(a,2,1,c1,c2,c3);
257 sqr_add_c(a,2,c2,c3,c1);
258 sqr_add_c2(a,3,1,c2,c3,c1);
259 sqr_add_c2(a,4,0,c2,c3,c1);
262 sqr_add_c2(a,5,0,c3,c1,c2);
263 sqr_add_c2(a,4,1,c3,c1,c2);
264 sqr_add_c2(a,3,2,c3,c1,c2);
267 sqr_add_c(a,3,c1,c2,c3);
268 sqr_add_c2(a,4,2,c1,c2,c3);
269 sqr_add_c2(a,5,1,c1,c2,c3);
270 sqr_add_c2(a,6,0,c1,c2,c3);
273 sqr_add_c2(a,7,0,c2,c3,c1);
274 sqr_add_c2(a,6,1,c2,c3,c1);
275 sqr_add_c2(a,5,2,c2,c3,c1);
276 sqr_add_c2(a,4,3,c2,c3,c1);
279 sqr_add_c(a,4,c3,c1,c2);
280 sqr_add_c2(a,5,3,c3,c1,c2);
281 sqr_add_c2(a,6,2,c3,c1,c2);
282 sqr_add_c2(a,7,1,c3,c1,c2);
285 sqr_add_c2(a,7,2,c1,c2,c3);
286 sqr_add_c2(a,6,3,c1,c2,c3);
287 sqr_add_c2(a,5,4,c1,c2,c3);
290 sqr_add_c(a,5,c2,c3,c1);
291 sqr_add_c2(a,6,4,c2,c3,c1);
292 sqr_add_c2(a,7,3,c2,c3,c1);
295 sqr_add_c2(a,7,4,c3,c1,c2);
296 sqr_add_c2(a,6,5,c3,c1,c2);
299 sqr_add_c(a,6,c1,c2,c3);
300 sqr_add_c2(a,7,5,c1,c2,c3);
303 sqr_add_c2(a,7,6,c2,c3,c1);
306 sqr_add_c(a,7,c3,c1,c2);
311 void bn_sqr_comba44(r,a)
325 sqr_add_c(a,0,c1,c2,c3);
328 sqr_add_c2(a,1,0,c2,c3,c1);
331 sqr_add_c(a,1,c3,c1,c2);
332 sqr_add_c2(a,2,0,c3,c1,c2);
335 sqr_add_c2(a,3,0,c1,c2,c3);
336 sqr_add_c2(a,2,1,c1,c2,c3);
339 sqr_add_c(a,2,c2,c3,c1);
340 sqr_add_c2(a,3,1,c2,c3,c1);
343 sqr_add_c2(a,3,2,c3,c1,c2);
346 sqr_add_c(a,3,c1,c2,c3);