2 # Copyright (C) 2013 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <http://www.gnu.org/licenses/>.
22 # Generate a benchmark source file for a given input.
25 die "Usage: bench.pl <function> <iterations> [parameter types] [return type]"
37 @args = split(':', $ARGV[2]);
44 my $decl = "extern $ret $func (";
46 if (@args == 0 || $args[0] eq "void") {
47 print "$decl void);\n";
48 print "#define CALL_BENCH_FUNC(j) $func();\n";
49 print "#define NUM_SAMPLES (1)\n";
53 my $bench_func = "#define CALL_BENCH_FUNC(j) $func (";
54 my $struct = "struct args {";
56 foreach $arg (@args) {
58 $bench_func = "$bench_func,";
62 $struct = "$struct $arg arg$num;";
63 $bench_func = "$bench_func in[j].arg$num";
69 print "$bench_func);\n";
70 print "$struct } in[] = {";
72 open INPUTS, "<$func-inputs" or die $!;
79 print "#define NUM_SAMPLES (sizeof (in) / sizeof (struct args))\n"
82 # In some cases not storing a return value seems to result in the function call
83 # being optimized out.
85 print "static volatile $ret ret = 0.0;\n";
89 print "#define BENCH_FUNC(j) ({$getret CALL_BENCH_FUNC (j);})\n";
91 print "#define ITER $iters\n";
92 print "#define FUNCNAME \"$func\"\n";
93 print "#include \"bench-skeleton.c\"\n";