x86[_64]cpuid.pl: add low-level RDSEED.
authorAndy Polyakov <appro@openssl.org>
Fri, 14 Feb 2014 16:24:12 +0000 (17:24 +0100)
committerAndy Polyakov <appro@openssl.org>
Fri, 14 Feb 2014 16:24:12 +0000 (17:24 +0100)
crypto/perlasm/x86_64-xlate.pl
crypto/perlasm/x86asm.pl
crypto/x86_64cpuid.pl
crypto/x86cpuid.pl

index ed74b85ac96a40db973f952c52e6adbafe23b982..4dd7f5252d7f701d2894e1706ae359333efaf05e 100755 (executable)
@@ -778,6 +778,19 @@ my $rdrand = sub {
     }
 };
 
     }
 };
 
+my $rdseed = sub {
+    if (shift =~ /%[er](\w+)/) {
+      my @opcode=();
+      my $dst=$1;
+       if ($dst !~ /[0-9]+/) { $dst = $regrm{"%e$dst"}; }
+       rex(\@opcode,0,$1,8);
+       push @opcode,0x0f,0xc7,0xf8|($dst&7);
+       @opcode;
+    } else {
+       ();
+    }
+};
+
 sub rxb {
  local *opcode=shift;
  my ($dst,$src1,$src2,$rxb)=@_;
 sub rxb {
  local *opcode=shift;
  my ($dst,$src1,$src2,$rxb)=@_;
index 17abf9229779a3f7c3a3837565ac9a054b6fb1da..dcbc73851603fe53f57516cfec2a87de52b07f30 100644 (file)
@@ -131,6 +131,14 @@ sub ::rdrand
     {  &::generic("rdrand",@_);        }
 }
 
     {  &::generic("rdrand",@_);        }
 }
 
+sub ::rdseed
+{ my ($dst)=@_;
+    if ($dst =~ /(e[a-dsd][ixp])/)
+    {  &::data_byte(0x0f,0xc7,0xf8|$regrm{$dst});      }
+    else
+    {  &::generic("rdrand",@_);        }
+}
+
 sub rxb {
  local *opcode=shift;
  my ($dst,$src1,$src2,$rxb)=@_;
 sub rxb {
  local *opcode=shift;
  my ($dst,$src1,$src2,$rxb)=@_;
index 0cf68f1360ef2e9b49960c64f038ec78435e7a4a..db5aa4aa361d4f6cf46a378bb45bff80ecdd464c 100644 (file)
@@ -379,6 +379,21 @@ OPENSSL_ia32_rdrand:
        cmove   %rcx,%rax
        ret
 .size  OPENSSL_ia32_rdrand,.-OPENSSL_ia32_rdrand
        cmove   %rcx,%rax
        ret
 .size  OPENSSL_ia32_rdrand,.-OPENSSL_ia32_rdrand
+
+.globl OPENSSL_ia32_rdseed
+.type  OPENSSL_ia32_rdseed,\@abi-omnipotent
+.align 16
+OPENSSL_ia32_rdseed:
+       mov     \$8,%ecx
+.Loop_rdseed:
+       rdseed  %rax
+       jc      .Lbreak_rdseed
+       loop    .Loop_rdseed
+.Lbreak_rdseed:
+       cmp     \$0,%rax
+       cmove   %rcx,%rax
+       ret
+.size  OPENSSL_ia32_rdseed,.-OPENSSL_ia32_rdseed
 ___
 
 close STDOUT;  # flush
 ___
 
 close STDOUT;  # flush
index ef1216a8b2ed4cc8ee5fc35667114ce36017b1aa..86772329bc7bd5a2492e59fdddb25e7901b0f6c2 100644 (file)
@@ -469,6 +469,18 @@ my $max = "ebp";
        &ret    ();
 &function_end_B("OPENSSL_ia32_rdrand");
 
        &ret    ();
 &function_end_B("OPENSSL_ia32_rdrand");
 
+&function_begin_B("OPENSSL_ia32_rdseed");
+       &mov    ("ecx",8);
+&set_label("loop");
+       &rdseed ("eax");
+       &jc     (&label("break"));
+       &loop   (&label("loop"));
+&set_label("break");
+       &cmp    ("eax",0);
+       &cmove  ("eax","ecx");
+       &ret    ();
+&function_end_B("OPENSSL_ia32_rdseed");
+
 &initseg("OPENSSL_cpuid_setup");
 
 &hidden("OPENSSL_cpuid_setup");
 &initseg("OPENSSL_cpuid_setup");
 
 &hidden("OPENSSL_cpuid_setup");