]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add more directives to benchmark input files
authorSiddhesh Poyarekar <siddhesh@redhat.com>
Mon, 7 Oct 2013 06:21:24 +0000 (11:51 +0530)
committerSiddhesh Poyarekar <siddhesh@redhat.com>
Mon, 7 Oct 2013 06:21:25 +0000 (11:51 +0530)
This patch adds some more directives to the benchmark inputs file,
moving functionality from the Makefile and making the code generation
script a bit cleaner.  The function argument and return types that
were earlier added as variables in the makefile and passed to the
script via command line arguments are now the 'args' and 'ret'
directive respectively.  'args' should be a colon separated list of
argument types (skipped if the function doesn't accept any arguments)
and 'ret' should be the return type.

Additionally, an 'includes' directive may have a comma separated list
of headers to include in the source.  For example, the pow input file
now looks like this:

42.0, 42.0
1.0000000000000020, 1.5

I did this to unclutter the benchtests Makefile a bit and eventually
eliminate dependency of the tests on the Makefile and have tests
depend on their respective include files only.

20 files changed:
ChangeLog
benchtests/Makefile
benchtests/README
benchtests/acos-inputs
benchtests/acosh-inputs
benchtests/asin-inputs
benchtests/asinh-inputs
benchtests/atan-inputs
benchtests/atanh-inputs
benchtests/cos-inputs
benchtests/cosh-inputs
benchtests/exp-inputs
benchtests/log-inputs
benchtests/pow-inputs
benchtests/rint-inputs
benchtests/sin-inputs
benchtests/sinh-inputs
benchtests/tan-inputs
benchtests/tanh-inputs
scripts/bench.pl

index 44ebf726d39099634c57dbe077f99ed62f17cc13..09832991378a3be172bd6456281fd161385d2a4a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2013-10-07  Siddhesh Poyarekar  <siddhesh@redhat.com>
+
+       * benchtests/Makefile: Remove ARGLIST and RET variables.
+       ($(objpfx)bench-%.c): Pass only function name to the script.
+       * benchtests/README: Update documentation.
+       * benchtests/acos-inputs: Add new directives.
+       * benchtests/acosh-inputs: Likewise.
+       * benchtests/asin-inputs: Likewise.
+       * benchtests/asinh-inputs: Likewise.
+       * benchtests/atan-inputs: Likewise.
+       * benchtests/atanh-inputs: Likewise.
+       * benchtests/cos-inputs: Likewise.
+       * benchtests/cosh-inputs: Likewise.
+       * benchtests/exp-inputs: Likewise.
+       * benchtests/log-inputs: Likewise.
+       * benchtests/pow-inputs: Likewise.
+       * benchtests/rint-inputs: Likewise.
+       * benchtests/sin-inputs: Likewise.
+       * benchtests/sinh-inputs: Likewise.
+       * benchtests/tan-inputs: Likewise.
+       * benchtests/tanh-inputs: Likewise.
+       * scripts/bench.pl: Add support for new directives.
+
 2013-10-07  Alan Modra  <amodra@gmail.com>
 
        * README: Fix careless merge.
index 4f4bd5408a1a2372e8c75596c5d5c2b3783cdc6f..aec395a814acc4f4d1746f9ace3b5b1e55fe1e44 100644 (file)
@@ -34,70 +34,22 @@ string-bench-all := $(string-bench) $(string-bench-ifunc)
 
 benchset := $(string-bench-all)
 
-acos-ARGLIST = double
-acos-RET = double
 LDLIBS-bench-acos = -lm
-
-acosh-ARGLIST = double
-acosh-RET = double
 LDLIBS-bench-acosh = -lm
-
-asin-ARGLIST = double
-asin-RET = double
 LDLIBS-bench-asin = -lm
-
-asinh-ARGLIST = double
-asinh-RET = double
 LDLIBS-bench-asinh = -lm
-
-atan-ARGLIST = double
-atan-RET = double
 LDLIBS-bench-atan = -lm
-
-atanh-ARGLIST = double
-atanh-RET = double
 LDLIBS-bench-atanh = -lm
-
-cos-ARGLIST = double
-cos-RET = double
 LDLIBS-bench-cos = -lm
-
-cosh-ARGLIST = double
-cosh-RET = double
 LDLIBS-bench-cosh = -lm
-
-exp-ARGLIST = double
-exp-RET = double
 LDLIBS-bench-exp = -lm
-
-log-ARGLIST = double
-log-RET = double
 LDLIBS-bench-log = -lm
-
-pow-ARGLIST = double:double
-pow-RET = double
 LDLIBS-bench-pow = -lm
-
-rint-ARGLIST = double
-rint-RET = double
 LDLIBS-bench-rint = -lm
-
-sin-ARGLIST = double
-sin-RET = double
 LDLIBS-bench-sin = -lm
-
-sinh-ARGLIST = double
-sinh-RET = double
 LDLIBS-bench-sinh = -lm
-
-tan-ARGLIST = double
-tan-RET = double
 LDLIBS-bench-tan = -lm
-
-tanh-ARGLIST = double
-tanh-RET = double
 LDLIBS-bench-tanh = -lm
-
 LDLIBS-bench-sincos = -lm
 
 \f
@@ -171,6 +123,5 @@ $(objpfx)bench-%.c: %-inputs $(bench-deps)
        { if [ -n "$($*-INCLUDE)" ]; then \
          cat $($*-INCLUDE); \
        fi; \
-       $(..)scripts/bench.pl $(patsubst %-inputs,%,$<) \
-         $($*-ARGLIST) $($*-RET); } > $@-tmp
+       $(..)scripts/bench.pl $(patsubst %-inputs,%,$<); } > $@-tmp
        mv -f $@-tmp $@
