summaryrefslogtreecommitdiff
path: root/libc/scripts/bench.pl
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-10-18 21:33:25 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-10-18 21:33:25 +0000
commitfe2ed5aaa408e1ab996a9fe1595a05634208a79c (patch)
treee1027fbc9d8a4a8c33f8149b2b42e8cde89c74f6 /libc/scripts/bench.pl
parent571c782b982d888565e7d06bfc2f3d47582fe829 (diff)
downloadeglibc2-fe2ed5aaa408e1ab996a9fe1595a05634208a79c.tar.gz
Merge changes between r23946 and r24305 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@24306 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/scripts/bench.pl')
-rwxr-xr-xlibc/scripts/bench.pl148
1 files changed, 84 insertions, 64 deletions
diff --git a/libc/scripts/bench.pl b/libc/scripts/bench.pl
index dcf135528..492ab816e 100755
--- a/libc/scripts/bench.pl
+++ b/libc/scripts/bench.pl
@@ -21,40 +21,92 @@ use strict;
use warnings;
# Generate a benchmark source file for a given input.
-if (@ARGV < 2) {
- die "Usage: bench.pl <function> [parameter types] [return type]"
+if (@ARGV < 1) {
+ die "Usage: bench.pl <function>"
}
-my $arg;
my $func = $ARGV[0];
my @args;
my $ret = "void";
my $getret = "";
-my $retval = "";
-if (@ARGV >= 2) {
- @args = split(':', $ARGV[1]);
-}
+# We create a hash of inputs for each variant of the test.
+my $variant = "";
+my @curvals;
+my %vals;
+my @include_headers;
+my @include_sources;
+my $incl;
+
+open INPUTS, "<$func-inputs" or die $!;
+
+LINE:while (<INPUTS>) {
+ chomp;
+
+ # Directives.
+ if (/^## ([\w-]+): (.*)/) {
+ # Function argument types.
+ if ($1 eq "args") {
+ @args = split(":", $2);
+ }
+
+ # Function return type.
+ elsif ($1 eq "ret") {
+ $ret = $2;
+ }
+
+ elsif ($1 eq "includes") {
+ @include_headers = split (",", $2);
+ }
+
+ elsif ($1 eq "include-sources") {
+ @include_sources = split (",", $2);
+ }
+
+ # New variant. This is the only directive allowed in the body of the
+ # inputs to separate inputs into variants. All others should be at the
+ # top or else all hell will break loose.
+ elsif ($1 eq "name") {
+
+ # Save values in the previous variant.
+ my @copy = @curvals;
+ $vals{$variant} = \@copy;
+
+ # Prepare for the next.
+ $variant=$2;
+ undef @curvals;
+ next LINE;
+ }
+
+ else {
+ die "Unknown directive: ".$1;
+ }
+ }
-if (@ARGV == 3) {
- $ret = $ARGV[2];
+ # Skip over comments.
+ if (/^#/) {
+ next LINE;
+ }
+ push (@curvals, $_);
}
-my $decl = "extern $ret $func (";
-# Function has no arguments.
-if (@args == 0 || $args[0] eq "void") {
- print "$decl void);\n";
- print "#define CALL_BENCH_FUNC(i,j) $func();\n";
- print "#define NUM_VARIANTS (1)\n";
- print "#define NUM_SAMPLES(v) (1)\n";
- print "#define VARIANT(v) FUNCNAME \"()\"\n"
+my $bench_func = "#define CALL_BENCH_FUNC(v, i) $func (";
+
+
+# Print the definitions and macros.
+foreach $incl (@include_headers) {
+ print "#include <" . $incl . ">\n";
}
-# The function has arguments, so parse them and populate the inputs.
-else {
- my $num = 0;
- my $bench_func = "#define CALL_BENCH_FUNC(v, i) $func (";
+# Print the source files.
+foreach $incl (@include_sources) {
+ print "#include \"" . $incl . "\"\n";
+}
+
+if (@args > 0) {
+ # Save values in the last variant.
+ $vals{$variant} = \@curvals;
my $struct =
"struct _variants
{
@@ -65,60 +117,21 @@ else {
my $arg_struct = "struct args {";
+ my $num = 0;
+ my $arg;
foreach $arg (@args) {
if ($num > 0) {
$bench_func = "$bench_func,";
- $decl = "$decl,";
}
$arg_struct = "$arg_struct volatile $arg arg$num;";
$bench_func = "$bench_func variants[v].in[i].arg$num";
- $decl = "$decl $arg";
$num = $num + 1;
}
$arg_struct = $arg_struct . "};\n";
- $decl = $decl . ");\n";
$bench_func = $bench_func . ");\n";
- # We create a hash of inputs for each variant of the test.
- my $variant = "";
- my @curvals;
- my %vals;
-
- open INPUTS, "<$func-inputs" or die $!;
-
- LINE:while (<INPUTS>) {
- chomp;
-
- # New variant.
- if (/^## (\w+): (\w+)/) {
- #We only identify Name for now.
- if ($1 ne "name") {
- next LINE;
- }
-
- # Save values in the last variant.
- my @copy = @curvals;
- $vals{$variant} = \@copy;
-
- # Prepare for the next.
- $variant=$2;
- undef @curvals;
- next LINE;
- }
-
- # Skip over comments.
- if (/^#/) {
- next LINE;
- }
- push (@curvals, $_);
- }
-
- $vals{$variant} = \@curvals;
-
- # Print the definitions and macros.
- print $decl;
print $bench_func;
print $arg_struct;
print $struct;
@@ -147,17 +160,24 @@ else {
$c += 1;
}
print "};\n\n";
-
# Finally, print the last set of macros.
print "#define NUM_VARIANTS $c\n";
print "#define NUM_SAMPLES(i) (variants[i].count)\n";
print "#define VARIANT(i) (variants[i].name)\n";
}
+else {
+ print $bench_func . ");\n";
+ print "#define NUM_VARIANTS (1)\n";
+ print "#define NUM_SAMPLES(v) (1)\n";
+ print "#define VARIANT(v) FUNCNAME \"()\"\n"
+}
+
+
# In some cases not storing a return value seems to result in the function call
# being optimized out.
if ($ret ne "void") {
- print "static volatile $ret ret = 0.0;\n";
+ print "static volatile $ret ret;\n";
$getret = "ret = ";
}