1*0Sstevel@tonic-gate#!/usr/local/bin/perl 2*0Sstevel@tonic-gate# x86 assember 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gatesub bn_mul_add_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="ebp"; 15*0Sstevel@tonic-gate $r="edi"; 16*0Sstevel@tonic-gate $c="esi"; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate &xor($c,$c); # clear carry 19*0Sstevel@tonic-gate &mov($r,&wparam(0)); # 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gate &mov("ecx",&wparam(2)); # 22*0Sstevel@tonic-gate &mov($a,&wparam(1)); # 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gate &and("ecx",0xfffffff8); # num / 8 25*0Sstevel@tonic-gate &mov($w,&wparam(3)); # 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate &push("ecx"); # Up the stack for a tmp variable 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate &jz(&label("maw_finish")); 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate &set_label("maw_loop",0); 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate &mov(&swtmp(0),"ecx"); # 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate for ($i=0; $i<32; $i+=4) 36*0Sstevel@tonic-gate { 37*0Sstevel@tonic-gate &comment("Round $i"); 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate &mov("eax",&DWP($i,$a,"",0)); # *a 40*0Sstevel@tonic-gate &mul($w); # *a * w 41*0Sstevel@tonic-gate &add("eax",$c); # L(t)+= *r 42*0Sstevel@tonic-gate &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r 43*0Sstevel@tonic-gate &adc("edx",0); # H(t)+=carry 44*0Sstevel@tonic-gate &add("eax",$c); # L(t)+=c 45*0Sstevel@tonic-gate &adc("edx",0); # H(t)+=carry 46*0Sstevel@tonic-gate &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); 47*0Sstevel@tonic-gate &mov($c,"edx"); # c= H(t); 48*0Sstevel@tonic-gate } 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate &comment(""); 51*0Sstevel@tonic-gate &mov("ecx",&swtmp(0)); # 52*0Sstevel@tonic-gate &add($a,32); 53*0Sstevel@tonic-gate &add($r,32); 54*0Sstevel@tonic-gate &sub("ecx",8); 55*0Sstevel@tonic-gate &jnz(&label("maw_loop")); 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate &set_label("maw_finish",0); 58*0Sstevel@tonic-gate &mov("ecx",&wparam(2)); # get num 59*0Sstevel@tonic-gate &and("ecx",7); 60*0Sstevel@tonic-gate &jnz(&label("maw_finish2")); # helps branch prediction 61*0Sstevel@tonic-gate &jmp(&label("maw_end")); 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate &set_label("maw_finish2",1); 64*0Sstevel@tonic-gate for ($i=0; $i<7; $i++) 65*0Sstevel@tonic-gate { 66*0Sstevel@tonic-gate &comment("Tail Round $i"); 67*0Sstevel@tonic-gate &mov("eax",&DWP($i*4,$a,"",0));# *a 68*0Sstevel@tonic-gate &mul($w); # *a * w 69*0Sstevel@tonic-gate &add("eax",$c); # L(t)+=c 70*0Sstevel@tonic-gate &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r 71*0Sstevel@tonic-gate &adc("edx",0); # H(t)+=carry 72*0Sstevel@tonic-gate &add("eax",$c); 73*0Sstevel@tonic-gate &adc("edx",0); # H(t)+=carry 74*0Sstevel@tonic-gate &dec("ecx") if ($i != 7-1); 75*0Sstevel@tonic-gate &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t); 76*0Sstevel@tonic-gate &mov($c,"edx"); # c= H(t); 77*0Sstevel@tonic-gate &jz(&label("maw_end")) if ($i != 7-1); 78*0Sstevel@tonic-gate } 79*0Sstevel@tonic-gate &set_label("maw_end",0); 80*0Sstevel@tonic-gate &mov("eax",$c); 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate &pop("ecx"); # clear variable from 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate &function_end($name); 85*0Sstevel@tonic-gate } 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate1; 88