summaryrefslogtreecommitdiff
path: root/libc/scripts/bench.pl
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-03-18 16:44:23 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-03-18 16:44:23 +0000
commit8751114637bcc3caaf16a4216da0afb84456558a (patch)
treef3eca66b88003bc49c309a95827d461ae5b66aed /libc/scripts/bench.pl
parentb261131fe2b94b53fe4950d9265ae10bef228455 (diff)
Merge changes between r22552 and r22663 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@22664 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/scripts/bench.pl')
-rwxr-xr-xlibc/scripts/bench.pl93
1 files changed, 93 insertions, 0 deletions
diff --git a/libc/scripts/bench.pl b/libc/scripts/bench.pl
new file mode 100755
index 000000000..bb7f64897
--- /dev/null
+++ b/libc/scripts/bench.pl
@@ -0,0 +1,93 @@
+#! /usr/bin/perl -w
+# Copyright (C) 2013 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+
+use strict;
+use warnings;
+# Generate a benchmark source file for a given input.
+
+if (@ARGV < 2) {
+ die "Usage: bench.pl <function> <iterations> [parameter types] [return type]"
+}
+
+my $arg;
+my $func = $ARGV[0];
+my $iters = $ARGV[1];
+my @args;
+my $ret = "void";
+my $getret = "";
+my $retval = "";
+
+if (@ARGV >= 3) {
+ @args = split(':', $ARGV[2]);
+}
+
+if (@ARGV == 4) {
+ $ret = $ARGV[3];
+}
+
+my $decl = "extern $ret $func (";
+
+if (@args == 0 || $args[0] eq "void") {
+ print "$decl void);\n";
+ print "#define CALL_BENCH_FUNC(j) $func();\n";
+ print "#define NUM_SAMPLES (1)\n";
+}
+else {
+ my $num = 0;
+ my $bench_func = "#define CALL_BENCH_FUNC(j) $func (";
+ my $struct = "struct args {";
+
+ foreach $arg (@args) {
+ if ($num > 0) {
+ $bench_func = "$bench_func,";
+ $decl = "$decl,";
+ }
+
+ $struct = "$struct $arg arg$num;";
+ $bench_func = "$bench_func in[j].arg$num";
+ $decl = "$decl $arg";
+ $num = $num + 1;
+ }
+
+ print "$decl);\n";
+ print "$bench_func);\n";
+ print "$struct } in[] = {";
+
+ open INPUTS, "<$func-inputs" or die $!;
+
+ while (<INPUTS>) {
+ chomp;
+ print "{$_},\n";
+ }
+ print "};\n";
+ print "#define NUM_SAMPLES (sizeof (in) / sizeof (struct args))\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";
+ $getret = "ret = ";
+}
+
+print "#define BENCH_FUNC(j) ({$getret CALL_BENCH_FUNC (j);})\n";
+
+print "#define ITER $iters\n";
+print "#define FUNCNAME \"$func\"\n";
+print "#include \"bench-skeleton.c\"\n";