From: Ian Rogers Date: Thu, 23 Sep 2021 07:46:08 +0000 (-0700) Subject: perf expr: Use macros for operators X-Git-Tag: v6.6.17~8887^2~97 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e87576c5ac14e038ac96145d289bf0134eb08506;p=platform%2Fkernel%2Flinux-rpi.git perf expr: Use macros for operators No functional change, switch the operators to use macros so that additional complexity for constants can be added in a later change. Signed-off-by: Ian Rogers Tested-by: John Garry Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ingo Molnar Cc: Jin Yao Cc: Kajol Jain Cc: Mark Rutland Cc: Namhyung Kim Cc: Paul Clarke Cc: Peter Zijlstra Cc: Sandeep Dasgupta Cc: Stephane Eranian Link: https://lore.kernel.org/r/20210923074616.674826-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index 68b122e..5535bad 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -43,6 +43,12 @@ static void expr_error(double *final_val __maybe_unused, pr_debug("%s\n", s); } +#define BINARY_LONG_OP(RESULT, OP, LHS, RHS) \ + RESULT = (long)LHS OP (long)RHS; + +#define BINARY_OP(RESULT, OP, LHS, RHS) \ + RESULT = LHS OP RHS; + %} %% @@ -81,14 +87,14 @@ expr: NUMBER free($1); } - | expr '|' expr { $$ = (long)$1 | (long)$3; } - | expr '&' expr { $$ = (long)$1 & (long)$3; } - | expr '^' expr { $$ = (long)$1 ^ (long)$3; } - | expr '<' expr { $$ = $1 < $3; } - | expr '>' expr { $$ = $1 > $3; } - | expr '+' expr { $$ = $1 + $3; } - | expr '-' expr { $$ = $1 - $3; } - | expr '*' expr { $$ = $1 * $3; } + | expr '|' expr { BINARY_LONG_OP($$, |, $1, $3); } + | expr '&' expr { BINARY_LONG_OP($$, &, $1, $3); } + | expr '^' expr { BINARY_LONG_OP($$, ^, $1, $3); } + | expr '<' expr { BINARY_OP($$, <, $1, $3); } + | expr '>' expr { BINARY_OP($$, >, $1, $3); } + | expr '+' expr { BINARY_OP($$, +, $1, $3); } + | expr '-' expr { BINARY_OP($$, -, $1, $3); } + | expr '*' expr { BINARY_OP($$, *, $1, $3); } | expr '/' expr { if ($3 == 0) { pr_debug("division by zero\n"); YYABORT;