1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sqr_words
5	{
6	local($name)=@_;
7
8	&function_begin($name,"");
9
10	&comment("");
11	$r="esi";
12	$a="edi";
13	$num="ebx";
14
15	&mov($r,&wparam(0));	#
16	&mov($a,&wparam(1));	#
17	&mov($num,&wparam(2));	#
18
19	&and($num,0xfffffff8);	# num / 8
20	&jz(&label("sw_finish"));
21
22	&set_label("sw_loop",0);
23	for ($i=0; $i<32; $i+=4)
24		{
25		&comment("Round $i");
26		&mov("eax",&DWP($i,$a,"",0)); 	# *a
27		 # XXX
28		&mul("eax");			# *a * *a
29		&mov(&DWP($i*2,$r,"",0),"eax");	#
30		 &mov(&DWP($i*2+4,$r,"",0),"edx");#
31		}
32
33	&comment("");
34	&add($a,32);
35	&add($r,64);
36	&sub($num,8);
37	&jnz(&label("sw_loop"));
38
39	&set_label("sw_finish",0);
40	&mov($num,&wparam(2));	# get num
41	&and($num,7);
42	&jz(&label("sw_end"));
43
44	for ($i=0; $i<7; $i++)
45		{
46		&comment("Tail Round $i");
47		&mov("eax",&DWP($i*4,$a,"",0));	# *a
48		 # XXX
49		&mul("eax");			# *a * *a
50		&mov(&DWP($i*8,$r,"",0),"eax");	#
51		 &dec($num) if ($i != 7-1);
52		&mov(&DWP($i*8+4,$r,"",0),"edx");
53		 &jz(&label("sw_end")) if ($i != 7-1);
54		}
55	&set_label("sw_end",0);
56
57	&function_end($name);
58	}
59
601;
61