md5/asm/md5-[586|x86_64].pl: +15% on Atom.
[oweals/openssl.git] / crypto / md5 / asm / md5-x86_64.pl
index b75cf3b7a48db879c59f9bed66c5c7843c7ceca3..f7dae275768bf09b49fea2a96622c21e3761f762 100755 (executable)
@@ -25,8 +25,8 @@ sub round1_step
        xor     $y,             %r11d           /* y ^ ... */
        lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
        and     $x,             %r11d           /* x & ... */
-       xor     $z,             %r11d           /* z ^ ... */
        mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
+       xor     $z,             %r11d           /* z ^ ... */
        add     %r11d,          $dst            /* dst += ... */
        rol     \$$s,           $dst            /* dst <<< s */
        mov     $y,             %r11d           /* (NEXT STEP) z' = $y */
@@ -43,13 +43,12 @@ EOF
 sub round2_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $code .= " mov     1*4(%rsi),      %r10d           /* (NEXT STEP) X[1] */\n" if ($pos == -1);
     $code .= " mov     %edx,           %r11d           /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
     $code .= " mov     %edx,           %r12d           /* (NEXT STEP) z' = %edx */\n" if ($pos == -1);
     $code .= <<EOF;
        not     %r11d                           /* not z */
-       lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
        and     $x,             %r12d           /* x & z */
+       lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
        and     $y,             %r11d           /* y & (not z) */
        mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
        or      %r11d,          %r12d           /* (y & (not z)) | (x & z) */
@@ -66,21 +65,31 @@ EOF
 #   %r10d = X[k_next]
 #   %r11d = y' (copy of y for the next step)
 # Each round3_step() takes about 4.2 clocks (8 instructions, 1.9 IPC)
+{ my $round3_alter=0;
 sub round3_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $code .= " mov     5*4(%rsi),      %r10d           /* (NEXT STEP) X[5] */\n" if ($pos == -1);
     $code .= " mov     %ecx,           %r11d           /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1);
     $code .= <<EOF;
        lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
-       mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
        xor     $z,             %r11d           /* z ^ ... */
+       mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
        xor     $x,             %r11d           /* x ^ ... */
        add     %r11d,          $dst            /* dst += ... */
+EOF
+    $code .= <<EOF if ($round3_alter);
        rol     \$$s,           $dst            /* dst <<< s */
        mov     $x,             %r11d           /* (NEXT STEP) y' = $x */
+EOF
+    $code .= <<EOF if (!$round3_alter);
+       mov     $x,             %r11d           /* (NEXT STEP) y' = $x */
+       rol     \$$s,           $dst            /* dst <<< s */
+EOF
+    $code .= <<EOF;
        add     $x,             $dst            /* dst += x */
 EOF
+    $round3_alter^=1;
+}
 }
 
 # round4_step() does:
@@ -91,16 +100,15 @@ EOF
 sub round4_step
 {
     my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_;
-    $code .= " mov     0*4(%rsi),      %r10d           /* (NEXT STEP) X[0] */\n" if ($pos == -1);
     $code .= " mov     \$0xffffffff,   %r11d\n" if ($pos == -1);
     $code .= " xor     %edx,           %r11d           /* (NEXT STEP) not z' = not %edx*/\n"
     if ($pos == -1);
     $code .= <<EOF;
        lea     $T_i($dst,%r10d),$dst           /* Const + dst + ... */
        or      $x,             %r11d           /* x | ... */
+       mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
        xor     $y,             %r11d           /* y ^ ... */
        add     %r11d,          $dst            /* dst += ... */
-       mov     $k_next*4(%rsi),%r10d           /* (NEXT STEP) X[$k_next] */
        mov     \$0xffffffff,   %r11d
        rol     \$$s,           $dst            /* dst <<< s */
        xor     $y,             %r11d           /* (NEXT STEP) not z' = not $y */
@@ -120,10 +128,10 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
 die "can't locate x86_64-xlate.pl";
 
 no warnings qw(uninitialized);
-open STDOUT,"| $^X $xlate $flavour $output";
+open OUT,"| \"$^X\" $xlate $flavour $output";
+*STDOUT=*OUT;
 
 $code .= <<EOF;
-.section .note.GNU-stack,"",\@progbits
 .text
 .align 16
 
@@ -179,7 +187,7 @@ round1_step( 0,'%ebx','%ecx','%edx','%eax','12','0x895cd7be','22');
 round1_step( 0,'%eax','%ebx','%ecx','%edx','13','0x6b901122', '7');
 round1_step( 0,'%edx','%eax','%ebx','%ecx','14','0xfd987193','12');
 round1_step( 0,'%ecx','%edx','%eax','%ebx','15','0xa679438e','17');
-round1_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x49b40821','22');
+round1_step( 1,'%ebx','%ecx','%edx','%eax', '1','0x49b40821','22');
 
 round2_step(-1,'%eax','%ebx','%ecx','%edx', '6','0xf61e2562', '5');
 round2_step( 0,'%edx','%eax','%ebx','%ecx','11','0xc040b340', '9');
@@ -196,7 +204,7 @@ round2_step( 0,'%ebx','%ecx','%edx','%eax','13','0x455a14ed','20');
 round2_step( 0,'%eax','%ebx','%ecx','%edx', '2','0xa9e3e905', '5');
 round2_step( 0,'%edx','%eax','%ebx','%ecx', '7','0xfcefa3f8', '9');
 round2_step( 0,'%ecx','%edx','%eax','%ebx','12','0x676f02d9','14');
-round2_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x8d2a4c8a','20');
+round2_step( 1,'%ebx','%ecx','%edx','%eax', '5','0x8d2a4c8a','20');
 
 round3_step(-1,'%eax','%ebx','%ecx','%edx', '8','0xfffa3942', '4');
 round3_step( 0,'%edx','%eax','%ebx','%ecx','11','0x8771f681','11');