2 # Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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");
13 $output = pop and open STDOUT,">$output";
17 &bn_mul_comba("bn_mul_comba8",8);
18 &bn_mul_comba("bn_mul_comba4",4);
19 &bn_sqr_comba("bn_sqr_comba8",8);
20 &bn_sqr_comba("bn_sqr_comba4",4);
24 close STDOUT or die "error closing STDOUT: $!";
28 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
30 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
31 # words, and 1 if load return value
33 &comment("mul a[$ai]*b[$bi]");
35 # "eax" and "edx" will always be pre-loaded.
36 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
37 # &mov("edx",&DWP($bi*4,$b,"",0));
41 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
42 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
45 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # load next b
46 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # load next b
49 # is pos > 1, it means it is the last loop
50 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
51 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next a
56 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
58 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
59 # words, and 1 if load return value
61 &comment("sqr a[$ai]*a[$bi]");
63 # "eax" and "edx" will always be pre-loaded.
64 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
65 # &mov("edx",&DWP($bi*4,$b,"",0));
72 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
75 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
78 # is pos > 1, it means it is the last loop
79 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
80 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
85 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
87 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
88 # words, and 1 if load return value
90 &comment("sqr a[$ai]*a[$bi]");
92 # "eax" and "edx" will always be pre-loaded.
93 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
94 # &mov("edx",&DWP($bi*4,$a,"",0));
107 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
108 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
110 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
111 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
117 local($name,$num)=@_;
118 local($a,$b,$c0,$c1,$c2);
119 local($i,$as,$ae,$bs,$be,$ai,$bi);
122 &function_begin_B($name,"");
144 &mov("eax",&DWP(0,$a,"",0)); # load the first word
146 &mov("edx",&DWP(0,$b,"",0)); # load the first second
148 for ($i=0; $i<$tot; $i++)
154 &comment("################## Calculate word $i");
156 for ($j=$bs; $j<$end; $j++)
158 &xor($c2,$c2) if ($j == $bs);
162 $v=2 if (($i+1) == $tot);
173 $na=$as+($i < ($num-1));
174 $nb=$bs+($i >= ($num-1));
176 #printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
177 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
180 &comment("saved r[$i]");
181 # &mov("eax",&wparam(0));
182 # &mov(&DWP($i*4,"eax","",0),$c0);
183 ($c0,$c1,$c2)=($c1,$c2,$c0);
188 $as++ if ($i < ($num-1));
189 $ae++ if ($i >= ($num-1));
191 $bs++ if ($i >= ($num-1));
192 $be++ if ($i < ($num-1));
194 &comment("save r[$i]");
195 # &mov("eax",&wparam(0));
196 &mov(&DWP($i*4,"eax","",0),$c0);
203 &function_end_B($name);
208 local($name,$num)=@_;
209 local($r,$a,$c0,$c1,$c2)=@_;
210 local($i,$as,$ae,$bs,$be,$ai,$bi);
211 local($b,$tot,$end,$half);
213 &function_begin_B($name,"");
229 &mov("eax",&DWP(0,$a,"",0)); # load the first word
237 for ($i=0; $i<$tot; $i++)
243 &comment("############### Calculate word $i");
244 for ($j=$bs; $j<$end; $j++)
246 &xor($c2,$c2) if ($j == $bs);
247 if (($ai-1) < ($bi+1))
250 $v=2 if ($i+1) == $tot;
261 $na=$as+($i < ($num-1));
262 $nb=$bs+($i >= ($num-1));
266 &sqr_add_c($r,$a,$ai,$bi,
267 $c0,$c1,$c2,$v,$i,$na,$nb);
271 &sqr_add_c2($r,$a,$ai,$bi,
272 $c0,$c1,$c2,$v,$i,$na,$nb);
276 &comment("saved r[$i]");
277 #&mov(&DWP($i*4,$r,"",0),$c0);
278 ($c0,$c1,$c2)=($c1,$c2,$c0);
284 $as++ if ($i < ($num-1));
285 $ae++ if ($i >= ($num-1));
287 $bs++ if ($i >= ($num-1));
288 $be++ if ($i < ($num-1));
290 &mov(&DWP($i*4,$r,"",0),$c0);
296 &function_end_B($name);