xref: /onnv-gate/usr/src/common/openssl/crypto/bn/asm/x86/sub.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_sub_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	$a="esi";
12*0Sstevel@tonic-gate	$b="edi";
13*0Sstevel@tonic-gate	$c="eax";
14*0Sstevel@tonic-gate	$r="ebx";
15*0Sstevel@tonic-gate	$tmp1="ecx";
16*0Sstevel@tonic-gate	$tmp2="edx";
17*0Sstevel@tonic-gate	$num="ebp";
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gate	&mov($r,&wparam(0));	# get r
20*0Sstevel@tonic-gate	 &mov($a,&wparam(1));	# get a
21*0Sstevel@tonic-gate	&mov($b,&wparam(2));	# get b
22*0Sstevel@tonic-gate	 &mov($num,&wparam(3));	# get num
23*0Sstevel@tonic-gate	&xor($c,$c);		# clear carry
24*0Sstevel@tonic-gate	 &and($num,0xfffffff8);	# num / 8
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate	&jz(&label("aw_finish"));
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate	&set_label("aw_loop",0);
29*0Sstevel@tonic-gate	for ($i=0; $i<8; $i++)
30*0Sstevel@tonic-gate		{
31*0Sstevel@tonic-gate		&comment("Round $i");
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate		&mov($tmp1,&DWP($i*4,$a,"",0)); 	# *a
34*0Sstevel@tonic-gate		 &mov($tmp2,&DWP($i*4,$b,"",0)); 	# *b
35*0Sstevel@tonic-gate		&sub($tmp1,$c);
36*0Sstevel@tonic-gate		 &mov($c,0);
37*0Sstevel@tonic-gate		&adc($c,$c);
38*0Sstevel@tonic-gate		 &sub($tmp1,$tmp2);
39*0Sstevel@tonic-gate		&adc($c,0);
40*0Sstevel@tonic-gate		 &mov(&DWP($i*4,$r,"",0),$tmp1); 	# *r
41*0Sstevel@tonic-gate		}
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate	&comment("");
44*0Sstevel@tonic-gate	&add($a,32);
45*0Sstevel@tonic-gate	 &add($b,32);
46*0Sstevel@tonic-gate	&add($r,32);
47*0Sstevel@tonic-gate	 &sub($num,8);
48*0Sstevel@tonic-gate	&jnz(&label("aw_loop"));
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate	&set_label("aw_finish",0);
51*0Sstevel@tonic-gate	&mov($num,&wparam(3));	# get num
52*0Sstevel@tonic-gate	&and($num,7);
53*0Sstevel@tonic-gate	 &jz(&label("aw_end"));
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate	for ($i=0; $i<7; $i++)
56*0Sstevel@tonic-gate		{
57*0Sstevel@tonic-gate		&comment("Tail Round $i");
58*0Sstevel@tonic-gate		&mov($tmp1,&DWP($i*4,$a,"",0));	# *a
59*0Sstevel@tonic-gate		 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60*0Sstevel@tonic-gate		&sub($tmp1,$c);
61*0Sstevel@tonic-gate		 &mov($c,0);
62*0Sstevel@tonic-gate		&adc($c,$c);
63*0Sstevel@tonic-gate		 &sub($tmp1,$tmp2);
64*0Sstevel@tonic-gate		&adc($c,0);
65*0Sstevel@tonic-gate		 &dec($num) if ($i != 6);
66*0Sstevel@tonic-gate		&mov(&DWP($i*4,$r,"",0),$tmp1);	# *a
67*0Sstevel@tonic-gate		 &jz(&label("aw_end")) if ($i != 6);
68*0Sstevel@tonic-gate		}
69*0Sstevel@tonic-gate	&set_label("aw_end",0);
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate#	&mov("eax",$c);		# $c is "eax"
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate	&function_end($name);
74*0Sstevel@tonic-gate	}
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate1;
77