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