Skip to content

Commit 1aa89a7

Browse files
committed
Unify all assembler file generators
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)
1 parent a1c8bef commit 1aa89a7

File tree

165 files changed

+677
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+677
-481
lines changed

crypto/aes/asm/aes-586.pl

+1-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@
198198
push(@INC,"${dir}","${dir}../../perlasm");
199199
require "x86asm.pl";
200200

201-
$output = pop;
202-
open OUT,">$output";
203-
*STDOUT=*OUT;
201+
$output = pop and open STDOUT,">$output";
204202

205203
&asm_init($ARGV[0],$x86only = $ARGV[$#ARGV] eq "386");
206204
&static_label("AES_Te");

crypto/aes/asm/aes-armv4.pl

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@
3939
# Profiler-assisted and platform-specific optimization resulted in 16%
4040
# improvement on Cortex A8 core and ~21.5 cycles per byte.
4141

42-
$flavour = shift;
43-
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
44-
else { while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} }
42+
# $output is the last argument if it looks like a file (it has an extension)
43+
# $flavour is the first argument if it doesn't look like a file
44+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
45+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
4546

4647
if ($flavour && $flavour ne "void") {
4748
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
4849
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
4950
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
5051
die "can't locate arm-xlate.pl";
5152

52-
open STDOUT,"| \"$^X\" $xlate $flavour $output";
53+
open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
54+
or die "can't call $xlate: $!";
5355
} else {
54-
open STDOUT,">$output";
56+
$output and open STDOUT,">$output";
5557
}
5658

5759
$s0="r0";

crypto/aes/asm/aes-c64xplus.pl

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
# cost of 8x increased pressure on L1D. 8x because you'd have
3838
# to interleave both Te and Td tables...
3939

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

4342
($TEA,$TEB)=("A5","B5");
4443
($KPA,$KPB)=("A3","B1");

crypto/aes/asm/aes-mips.pl

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@
6565
# ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25));
6666
# ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23));
6767
# ($gp,$sp,$fp,$ra)=map("\$$_",(28..31));
68-
#
69-
$flavour = shift || "o32"; # supported flavours are o32,n32,64,nubi32,nubi64
68+
69+
# $output is the last argument if it looks like a file (it has an extension)
70+
# $flavour is the first argument if it doesn't look like a file
71+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
72+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
73+
$flavour ||= "o32"; # supported flavours are o32,n32,64,nubi32,nubi64
7074

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

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

98-
for (@ARGV) { $output=$_ if (/\w[\w\-]*\.\w+$/); }
99-
open STDOUT,">$output";
100-
101102
if (!defined($big_endian))
102103
{ $big_endian=(unpack('L',pack('N',1))==1); }
103104

104-
while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
105-
open STDOUT,">$output";
106-
107105
my ($MSB,$LSB)=(0,3); # automatically converted to little-endian
108106

107+
$output and open STDOUT,">$output";
108+
109109
$code.=<<___;
110110
#include "mips_arch.h"
111111

crypto/aes/asm/aes-parisc.pl

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
#
2929
# Special thanks to polarhome.com for providing HP-UX account.
3030

31-
$flavour = shift;
32-
$output = shift;
33-
open STDOUT,">$output";
31+
# $output is the last argument if it looks like a file (it has an extension)
32+
# $flavour is the first argument if it doesn't look like a file
33+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
34+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
35+
36+
$output and open STDOUT,">$output";
3437

3538
if ($flavour =~ /64/) {
3639
$LEVEL ="2.0W";

crypto/aes/asm/aes-ppc.pl

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
# ppc_AES_encrypt_compact operates at 42 cycles per byte, while
3737
# ppc_AES_decrypt_compact - at 55 (in 64-bit build).
3838

39-
$flavour = shift;
39+
# $output is the last argument if it looks like a file (it has an extension)
40+
# $flavour is the first argument if it doesn't look like a file
41+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
42+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
4043

4144
if ($flavour =~ /64/) {
4245
$SIZE_T =8;
@@ -59,7 +62,8 @@
5962
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
6063
die "can't locate ppc-xlate.pl";
6164

62-
open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
65+
open STDOUT,"| $^X $xlate $flavour \"$output\""
66+
or die "can't call $xlate: $!";
6367

6468
$FRAME=32*$SIZE_T;
6569

crypto/aes/asm/aes-s390x.pl

+5-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@
8989
# instructions, which deliver ~70% improvement at 8KB block size over
9090
# vanilla km-based code, 37% - at most like 512-bytes block size.
9191

92-
$flavour = shift;
92+
# $output is the last argument if it looks like a file (it has an extension)
93+
# $flavour is the first argument if it doesn't look like a file
94+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
95+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
9396

9497
if ($flavour =~ /3[12]/) {
9598
$SIZE_T=4;
@@ -99,8 +102,7 @@
99102
$g="g";
100103
}
101104

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

105107
$softonly=0; # allow hardware support
106108

crypto/aes/asm/aes-sparcv9.pl

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
# optimal decrypt procedure]. Compared to GNU C generated code both
3838
# procedures are more than 60% faster:-)
3939

40-
$output = pop;
41-
open STDOUT,">$output";
40+
$output = pop and open STDOUT,">$output";
4241

4342
$frame="STACK_FRAME";
4443
$bias="STACK_BIAS";

crypto/aes/asm/aes-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
#
3434
# (*) with hyper-threading off
3535

36-
$flavour = shift;
37-
$output = shift;
38-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
36+
# $output is the last argument if it looks like a file (it has an extension)
37+
# $flavour is the first argument if it doesn't look like a file
38+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
39+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
3940

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

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

47-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
48+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
49+
or die "can't call $xlate: $!";
4850
*STDOUT=*OUT;
4951

5052
$verticalspin=1; # unlike 32-bit version $verticalspin performs

crypto/aes/asm/aesfx-sparcv9.pl

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
# instructions and improve single-block and short-input performance
3434
# with misaligned data.
3535

36-
$output = pop;
37-
open STDOUT,">$output";
36+
$output = pop and open STDOUT,">$output";
3837

3938
{
4039
my ($inp,$out,$key,$rounds,$tmp,$mask) = map("%o$_",(0..5));

crypto/aes/asm/aesni-mb-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
# (*) Sandy/Ivy Bridge are known to handle high interleave factors
4343
# suboptimally;
4444

45-
$flavour = shift;
46-
$output = shift;
47-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
45+
# $output is the last argument if it looks like a file (it has an extension)
46+
# $flavour is the first argument if it doesn't look like a file
47+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
48+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
4849

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

@@ -74,7 +75,8 @@
7475
$avx = ($2>=3.0) + ($2>3.0);
7576
}
7677

77-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
78+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
79+
or die "can't call $xlate: $!";
7880
*STDOUT=*OUT;
7981

8082
# void aesni_multi_cbc_encrypt (

crypto/aes/asm/aesni-sha1-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@
8888
# (**) Execution is fully dominated by integer code sequence and
8989
# SIMD still hardly shows [in single-process benchmark;-]
9090

91-
$flavour = shift;
92-
$output = shift;
93-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
91+
# $output is the last argument if it looks like a file (it has an extension)
92+
# $flavour is the first argument if it doesn't look like a file
93+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
94+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
9495

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

@@ -114,7 +115,8 @@
114115

115116
$stitched_decrypt=0;
116117

117-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
118+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
119+
or die "can't call $xlate: $!";
118120
*STDOUT=*OUT;
119121

120122
# void aesni_cbc_sha1_enc(const void *inp,

crypto/aes/asm/aesni-sha256-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
# -evp aes-256-cbc-hmac-sha256' will vary by percent or two;
4545
# (***) these are SHAEXT results;
4646

47-
$flavour = shift;
48-
$output = shift;
49-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
47+
# $output is the last argument if it looks like a file (it has an extension)
48+
# $flavour is the first argument if it doesn't look like a file
49+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
50+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
5051

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

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

80-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
81+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
82+
or die "can't call $xlate: $!";
8183
*STDOUT=*OUT;
8284

8385
$func="aesni_cbc_sha256_enc";

crypto/aes/asm/aesni-x86.pl

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
push(@INC,"${dir}","${dir}../../perlasm");
7777
require "x86asm.pl";
7878

79-
$output = pop;
80-
open OUT,">$output";
81-
*STDOUT=*OUT;
79+
$output = pop and open STDOUT,">$output";
8280

8381
&asm_init($ARGV[0]);
8482

crypto/aes/asm/aesni-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@
192192
# generates drop-in replacement for
193193
# crypto/aes/asm/aes-x86_64.pl:-)
194194

195-
$flavour = shift;
196-
$output = shift;
197-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
195+
# $output is the last argument if it looks like a file (it has an extension)
196+
# $flavour is the first argument if it doesn't look like a file
197+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
198+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
198199

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

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

206-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
207+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
208+
or die "can't call $xlate: $!";
207209
*STDOUT=*OUT;
208210

209211
$movkey = $PREFIX eq "aesni" ? "movups" : "movups";

crypto/aes/asm/aesp8-ppc.pl

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
# POWER9[le] 4.02/0.86 0.84 1.05
4444
# POWER9[be] 3.99/0.78 0.79 0.97
4545

46-
$flavour = shift;
46+
# $output is the last argument if it looks like a file (it has an extension)
47+
# $flavour is the first argument if it doesn't look like a file
48+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
49+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
4750

4851
if ($flavour =~ /64/) {
4952
$SIZE_T =8;
@@ -70,7 +73,8 @@
7073
( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
7174
die "can't locate ppc-xlate.pl";
7275

73-
open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
76+
open STDOUT,"| $^X $xlate $flavour \"$output\""
77+
or die "can't call $xlate: $!";
7478

7579
$FRAME=8*$SIZE_T;
7680
$prefix="aes_p8";

crypto/aes/asm/aest4-sparcv9.pl

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
push(@INC,"${dir}","${dir}../../perlasm");
7676
require "sparcv9_modes.pl";
7777

78-
$output = pop;
79-
open STDOUT,">$output";
78+
$output = pop and open STDOUT,">$output";
8079

8180
$::evp=1; # if $evp is set to 0, script generates module with
8281
# AES_[en|de]crypt, AES_set_[en|de]crypt_key and AES_cbc_encrypt entry

crypto/aes/asm/aesv8-armx.pl

+6-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@
5656
# (**) numbers after slash are for 32-bit code, which is 3x-
5757
# interleaved;
5858

59-
$flavour = shift;
60-
$output = shift;
59+
# $output is the last argument if it looks like a file (it has an extension)
60+
# $flavour is the first argument if it doesn't look like a file
61+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
62+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
6163

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

67-
open OUT,"| \"$^X\" $xlate $flavour $output";
69+
open OUT,"| \"$^X\" $xlate $flavour \"$output\""
70+
or die "can't call $xlate: $!";
6871
*STDOUT=*OUT;
6972

7073
$prefix="aes_v8";

crypto/aes/asm/bsaes-armv7.pl

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@
5050
# April-August 2013
5151
# Add CBC, CTR and XTS subroutines and adapt for kernel use; courtesy of Ard.
5252

53-
$flavour = shift;
54-
if ($flavour=~/\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
55-
else { while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} }
53+
# $output is the last argument if it looks like a file (it has an extension)
54+
# $flavour is the first argument if it doesn't look like a file
55+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
56+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
5657

5758
if ($flavour && $flavour ne "void") {
5859
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
5960
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
6061
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
6162
die "can't locate arm-xlate.pl";
6263

63-
open STDOUT,"| \"$^X\" $xlate $flavour $output";
64+
open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
65+
or die "can't call $xlate: $!";
6466
} else {
65-
open STDOUT,">$output";
67+
$output and open STDOUT,">$output";
6668
}
6769

6870
my ($inp,$out,$len,$key)=("r0","r1","r2","r3");

crypto/aes/asm/bsaes-x86_64.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@
9797
#
9898
9999

100-
$flavour = shift;
101-
$output = shift;
102-
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
100+
# $output is the last argument if it looks like a file (it has an extension)
101+
# $flavour is the first argument if it doesn't look like a file
102+
$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
103+
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
103104

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

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

111-
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
112+
open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
113+
or die "can't call $xlate: $!";
112114
*STDOUT=*OUT;
113115

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

0 commit comments

Comments
 (0)