From 9298ecba15e2b8055e68189c1b11b08ef3ac008d Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 5 Dec 2013 10:12:59 +0530 Subject: Accept output arguments to benchmark functions This patch adds the ability to accept output arguments to functions being benchmarked, by nesting the argument type in <> in the args directive. It includes the sincos implementation as an example, where the function would have the following args directive: ## args: double:: This simply adds a definition for a static variable whose pointer gets passed into the function, so it's not yet possible to pass something more complicated like a pre-allocated string or array. That would be a good feature to add if a function needs it. The values in the input file will map only to the input arguments. So if I had a directive like this for a function foo: ## args: int::int: and I have a value list like this: 1, 2 3, 4 5, 6 then the function calls generated would be: foo (1, &out1, 2, &out2); foo (3, &out1, 4, &out2); foo (5, &out1, 6, &out2); --- scripts/bench.pl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'scripts/bench.pl') diff --git a/scripts/bench.pl b/scripts/bench.pl index 6ad93fa..90441e1 100755 --- a/scripts/bench.pl +++ b/scripts/bench.pl @@ -93,6 +93,13 @@ LINE:while () { my $bench_func = "#define CALL_BENCH_FUNC(v, i) $func ("; +# Output variables. These include the return value as well as any pointers +# that may get passed into the function, denoted by the <> around the type. +my $outvars = ""; + +if ($ret ne "void") { + $outvars = "static volatile $ret ret;\n"; +} # Print the definitions and macros. foreach $incl (@include_headers) { @@ -124,8 +131,18 @@ if (@args > 0) { $bench_func = "$bench_func,"; } - $arg_struct = "$arg_struct volatile $arg arg$num;"; - $bench_func = "$bench_func variants[v].in[i].arg$num"; + $_ = $arg; + if (/<(.*)\*>/) { + # Output variables. These have to be pointers, so dereference once by + # dropping one *. + $outvars = $outvars . "static $1 out$num;\n"; + $bench_func = "$bench_func &out$num"; + } + else { + $arg_struct = "$arg_struct volatile $arg arg$num;"; + $bench_func = "$bench_func variants[v].in[i].arg$num"; + } + $num = $num + 1; } @@ -172,12 +189,12 @@ else { print "#define VARIANT(v) FUNCNAME \"()\"\n" } - +# Print the output variable definitions. +print "$outvars\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;\n"; $getret = "ret = "; } -- cgit v1.1