Home | History | Annotate | Download | only in x86
      1 #!/usr/local/bin/perl
      2 # x86 assember
      3 
      4 sub bn_mul_words
      5 	{
      6 	local($name)=@_;
      7 
      8 	&function_begin($name,"");
      9 
     10 	&comment("");
     11 	$Low="eax";
     12 	$High="edx";
     13 	$a="ebx";
     14 	$w="ecx";
     15 	$r="edi";
     16 	$c="esi";
     17 	$num="ebp";
     18 
     19 	&xor($c,$c);		# clear carry
     20 	&mov($r,&wparam(0));	#
     21 	&mov($a,&wparam(1));	#
     22 	&mov($num,&wparam(2));	#
     23 	&mov($w,&wparam(3));	#
     24 
     25 	&and($num,0xfffffff8);	# num / 8
     26 	&jz(&label("mw_finish"));
     27 
     28 	&set_label("mw_loop",0);
     29 	for ($i=0; $i<32; $i+=4)
     30 		{
     31 		&comment("Round $i");
     32 
     33 		 &mov("eax",&DWP($i,$a,"",0)); 	# *a
     34 		&mul($w);			# *a * w
     35 		&add("eax",$c);			# L(t)+=c
     36 		 # XXX
     37 
     38 		&adc("edx",0);			# H(t)+=carry
     39 		 &mov(&DWP($i,$r,"",0),"eax");	# *r= L(t);
     40 
     41 		&mov($c,"edx");			# c=  H(t);
     42 		}
     43 
     44 	&comment("");
     45 	&add($a,32);
     46 	&add($r,32);
     47 	&sub($num,8);
     48 	&jz(&label("mw_finish"));
     49 	&jmp(&label("mw_loop"));
     50 
     51 	&set_label("mw_finish",0);
     52 	&mov($num,&wparam(2));	# get num
     53 	&and($num,7);
     54 	&jnz(&label("mw_finish2"));
     55 	&jmp(&label("mw_end"));
     56 
     57 	&set_label("mw_finish2",1);
     58 	for ($i=0; $i<7; $i++)
     59 		{
     60 		&comment("Tail Round $i");
     61 		 &mov("eax",&DWP($i*4,$a,"",0));# *a
     62 		&mul($w);			# *a * w
     63 		&add("eax",$c);			# L(t)+=c
     64 		 # XXX
     65 		&adc("edx",0);			# H(t)+=carry
     66 		 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
     67 		&mov($c,"edx");			# c=  H(t);
     68 		 &dec($num) if ($i != 7-1);
     69 		&jz(&label("mw_end")) if ($i != 7-1);
     70 		}
     71 	&set_label("mw_end",0);
     72 	&mov("eax",$c);
     73 
     74 	&function_end($name);
     75 	}
     76 
     77 1;
     78