3 push(@INC,"perlasm","../../perlasm");
6 &asm_init($ARGV[0],$0);
8 &bn_mul_comba("bn_mul_comba8",8);
9 &bn_mul_comba("bn_mul_comba4",4);
10 &bn_sqr_comba("bn_sqr_comba8",8);
11 &bn_sqr_comba("bn_sqr_comba4",4);
17 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
19 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
20 # words, and 1 if load return value
22 &comment("mul a[$ai]*b[$bi]");
24 # "eax" and "edx" will always be pre-loaded.
25 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
26 # &mov("edx",&DWP($bi*4,$b,"",0));
30 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
31 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
34 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
35 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
38 # is pos > 1, it means it is the last loop
39 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
40 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
45 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
47 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
48 # words, and 1 if load return value
50 &comment("sqr a[$ai]*a[$bi]");
52 # "eax" and "edx" will always be pre-loaded.
53 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
54 # &mov("edx",&DWP($bi*4,$b,"",0));
61 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
64 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
67 # is pos > 1, it means it is the last loop
68 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
69 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
74 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
76 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
77 # words, and 1 if load return value
79 &comment("sqr a[$ai]*a[$bi]");
81 # "eax" and "edx" will always be pre-loaded.
82 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
83 # &mov("edx",&DWP($bi*4,$a,"",0));
96 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
97 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
99 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
100 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
106 local($name,$num)=@_;
107 local($a,$b,$c0,$c1,$c2);
108 local($i,$as,$ae,$bs,$be,$ai,$bi);
111 &function_begin_B($name,"");
133 &mov("eax",&DWP(0,$a,"",0)); # load the first word
135 &mov("edx",&DWP(0,$b,"",0)); # load the first second
137 for ($i=0; $i<$tot; $i++)
143 &comment("################## Calculate word $i");
145 for ($j=$bs; $j<$end; $j++)
147 &xor($c2,$c2) if ($j == $bs);
151 $v=2 if (($i+1) == $tot);
162 $na=$as+($i < ($num-1));
163 $nb=$bs+($i >= ($num-1));
165 #printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
166 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
169 &comment("saved r[$i]");
170 # &mov("eax",&wparam(0));
171 # &mov(&DWP($i*4,"eax","",0),$c0);
172 ($c0,$c1,$c2)=($c1,$c2,$c0);
177 $as++ if ($i < ($num-1));
178 $ae++ if ($i >= ($num-1));
180 $bs++ if ($i >= ($num-1));
181 $be++ if ($i < ($num-1));
183 &comment("save r[$i]");
184 # &mov("eax",&wparam(0));
185 &mov(&DWP($i*4,"eax","",0),$c0);
192 &function_end_B($name);
197 local($name,$num)=@_;
198 local($r,$a,$c0,$c1,$c2)=@_;
199 local($i,$as,$ae,$bs,$be,$ai,$bi);
200 local($b,$tot,$end,$half);
202 &function_begin_B($name,"");
218 &mov("eax",&DWP(0,$a,"",0)); # load the first word
226 for ($i=0; $i<$tot; $i++)
232 &comment("############### Calculate word $i");
233 for ($j=$bs; $j<$end; $j++)
235 &xor($c2,$c2) if ($j == $bs);
236 if (($ai-1) < ($bi+1))
239 $v=2 if ($i+1) == $tot;
250 $na=$as+($i < ($num-1));
251 $nb=$bs+($i >= ($num-1));
255 &sqr_add_c($r,$a,$ai,$bi,
256 $c0,$c1,$c2,$v,$i,$na,$nb);
260 &sqr_add_c2($r,$a,$ai,$bi,
261 $c0,$c1,$c2,$v,$i,$na,$nb);
265 &comment("saved r[$i]");
266 #&mov(&DWP($i*4,$r,"",0),$c0);
267 ($c0,$c1,$c2)=($c1,$c2,$c0);
273 $as++ if ($i < ($num-1));
274 $ae++ if ($i >= ($num-1));
276 $bs++ if ($i >= ($num-1));
277 $be++ if ($i < ($num-1));
279 &mov(&DWP($i*4,$r,"",0),$c0);
285 &function_end_B($name);