7 /* crypto/bn/bn_comba.c */
10 /* Auto generated from crypto/bn/comba.pl
19 #define mul_add_c(a,b,c0,c1,c2) \\
21 t1=(BN_ULONG)Lw(t); \\
22 t2=(BN_ULONG)Hw(t); \\
23 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
24 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
26 #define mul_add_c2(a,b,c0,c1,c2) \\
30 t1=(BN_ULONG)Lw(tt); \\
31 t2=(BN_ULONG)Hw(tt); \\
32 c0=(c0+t1)&BN_MASK2; \\
33 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
34 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
36 #define sqr_add_c(a,i,c0,c1,c2) \\
37 t=(BN_ULLONG)a[i]*a[i]; \\
38 t1=(BN_ULONG)Lw(t); \\
39 t2=(BN_ULONG)Hw(t); \\
40 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
41 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
43 #define sqr_add_c2(a,i,j,c0,c1,c2) \\
44 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
46 #define mul_add_c(a,b,c0,c1,c2) \\
47 t1=LBITS(a); t2=HBITS(a); \\
48 bl=LBITS(b); bh=HBITS(b); \\
49 mul64(t1,t2,bl,bh); \\
50 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
51 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
53 #define mul_add_c2(a,b,c0,c1,c2) \\
54 t1=LBITS(a); t2=HBITS(a); \\
55 bl=LBITS(b); bh=HBITS(b); \\
56 mul64(t1,t2,bl,bh); \\
57 if (t2 & BN_TBIT) c2++; \\
58 t2=(t2+t2)&BN_MASK2; \\
59 if (t1 & BN_TBIT) t2++; \\
60 t1=(t1+t1)&BN_MASK2; \\
61 c0=(c0+t1)&BN_MASK2; \\
62 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
63 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
65 #define sqr_add_c(a,i,c0,c1,c2) \\
66 sqr64(t1,t2,(a)[i]); \\
67 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
68 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
70 #define sqr_add_c2(a,i,j,c0,c1,c2) \\
71 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
74 void bn_mul_comba${num}(r,a,b)
86 $ret=&combas_mul("r","a","b",$num,"c1","c2","c3");
90 void bn_mul_comba${num2}(r,a,b)
102 $ret=&combas_mul("r","a","b",$num2,"c1","c2","c3");
106 void bn_sqr_comba${num}(r,a)
118 $ret=&combas_sqr("r","a",$num,"c1","c2","c3");
122 void bn_sqr_comba${num2}(r,a)
134 $ret=&combas_sqr("r","a",$num2,"c1","c2","c3");
142 print "\t$var=$val;\n";
148 return("${var}[$idx]");
160 local($a,$b,$c0,$c1,$c2,$num)=@_;
163 { printf("\tmul_add_c2($a,$b,$c0,$c1,$c2);\n"); }
165 { printf("\tmul_add_c($a,$b,$c0,$c1,$c2);\n"); }
170 local($a,$i,$j,$c0,$c1,$c2,$num)=@_;
173 { printf("\tsqr_add_c2($a,$i,$j,$c0,$c1,$c2);\n"); }
175 { printf("\tsqr_add_c($a,$i,$c0,$c1,$c2);\n"); }
180 local($r,$a,$b,$num,$c0,$c1,$c2)=@_;
181 local($i,$as,$ae,$bs,$be,$ai,$bi);
191 for ($i=0; $i<$tot; $i++)
198 #print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
199 for ($j=$bs; $j<$end; $j++)
209 @numa=reverse(@numa);
210 @numb=reverse(@numb);
214 for ($j=0; $j<=$#numa; $j++)
216 &bn_mad(&bn_ary($a,$numa[$j]),
217 &bn_ary($b,$numb[$j]),$c0,$c1,$c2,1);
219 &bn_str(&bn_ary($r,$i),$c0);
220 ($c0,$c1,$c2)=($c1,$c2,$c0);
222 $as++ if ($i < ($num-1));
223 $ae++ if ($i >= ($num-1));
225 $bs++ if ($i >= ($num-1));
226 $be++ if ($i < ($num-1));
228 &bn_str(&bn_ary($r,$i),$c0);
233 local($r,$a,$num,$c0,$c1,$c2)=@_;
234 local($i,$as,$ae,$bs,$be,$ai,$bi);
235 local($b,$tot,$end,$half);
245 for ($i=0; $i<$tot; $i++)
252 #print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
253 for ($j=$bs; $j<$end; $j++)
263 @numa=reverse(@numa);
264 @numb=reverse(@numb);
268 for ($j=0; $j <= $#numa; $j++)
270 if ($numa[$j] == $numb[$j])
271 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,1);}
273 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,2);}
275 &bn_str(&bn_ary($r,$i),$c0);
276 ($c0,$c1,$c2)=($c1,$c2,$c0);
278 $as++ if ($i < ($num-1));
279 $ae++ if ($i >= ($num-1));
281 $bs++ if ($i >= ($num-1));
282 $be++ if ($i < ($num-1));
284 &bn_str(&bn_ary($r,$i),$c0);