2 # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
9 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10 push(@INC,"${dir}","${dir}../../perlasm");
14 open STDOUT,">$output";
16 &asm_init($ARGV[0],$0);
18 &bn_mul_comba("bn_mul_comba8",8);
19 &bn_mul_comba("bn_mul_comba4",4);
20 &bn_sqr_comba("bn_sqr_comba8",8);
21 &bn_sqr_comba("bn_sqr_comba4",4);
29 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
31 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
32 # words, and 1 if load return value
34 &comment("mul a[$ai]*b[$bi]");
36 # "eax" and "edx" will always be pre-loaded.
37 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
38 # &mov("edx",&DWP($bi*4,$b,"",0));
42 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
43 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
46 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
47 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
50 # is pos > 1, it means it is the last loop
51 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
52 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
57 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
59 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
60 # words, and 1 if load return value
62 &comment("sqr a[$ai]*a[$bi]");
64 # "eax" and "edx" will always be pre-loaded.
65 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
66 # &mov("edx",&DWP($bi*4,$b,"",0));
73 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
76 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
79 # is pos > 1, it means it is the last loop
80 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
81 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
86 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
88 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
89 # words, and 1 if load return value
91 &comment("sqr a[$ai]*a[$bi]");
93 # "eax" and "edx" will always be pre-loaded.
94 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
95 # &mov("edx",&DWP($bi*4,$a,"",0));
108 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
109 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
111 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
112 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
118 local($name,$num)=@_;
119 local($a,$b,$c0,$c1,$c2);
120 local($i,$as,$ae,$bs,$be,$ai,$bi);
123 &function_begin_B($name,"");
145 &mov("eax",&DWP(0,$a,"",0)); # load the first word
147 &mov("edx",&DWP(0,$b,"",0)); # load the first second
149 for ($i=0; $i<$tot; $i++)
155 &comment("################## Calculate word $i");
157 for ($j=$bs; $j<$end; $j++)
159 &xor($c2,$c2) if ($j == $bs);
163 $v=2 if (($i+1) == $tot);
174 $na=$as+($i < ($num-1));
175 $nb=$bs+($i >= ($num-1));
177 #printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
178 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
181 &comment("saved r[$i]");
182 # &mov("eax",&wparam(0));
183 # &mov(&DWP($i*4,"eax","",0),$c0);
184 ($c0,$c1,$c2)=($c1,$c2,$c0);
189 $as++ if ($i < ($num-1));
190 $ae++ if ($i >= ($num-1));
192 $bs++ if ($i >= ($num-1));
193 $be++ if ($i < ($num-1));
195 &comment("save r[$i]");
196 # &mov("eax",&wparam(0));
197 &mov(&DWP($i*4,"eax","",0),$c0);
204 &function_end_B($name);
209 local($name,$num)=@_;
210 local($r,$a,$c0,$c1,$c2)=@_;
211 local($i,$as,$ae,$bs,$be,$ai,$bi);
212 local($b,$tot,$end,$half);
214 &function_begin_B($name,"");
230 &mov("eax",&DWP(0,$a,"",0)); # load the first word
238 for ($i=0; $i<$tot; $i++)
244 &comment("############### Calculate word $i");
245 for ($j=$bs; $j<$end; $j++)
247 &xor($c2,$c2) if ($j == $bs);
248 if (($ai-1) < ($bi+1))
251 $v=2 if ($i+1) == $tot;
262 $na=$as+($i < ($num-1));
263 $nb=$bs+($i >= ($num-1));
267 &sqr_add_c($r,$a,$ai,$bi,
268 $c0,$c1,$c2,$v,$i,$na,$nb);
272 &sqr_add_c2($r,$a,$ai,$bi,
273 $c0,$c1,$c2,$v,$i,$na,$nb);
277 &comment("saved r[$i]");
278 #&mov(&DWP($i*4,$r,"",0),$c0);
279 ($c0,$c1,$c2)=($c1,$c2,$c0);
285 $as++ if ($i < ($num-1));
286 $ae++ if ($i >= ($num-1));
288 $bs++ if ($i >= ($num-1));
289 $be++ if ($i < ($num-1));
291 &mov(&DWP($i*4,$r,"",0),$c0);
297 &function_end_B($name);