3 $0 =~ m/(.*[\/\\])[^\
/\\]+$/; $dir=$1;
4 push(@INC,"${dir}","${dir}../../perlasm");
7 &asm_init
($ARGV[0],$0);
9 &bn_mul_comba
("bn_mul_comba8",8);
10 &bn_mul_comba
("bn_mul_comba4",4);
11 &bn_sqr_comba
("bn_sqr_comba8",8);
12 &bn_sqr_comba
("bn_sqr_comba4",4);
18 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
20 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
21 # words, and 1 if load return value
23 &comment
("mul a[$ai]*b[$bi]");
25 # "eax" and "edx" will always be pre-loaded.
26 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
27 # &mov("edx",&DWP($bi*4,$b,"",0));
31 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 0; # laod next a
32 &mov
("eax",&wparam
(0)) if $pos > 0; # load r[]
35 &mov
("edx",&DWP
(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
36 &mov
("edx",&DWP
(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
39 # is pos > 1, it means it is the last loop
40 &mov
(&DWP
($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
41 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 1; # laod next a
46 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
48 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
49 # words, and 1 if load return value
51 &comment
("sqr a[$ai]*a[$bi]");
53 # "eax" and "edx" will always be pre-loaded.
54 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
55 # &mov("edx",&DWP($bi*4,$b,"",0));
62 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 0; # load next a
65 &mov
("edx",&DWP
(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
68 # is pos > 1, it means it is the last loop
69 &mov
(&DWP
($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
70 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 1; # load next b
75 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
77 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
78 # words, and 1 if load return value
80 &comment
("sqr a[$ai]*a[$bi]");
82 # "eax" and "edx" will always be pre-loaded.
83 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
84 # &mov("edx",&DWP($bi*4,$a,"",0));
97 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 0; # load next a
98 &mov
("eax",&DWP
(($na)*4,$a,"",0)) if $pos == 1; # load next b
100 &mov
(&DWP
($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
101 &mov
("edx",&DWP
(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
107 local($name,$num)=@_;
108 local($a,$b,$c0,$c1,$c2);
109 local($i,$as,$ae,$bs,$be,$ai,$bi);
112 &function_begin_B
($name,"");
134 &mov
("eax",&DWP
(0,$a,"",0)); # load the first word
136 &mov
("edx",&DWP
(0,$b,"",0)); # load the first second
138 for ($i=0; $i<$tot; $i++)
144 &comment
("################## Calculate word $i");
146 for ($j=$bs; $j<$end; $j++)
148 &xor($c2,$c2) if ($j == $bs);
152 $v=2 if (($i+1) == $tot);
163 $na=$as+($i < ($num-1));
164 $nb=$bs+($i >= ($num-1));
166 #printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
167 &mul_add_c
($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
170 &comment
("saved r[$i]");
171 # &mov("eax",&wparam(0));
172 # &mov(&DWP($i*4,"eax","",0),$c0);
173 ($c0,$c1,$c2)=($c1,$c2,$c0);
178 $as++ if ($i < ($num-1));
179 $ae++ if ($i >= ($num-1));
181 $bs++ if ($i >= ($num-1));
182 $be++ if ($i < ($num-1));
184 &comment
("save r[$i]");
185 # &mov("eax",&wparam(0));
186 &mov
(&DWP
($i*4,"eax","",0),$c0);
193 &function_end_B
($name);
198 local($name,$num)=@_;
199 local($r,$a,$c0,$c1,$c2)=@_;
200 local($i,$as,$ae,$bs,$be,$ai,$bi);
201 local($b,$tot,$end,$half);
203 &function_begin_B
($name,"");
219 &mov
("eax",&DWP
(0,$a,"",0)); # load the first word
227 for ($i=0; $i<$tot; $i++)
233 &comment
("############### Calculate word $i");
234 for ($j=$bs; $j<$end; $j++)
236 &xor($c2,$c2) if ($j == $bs);
237 if (($ai-1) < ($bi+1))
240 $v=2 if ($i+1) == $tot;
251 $na=$as+($i < ($num-1));
252 $nb=$bs+($i >= ($num-1));
256 &sqr_add_c
($r,$a,$ai,$bi,
257 $c0,$c1,$c2,$v,$i,$na,$nb);
261 &sqr_add_c2
($r,$a,$ai,$bi,
262 $c0,$c1,$c2,$v,$i,$na,$nb);
266 &comment
("saved r[$i]");
267 #&mov(&DWP($i*4,$r,"",0),$c0);
268 ($c0,$c1,$c2)=($c1,$c2,$c0);
274 $as++ if ($i < ($num-1));
275 $ae++ if ($i >= ($num-1));
277 $bs++ if ($i >= ($num-1));
278 $be++ if ($i < ($num-1));
280 &mov
(&DWP
($i*4,$r,"",0),$c0);
286 &function_end_B
($name);