Skip to content

Commit

Permalink
Unify all assembler file generators
Browse files Browse the repository at this point in the history
They now generally conform to the following argument sequence:

    script.pl "$(PERLASM_SCHEME)" [ C preprocessor arguments ... ] \
              $(PROCESSOR) <output file>

However, in the spirit of being able to use these scripts manually,
they also allow for no argument, or for only the flavour, or for only
the output file.  This is done by only using the last argument as
output file if it's a file (it has an extension), and only using the
first argument as flavour if it isn't a file (it doesn't have an
extension).

While we're at it, we make all $xlate calls the same, i.e. the $output
argument is always quoted, and we always die on error when trying to
start $xlate.

There's a perl lesson in this, regarding operator priority...

This will always succeed, even when it fails:

    open FOO, "something" || die "ERR: $!";

The reason is that '||' has higher priority than list operators (a
function is essentially a list operator and gobbles up everything
following it that isn't lower priority), and since a non-empty string
is always true, so that ends up being exactly the same as:

    open FOO, "something";

This, however, will fail if "something" can't be opened:

    open FOO, "something" or die "ERR: $!";

The reason is that 'or' has lower priority that list operators,
i.e. it's performed after the 'open' call.

Reviewed-by: Matt Caswell <[email protected]>
(Merged from openssl#9884)
  • Loading branch information
levitte committed Sep 16, 2019
1 parent a1c8bef commit 1aa89a7
Show file tree
Hide file tree
Showing 165 changed files with 677 additions and 481 deletions.
4 changes: 1 addition & 3 deletions crypto/aes/asm/aes-586.pl
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@
push(@INC,"${dir}","${dir}../../perlasm");
require "x86asm.pl";

$output = pop;
open OUT,">$output";
*STDOUT=*OUT;
$output = pop and open STDOUT,">$output";

&asm_init($ARGV[0],$x86only = $ARGV[$#ARGV] eq "386");
&static_label("AES_Te");
Expand Down
12 changes: 7 additions & 5 deletions crypto/aes/asm/aes-armv4.pl
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@
# Profiler-assisted and platform-specific optimization resulted in 16%
# improvement on Cortex A8 core and ~21.5 cycles per byte.

$flavour = shift;
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
else { while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} }
# $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 && $flavour ne "void") {
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
die "can't locate arm-xlate.pl";

open STDOUT,"| \"$^X\" $xlate $flavour $output";
open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
or die "can't call $xlate: $!";
} else {
open STDOUT,">$output";
$output and open STDOUT,">$output";
}

$s0="r0";
Expand Down
3 changes: 1 addition & 2 deletions crypto/aes/asm/aes-c64xplus.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
# cost of 8x increased pressure on L1D. 8x because you'd have
# to interleave both Te and Td tables...

while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
open STDOUT,">$output";
$output = pop and open STDOUT,">$output";

($TEA,$TEB)=("A5","B5");
($KPA,$KPB)=("A3","B1");
Expand Down
16 changes: 8 additions & 8 deletions crypto/aes/asm/aes-mips.pl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@
# ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25));
# ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23));
# ($gp,$sp,$fp,$ra)=map("\$$_",(28..31));
#
$flavour = shift || "o32"; # supported flavours are o32,n32,64,nubi32,nubi64

# $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;
$flavour ||= "o32"; # supported flavours are o32,n32,64,nubi32,nubi64

if ($flavour =~ /64|n32/i) {
$PTR_LA="dla";
Expand Down Expand Up @@ -95,17 +99,13 @@

$big_endian=(`echo MIPSEB | $ENV{CC} -E -`=~/MIPSEB/)?0:1 if ($ENV{CC});

for (@ARGV) { $output=$_ if (/\w[\w\-]*\.\w+$/); }
open STDOUT,">$output";

if (!defined($big_endian))
{ $big_endian=(unpack('L',pack('N',1))==1); }

while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
open STDOUT,">$output";

my ($MSB,$LSB)=(0,3); # automatically converted to little-endian

$output and open STDOUT,">$output";

$code.=<<___;
#include "mips_arch.h"
Expand Down
9 changes: 6 additions & 3 deletions crypto/aes/asm/aes-parisc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
#
# Special thanks to polarhome.com for providing HP-UX account.

$flavour = shift;
$output = shift;
open STDOUT,">$output";
# $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;

$output and open STDOUT,">$output";

if ($flavour =~ /64/) {
$LEVEL ="2.0W";
Expand Down
8 changes: 6 additions & 2 deletions crypto/aes/asm/aes-ppc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
# ppc_AES_encrypt_compact operates at 42 cycles per byte, while
# ppc_AES_decrypt_compact - at 55 (in 64-bit build).

$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 =~ /64/) {
$SIZE_T =8;
Expand All @@ -59,7 +62,8 @@
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
die "can't locate ppc-xlate.pl";

open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
open STDOUT,"| $^X $xlate $flavour \"$output\""
or die "can't call $xlate: $!";

$FRAME=32*$SIZE_T;

Expand Down
8 changes: 5 additions & 3 deletions crypto/aes/asm/aes-s390x.pl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
# instructions, which deliver ~70% improvement at 8KB block size over
# vanilla km-based code, 37% - at most like 512-bytes block size.

$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;
Expand All @@ -99,8 +102,7 @@
$g="g";
}

while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
open STDOUT,">$output";
$output and open STDOUT,">$output";

$softonly=0; # allow hardware support

Expand Down
3 changes: 1 addition & 2 deletions crypto/aes/asm/aes-sparcv9.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
# optimal decrypt procedure]. Compared to GNU C generated code both
# procedures are more than 60% faster:-)

$output = pop;
open STDOUT,">$output";
$output = pop and open STDOUT,">$output";

$frame="STACK_FRAME";
$bias="STACK_BIAS";
Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/aes-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
#
# (*) with hyper-threading off

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand All @@ -44,7 +45,8 @@
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
die "can't locate x86_64-xlate.pl";

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

$verticalspin=1; # unlike 32-bit version $verticalspin performs
Expand Down
3 changes: 1 addition & 2 deletions crypto/aes/asm/aesfx-sparcv9.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
# instructions and improve single-block and short-input performance
# with misaligned data.

$output = pop;
open STDOUT,">$output";
$output = pop and open STDOUT,">$output";

{
my ($inp,$out,$key,$rounds,$tmp,$mask) = map("%o$_",(0..5));
Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/aesni-mb-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
# (*) Sandy/Ivy Bridge are known to handle high interleave factors
# suboptimally;

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand Down Expand Up @@ -74,7 +75,8 @@
$avx = ($2>=3.0) + ($2>3.0);
}

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

# void aesni_multi_cbc_encrypt (
Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/aesni-sha1-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@
# (**) Execution is fully dominated by integer code sequence and
# SIMD still hardly shows [in single-process benchmark;-]

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand All @@ -114,7 +115,8 @@

$stitched_decrypt=0;

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

# void aesni_cbc_sha1_enc(const void *inp,
Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/aesni-sha256-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
# -evp aes-256-cbc-hmac-sha256' will vary by percent or two;
# (***) these are SHAEXT results;

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand Down Expand Up @@ -77,7 +78,8 @@
$shaext=$avx; ### set to zero if compiling for 1.0.1
$avx=1 if (!$shaext && $avx);

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

$func="aesni_cbc_sha256_enc";
Expand Down
4 changes: 1 addition & 3 deletions crypto/aes/asm/aesni-x86.pl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
push(@INC,"${dir}","${dir}../../perlasm");
require "x86asm.pl";

$output = pop;
open OUT,">$output";
*STDOUT=*OUT;
$output = pop and open STDOUT,">$output";

&asm_init($ARGV[0]);

Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/aesni-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@
# generates drop-in replacement for
# crypto/aes/asm/aes-x86_64.pl:-)

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand All @@ -203,7 +204,8 @@
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
die "can't locate x86_64-xlate.pl";

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

$movkey = $PREFIX eq "aesni" ? "movups" : "movups";
Expand Down
8 changes: 6 additions & 2 deletions crypto/aes/asm/aesp8-ppc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
# POWER9[le] 4.02/0.86 0.84 1.05
# POWER9[be] 3.99/0.78 0.79 0.97

$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 =~ /64/) {
$SIZE_T =8;
Expand All @@ -70,7 +73,8 @@
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
die "can't locate ppc-xlate.pl";

open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
open STDOUT,"| $^X $xlate $flavour \"$output\""
or die "can't call $xlate: $!";

$FRAME=8*$SIZE_T;
$prefix="aes_p8";
Expand Down
3 changes: 1 addition & 2 deletions crypto/aes/asm/aest4-sparcv9.pl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
push(@INC,"${dir}","${dir}../../perlasm");
require "sparcv9_modes.pl";

$output = pop;
open STDOUT,">$output";
$output = pop and open STDOUT,">$output";

$::evp=1; # if $evp is set to 0, script generates module with
# AES_[en|de]crypt, AES_set_[en|de]crypt_key and AES_cbc_encrypt entry
Expand Down
9 changes: 6 additions & 3 deletions crypto/aes/asm/aesv8-armx.pl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@
# (**) numbers after slash are for 32-bit code, which is 3x-
# interleaved;

$flavour = shift;
$output = 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;

$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
die "can't locate arm-xlate.pl";

open OUT,"| \"$^X\" $xlate $flavour $output";
open OUT,"| \"$^X\" $xlate $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

$prefix="aes_v8";
Expand Down
12 changes: 7 additions & 5 deletions crypto/aes/asm/bsaes-armv7.pl
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@
# April-August 2013
# Add CBC, CTR and XTS subroutines and adapt for kernel use; courtesy of Ard.

$flavour = shift;
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
else { while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} }
# $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 && $flavour ne "void") {
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
die "can't locate arm-xlate.pl";

open STDOUT,"| \"$^X\" $xlate $flavour $output";
open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
or die "can't call $xlate: $!";
} else {
open STDOUT,">$output";
$output and open STDOUT,">$output";
}

my ($inp,$out,$len,$key)=("r0","r1","r2","r3");
Expand Down
10 changes: 6 additions & 4 deletions crypto/aes/asm/bsaes-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@
#
# <[email protected]>

$flavour = shift;
$output = shift;
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
# $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;

$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);

Expand All @@ -108,7 +109,8 @@
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
die "can't locate x86_64-xlate.pl";

open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
or die "can't call $xlate: $!";
*STDOUT=*OUT;

my ($inp,$out,$len,$key,$ivp)=("%rdi","%rsi","%rdx","%rcx");
Expand Down
Loading

0 comments on commit 1aa89a7

Please sign in to comment.