perlasm/x86* update: support for 3 and 4 argument instructions.
[openssl.git] / crypto / perlasm / x86gas.pl
index 575b13325267ed4da700f5da0014cf34d5383e5c..6eab727fd4e87753161321e2afa926e5636dc9dc 100644 (file)
@@ -25,24 +25,20 @@ sub opsize()
 # expand opcode with size suffix;
 # prefix numeric constants with $;
 sub ::generic
-{ my($opcode,$dst,$src)=@_;
-  my($tmp,$suffix,@arg);
-
-    if (defined($src))
-    {  $src =~ s/^(e?[a-dsixphl]{2})$/%$1/o;
-       $src =~ s/^(x?mm[0-7])$/%$1/o;
-       $src =~ s/^(\-?[0-9]+)$/\$$1/o;
-       $src =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o;
-       push(@arg,$src);
-    }
-    if (defined($dst))
-    {  $dst =~ s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o;
-       $dst =~ s/^(x?mm[0-7])$/%$1/o;
-       $dst =~ s/^(\-?[0-9]+)$/\$$1/o          if(!defined($src));
-       $dst =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o     if(!defined($src));
-       push(@arg,$dst);
+{ my($opcode,@arg)=@_;
+  my($suffix,$dst,$src);
+
+    @arg=reverse(@arg);
+
+    for (@arg)
+    {  s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o;    # gp registers
+       s/^([xy]?mm[0-7])$/%$1/o;               # xmm/mmx registers
+       s/^(\-?[0-9]+)$/\$$1/o;                 # constants
+       s/^(\-?0x[0-9a-f]+)$/\$$1/o;            # constants
     }
 
+    $dst = $arg[$#arg]         if ($#arg>=0);
+    $src = $arg[$#arg-1]       if ($#arg>=1);
     if    ($dst =~ m/^%/o)     { $suffix=&opsize($dst); }
     elsif ($src =~ m/^%/o)     { $suffix=&opsize($src); }
     else                       { $suffix="l";           }
@@ -71,19 +67,6 @@ sub ::jmp_ptr        { &::generic("jmp","*$_[0]");   }
 
 *::bswap = sub { &::emit("bswap","%$_[0]");    } if (!$::i386);
 
-*::pshufw = sub
-{ my($dst,$src,$magic)=@_;
-    &::emit("pshufw","\$$magic","%$src","%$dst");
-};
-*::shld = sub
-{ my($dst,$src,$bits)=@_;
-    &::emit("shldl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
-};
-*::shrd = sub
-{ my($dst,$src,$bits)=@_;
-    &::emit("shrdl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
-};
-
 sub ::DWP
 { my($addr,$reg1,$reg2,$idx)=@_;
   my $ret="";
@@ -124,7 +107,7 @@ sub ::function_begin_B
 
     push(@out,".globl\t$func\n")       if ($global);
     if ($::coff)
-    {  push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
+    {  push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
     elsif (($::aout and !$::pic) or $::macosx)
     { }
     else
@@ -160,7 +143,7 @@ sub ::comment
        }
 
 sub ::external_label
-{   push(@out,".extern\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
+{   foreach(@_) { &::LABEL($_,$nmdecor.$_); }   }
 
 sub ::public_label
 {   push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
@@ -172,8 +155,7 @@ sub ::file_end
        else            { push (@out,"$tmp\n"); }
     }
     if ($::macosx)
-    {  grep {s/^\.extern\s+.*$//} @out;
-       if (%non_lazy_ptr)
+    {  if (%non_lazy_ptr)
        {   push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
            foreach $i (keys %non_lazy_ptr)
            {   push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n");   }
@@ -212,9 +194,9 @@ sub ::picmeup
            $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
        }
        else
-       {   &::lea($dst,&::DWP("${nmdecor}_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
+       {   &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
                            $base));
-           &::mov($dst,&::DWP("$nmdecor$sym\@GOT",$dst));
+           &::mov($dst,&::DWP("$sym\@GOT",$dst));
        }
     }
     else
@@ -259,4 +241,7 @@ ___
     }
 }
 
+sub ::dataseg
+{   push(@out,".data\n");   }
+
 1;