Also check for errors in x86_64-xlate.pl.
[oweals/openssl.git] / crypto / modes / asm / ghash-s390x.pl
index 8c3ce6928d0a5bffd3e7951753ebf646c36dbb5d..bd1c811b7055a2398dceb3324a6a8b983fc27972 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2010-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@openssl.org> for the OpenSSL
 # it's actually almost 2 times slower. Which is the reason why
 # KIMD-GHASH is not used in gcm_gmult_4bit.
 
-$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;
@@ -47,8 +57,7 @@ if ($flavour =~ /3[12]/) {
        $g="g";
 }
 
-while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
-open STDOUT,">$output";
+$output and open STDOUT,">$output";
 
 $softonly=0;
 
@@ -73,6 +82,8 @@ $rem_4bit="%r14";
 $sp="%r15";
 
 $code.=<<___;
+#include "s390x_arch.h"
+
 .text
 
 .globl gcm_gmult_4bit
@@ -81,16 +92,14 @@ gcm_gmult_4bit:
 ___
 $code.=<<___ if(!$softonly && 0);      # hardware is slow for single block...
        larl    %r1,OPENSSL_s390xcap_P
-       lg      %r0,0(%r1)
-       tmhl    %r0,0x4000      # check for message-security-assist
-       jz      .Lsoft_gmult
        lghi    %r0,0
-       lg      %r1,24(%r1)     # load second word of kimd capabilities vector
+       lg      %r1,S390X_KIMD+8(%r1)   # load second word of kimd capabilities
+                                       #  vector
        tmhh    %r1,0x4000      # check for function 65
        jz      .Lsoft_gmult
        stg     %r0,16($sp)     # arrange 16 bytes of zero input
        stg     %r0,24($sp)
-       lghi    %r0,65          # function 65
+       lghi    %r0,S390X_GHASH # function 65
        la      %r1,0($Xi)      # H lies right after Xi in gcm128_context
        la      $inp,16($sp)
        lghi    $len,16
@@ -119,16 +128,11 @@ gcm_ghash_4bit:
 ___
 $code.=<<___ if(!$softonly);
        larl    %r1,OPENSSL_s390xcap_P
-       lg      %r0,0(%r1)
-       tmhl    %r0,0x4000      # check for message-security-assist
-       jz      .Lsoft_ghash
-       lghi    %r0,0
-       la      %r1,16($sp)
-       .long   0xb93e0004      # kimd %r0,%r4
-       lg      %r1,24($sp)
-       tmhh    %r1,0x4000      # check for function 65
+       lg      %r0,S390X_KIMD+8(%r1)   # load second word of kimd capabilities
+                                       #  vector
+       tmhh    %r0,0x4000      # check for function 65
        jz      .Lsoft_ghash
-       lghi    %r0,65          # function 65
+       lghi    %r0,S390X_GHASH # function 65
        la      %r1,0($Xi)      # H lies right after Xi in gcm128_context
        .long   0xb93e0004      # kimd %r0,$inp
        brc     1,.-4           # pay attention to "partial completion"
@@ -151,7 +155,7 @@ $code.=<<___;
        lg      $Zhi,0+1($Xi)
        lghi    $tmp,0
 .Louter:
-       xg      $Zhi,0($inp)            # Xi ^= inp 
+       xg      $Zhi,0($inp)            # Xi ^= inp
        xg      $Zlo,8($inp)
        xgr     $Zhi,$tmp
        stg     $Zlo,8+1($Xi)
@@ -257,4 +261,4 @@ ___
 
 $code =~ s/\`([^\`]*)\`/eval $1/gem;
 print $code;
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";