Also check for errors in x86_64-xlate.pl.
[oweals/openssl.git] / crypto / sha / asm / sha512-s390x.pl
index 079a3fc78ab4fdaa82a6cc0aa6d29aa4c4f02fb9..5c6786d85c07c1080e50f2aee1b45fe9a96c09f9 100644 (file)
@@ -1,7 +1,14 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
 
 # ====================================================================
-# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
 # project. The module is, however, dual licensed under OpenSSL and
 # CRYPTOGAMS licenses depending on where you obtain it. For further
 # details see http://www.openssl.org/~appro/cryptogams/.
 # instructions and achieve "64-bit" performance even in 31-bit legacy
 # application context. The feature is not specific to any particular
 # processor, as long as it's "z-CPU". Latter implies that the code
-# remains z/Architecture specific. On z900 SHA256 was measured to
+# remains z/Architecture specific. On z990 SHA256 was measured to
 # perform 2.4x and SHA512 - 13x better than code generated by gcc 4.3.
 
-$flavour = shift;
+# $output is the last argument if it looks like a file (it has an extension)
+# $flavour is the first argument if it doesn't look like a file
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
 
 if ($flavour =~ /3[12]/) {
        $SIZE_T=4;
@@ -64,7 +74,6 @@ $tbl="%r13";
 $T1="%r14";
 $sp="%r15";
 
-while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
 open STDOUT,">$output";
 
 if ($output =~ /512/) {
@@ -163,6 +172,8 @@ ___
 }
 
 $code.=<<___;
+#include "s390x_arch.h"
+
 .text
 .align 64
 .type  $Table,\@object
@@ -237,13 +248,7 @@ $Func:
 ___
 $code.=<<___ if ($kimdfunc);
        larl    %r1,OPENSSL_s390xcap_P
-       lg      %r0,0(%r1)
-       tmhl    %r0,0x4000      # check for message-security assist
-       jz      .Lsoftware
-       lghi    %r0,0
-       la      %r1,`2*$SIZE_T`($sp)
-       .long   0xb93e0002      # kimd %r0,%r2
-       lg      %r0,`2*$SIZE_T`($sp)
+       lg      %r0,S390X_KIMD(%r1)     # check kimd capabilities
        tmhh    %r0,`0x8000>>$kimdfunc`
        jz      .Lsoftware
        lghi    %r0,$kimdfunc
@@ -307,11 +312,10 @@ $code.=<<___;
        cl${g}  $inp,`$frame+4*$SIZE_T`($sp)
        jne     .Lloop
 
-       lm${g}  %r6,%r15,`$frame+6*$SIZE_T`($sp)        
+       lm${g}  %r6,%r15,`$frame+6*$SIZE_T`($sp)
        br      %r14
 .size  $Func,.-$Func
 .string        "SHA${label} block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
-.comm  OPENSSL_s390xcap_P,16,8
 ___
 
 $code =~ s/\`([^\`]*)\`/eval $1/gem;
@@ -319,4 +323,4 @@ $code =~ s/\`([^\`]*)\`/eval $1/gem;
 $code =~ s/(srlg\s+)(%r[0-9]+),/$1$2,$2,/gm;
 
 print $code;
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";