index 045b7a673d1c8136aa732fa3486b14992cab3e82..5faca535111bddc889ee1b0401577affcbcbe58b 100644 (file)
@@ -40,23 +40,24 @@ one to add `foo' to the bench tests:
 
 - Append the function name to the bench variable in the Makefile.
 
-- Define foo-ARGLIST as a colon separated list of types of the input
-  arguments.  Use `void' if function does not take any inputs.  Put in quotes
-  if the input argument is a pointer, e.g.:
-
-     malloc-ARGLIST: "void *"
-
-- Define foo-RET as the type the function returns.  Skip if the function
-  returns void.  One could even skip foo-ARGLIST if the function does not
-  take any inputs AND the function returns void.
-
-- Make a file called `foo-inputs` with one input value per line, an input
-  being a comma separated list of arguments to be passed into the function.
-  See pow-inputs for an example.
-
-  The script that parses the -inputs file treats lines beginning with a single
-  `#' as comments.  Lines beginning with two hashes `##' are treated specially
-  as `directives'.
+- Make a file called `foo-inputs` to provide the definition and input for the
+  function.  The file should have some directives telling the parser script
+  about the function and then one input per line.  Directives are lines that
+  have a special meaning for the parser and they begin with two hashes '##'.
+  The following directives are recognized:
+
+  - args: This should be assigned a colon separated list of types of the input
+    arguments.  This directive may be skipped if the function does not take any
+    inputs.
+  - ret: This should be assigned the type that the function returns.  This
+    directive may be skipped if the function does not return a value.
+  - includes: This should be assigned a comma separated list of headers that
+    need to be included to provide declarations for the function and types it
+    may need.
+  - name: See following section for instructions on how to use this directive.
+
+  Lines beginning with a single hash '#' are treated as comments.  See
+  pow-inputs for an example of an input file.
 
 Multiple execution units per function:
 =====================================
index b527af35e491083df237b6412fe1f76de053250a..080a4e916efe58851b849becd8cb99f4fe68256f 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.5
 0.1
 0.2
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index b527af35e491083df237b6412fe1f76de053250a..080a4e916efe58851b849becd8cb99f4fe68256f 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.5
 0.1
 0.2
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index 4a2cf3aca37174160c42843516951014a829bb68..e88e384346024de24a0c1293bb58ff0c8e7ba5fd 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0x1.000000c5cba86p0
 0x1.000001883003ap0
 0x1.00000dfb2b674p0
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index 82a40609cdd3a9a59461c3e844aa224d7b0092e6..c7bbaad15110f553199b9fe923a55b75a9e93a79 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0x1.000000cf4a2a1p0
 0x1.0000010b239a8p0
 0x1.00000162a932ap0
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index e9d33a3d1cba0b54e17961be3e56ce4b0845b192..593ad7c74b4b324a94b85eee37d9a266495f3b58 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 42
 # Slowest path with computation in 768 bit precision.
 # Implemented in: sysdeps/ieee754/dbl-64/mpexp.c
index 713c2229f519d08dc5d71063b54e973f6a8f4084..c92d78ce6ff85d1a9ee404cab69fdd1e7cfee08c 100644 (file)
@@ -1 +1,4 @@
+## args: double
+## ret: double
+## includes: math.h
 42.0
index dad65059aa3197686952328fcd246992a9b591e6..96b1b6c2ad940c2cfaa3979c121621f491a183ab 100644 (file)
@@ -1,3 +1,6 @@
+## args: double:double
+## ret: double
+## includes: math.h
 42.0, 42.0
 # pow slowest path at 768 bits
 # Implemented in sysdeps/ieee754/dbl-64/slowpow.c
index a5f83dc8f91333a278dea87cf24b80f771b872db..e9001f92e88b52e357b382033391e01de2f376ce 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 78.5
 -78.5
 4503599627370497.0
index 08192d8f0998c7b0feeffffd1a9d0f4dc680b51f..ae452a82df22d5eb54d96fafdd3e91f4bd82a202 100644 (file)
@@ -1,3 +1,6 @@
+## includes: math.h
+## args: double
+## ret: double
 0.9
 2.3
 3.7
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index 629414fc73c122a616b7e98582a24f4d85bdb5b6..f489ddde8e128064005f9e45c12a92f21f77f581 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0x1.dffffffffff1ep-22
 # tan slowest path at 768 bits
 # Implemented in sysdeps/ieee754/dbl-64/mptan.c
index 3c8c546f0c1a3fe68620575f54b940d5859cfad2..84a603dc3d9ff6f19b174a93dcdbae539b6ff43b 100644 (file)
@@ -1,3 +1,6 @@
+## args: double
+## ret: double
+## includes: math.h
 0.1
 0.2
 0.3
index dcf13552820eba64381f3ee23bb5167e749dbe83..5fe95d0c2f2137d5447c61f70f017086f3d48915 100755 (executable)
@@ -21,40 +21,78 @@ 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_files;
+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;
+    }
 
-if (@ARGV == 3) {
-  $ret = $ARGV[2];
+    elsif ($1 eq "includes") {
+      @include_files = 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;
+    }
+  }
+
+  # 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_files) {
+  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 (";
 
+if (@args > 0) {
+  # Save values in the last variant.
+  $vals{$variant} = \@curvals;
   my $struct =
     "struct _variants
     {
@@ -65,60 +103,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 +146,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 = ";
 }