sha/asm/sha512-armv8.pl: adapt for kernel use.
[openssl.git] / crypto / sha / asm / sha512-x86_64.pl
index 01698c40cfaa682edaef3b0a02eee1be5cd4d223..5a1cbcf0ca8d953776b33d04e0e616067de561b8 100755 (executable)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the OpenSSL license (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
@@ -34,7 +41,7 @@
 # level parallelism, on a given CPU implementation in this case.
 #
 # Special note on Intel EM64T. While Opteron CPU exhibits perfect
-# perfromance ratio of 1.5 between 64- and 32-bit flavors [see above],
+# performance ratio of 1.5 between 64- and 32-bit flavors [see above],
 # [currently available] EM64T CPUs apparently are far from it. On the
 # contrary, 64-bit version, sha512_block, is ~30% *slower* than 32-bit
 # sha256_block:-( This is presumably because 64-bit shifts/rotates
 # Sandy Bridge 17.4    14.2(+23%)  11.6(+50%(**))  11.2    8.10(+38%(**))
 # Ivy Bridge   12.6    10.5(+20%)  10.3(+22%)      8.17    7.22(+13%)
 # Haswell      12.2    9.28(+31%)  7.80(+56%)      7.66    5.40(+42%)
+# Skylake      11.4    9.03(+26%)  7.70(+48%)      7.25    5.20(+40%)
 # Bulldozer    21.1    13.6(+54%)  13.6(+54%(***)) 13.5    8.58(+57%)
 # VIA Nano     23.0    16.5(+39%)  -               14.7    -
 # Atom         23.0    18.9(+22%)  -               14.7    -
+# Silvermont   27.4    20.6(+33%)  -               17.5    -
+# Goldmont     18.9    14.3(+32%)  4.16(+350%)     12.0    -
 #
-# (*)  whichever best applicable;
+# (*)  whichever best applicable, including SHAEXT;
 # (**) switch from ror to shrd stands for fair share of improvement;
 # (***)        execution time is fully determined by remaining integer-only
 #      part, body_00_15; reducing the amount of SIMD instructions
@@ -123,7 +133,14 @@ if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
        $avx = ($1>=10) + ($1>=11);
 }
 
-open OUT,"| \"$^X\" $xlate $flavour $output";
+if (!$avx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9]\.[0-9]+)/) {
+       $avx = ($2>=3.0) + ($2>3.0);
+}
+
+$shaext=1;     ### set to zero if compiling for 1.0.1
+$avx=1         if (!$shaext && $avx);
+
+open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
 *STDOUT=*OUT;
 
 if ($output =~ /512/) {
@@ -259,7 +276,7 @@ $code.=<<___ if ($SZ==4 || $avx);
        mov     4(%r11),%r10d
        mov     8(%r11),%r11d
 ___
-$code.=<<___ if ($SZ==4);
+$code.=<<___ if ($SZ==4 && $shaext);
        test    \$`1<<29`,%r11d         # check for SHA
        jnz     _shaext_shortcut
 ___
@@ -518,7 +535,7 @@ ___
 ######################################################################
 # SIMD code paths
 #
-if ($SZ==4) {{{
+if ($SZ==4 && $shaext) {{{
 ######################################################################
 # Intel SHA Extensions implementation of SHA256 update function.
 #
@@ -1766,7 +1783,7 @@ if ($avx>1) {{
 ######################################################################
 # AVX2+BMI code path
 #
-my $a5=$SZ==4?"%esi":"%rsi";   # zap $inp 
+my $a5=$SZ==4?"%esi":"%rsi";   # zap $inp
 my $PUSH8=8*2*$SZ;
 use integer;
 
@@ -2255,7 +2272,9 @@ $code.=<<___;
        pop     %rsi
        ret
 .size  se_handler,.-se_handler
+___
 
+$code.=<<___ if ($SZ==4 && $shaext);
 .type  shaext_handler,\@abi-omnipotent
 .align 16
 shaext_handler:
@@ -2288,17 +2307,21 @@ shaext_handler:
 
        jmp     .Lin_prologue
 .size  shaext_handler,.-shaext_handler
+___
 
+$code.=<<___;
 .section       .pdata
 .align 4
        .rva    .LSEH_begin_$func
        .rva    .LSEH_end_$func
        .rva    .LSEH_info_$func
 ___
-$code.=<<___ if ($SZ==4);
+$code.=<<___ if ($SZ==4 && $shaext);
        .rva    .LSEH_begin_${func}_shaext
        .rva    .LSEH_end_${func}_shaext
        .rva    .LSEH_info_${func}_shaext
+___
+$code.=<<___ if ($SZ==4);
        .rva    .LSEH_begin_${func}_ssse3
        .rva    .LSEH_end_${func}_ssse3
        .rva    .LSEH_info_${func}_ssse3
@@ -2326,10 +2349,12 @@ $code.=<<___;
        .rva    se_handler
        .rva    .Lprologue,.Lepilogue                   # HandlerData[]
 ___
-$code.=<<___ if ($SZ==4);
+$code.=<<___ if ($SZ==4 && $shaext);
 .LSEH_info_${func}_shaext:
        .byte   9,0,0,0
        .rva    shaext_handler
+___
+$code.=<<___ if ($SZ==4);
 .LSEH_info_${func}_ssse3:
        .byte   9,0,0,0
        .rva    se_handler