Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp828236pxb; Wed, 22 Sep 2021 14:00:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwADnJmH7Xw3Uaz/S1ZSNTxJcozlsHxYC7KXRocE2GXXEBQ5ktQ9AREfItdRfti2CQ6rbre X-Received: by 2002:a50:e145:: with SMTP id i5mr1598823edl.16.1632344434602; Wed, 22 Sep 2021 14:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632344434; cv=none; d=google.com; s=arc-20160816; b=Nn3qRG2EHpyHfijwZg2Ddtv1LogWwC5CYHPMWdqcbLFgSaPToZXYNqAiUGyi1ue3NO ms34pbXL30WQyzyYrOWX8qsSkiY5/bptWhgEhMJdAEduJ6Xtk5GdPv0IahfCpT6B6Hjg CJpuJy1/qqdswhBRpNwq1c8o4CoYbUU8Dm1uqnINoAgcBDGcmTxP3lTs4pMxZSzm4WjZ JVyhlQUyR1C9U8CzX3fOT30x2nj6Kckrpjw5MxtwjyWQV1fItVfduaeuKTV5T1+LzMaA 49RPrXEze7mpV1vAAORUhvgLerZfyFnKgr6wwsWgsKZ2H8GC7PoeRcSD+ZU8RIs+KgMp 6C8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hws5eDqR+f2bTbX+cn5+y2+RLzs8dFQl3RKjAF5zxFE=; b=Vs+Xy4p54C9xGwfL3QqQm8homTBhAltGhImzb5eQbyg1RVHPPkTcwXEaumfpzNUr/p 37r65sZxkqUyME2hRzvDdNnXuvM+6ai+bH7M4xifE8oyG7l5wLldUFagMP6/ylf2f3nQ G9L2DJ4Pa7NidQio/RoV75VYdBwaJV83JS+Nq9U7JQAve2IVE2YrXWj9PsZgnChkC1tR I/gRBqcnr6Btmat1IPKirFMLFNiyYU332sX34sNxy6RcsehrSKMUKUPWPQIWsJrFl/o+ B58vOP7w23fZdm+hgLQAEp2MF4gDbvKc1aZ1a2yULWeRZw/8xRB9XqmH+BEBtdw5xBwG 46+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UIt5MCVP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si3812300ejz.183.2021.09.22.14.00.10; Wed, 22 Sep 2021 14:00:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UIt5MCVP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237786AbhIVVAY (ORCPT + 99 others); Wed, 22 Sep 2021 17:00:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45608 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237836AbhIVVAX (ORCPT ); Wed, 22 Sep 2021 17:00:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632344332; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hws5eDqR+f2bTbX+cn5+y2+RLzs8dFQl3RKjAF5zxFE=; b=UIt5MCVPJAmAdBwpbypUkD8nAdYWmecQhCV4oLid+Brwszg0ykoIEBy7+tnss5vdXYqVYH kex+zHK/mJFNlCMSLFoUAaNcEW9Qwoak7lgZh1LvIfxWpLlRfJn+OBLNbTHuaiQ+8W6zFz FOLQFSZCJeQ550R8asUecjl5LW8jj6E= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-tFunXzCVMra5iAMdbzhTRA-1; Wed, 22 Sep 2021 16:58:51 -0400 X-MC-Unique: tFunXzCVMra5iAMdbzhTRA-1 Received: by mail-wr1-f71.google.com with SMTP id c2-20020adfa302000000b0015e4260febdso3254888wrb.20 for ; Wed, 22 Sep 2021 13:58:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hws5eDqR+f2bTbX+cn5+y2+RLzs8dFQl3RKjAF5zxFE=; b=PqAJ9PosXVRoUiSpeVcxp9Tdtz5PXFcS1O2s9xk01mMIznV0hdhY2Fmk63zlLfrouP u0QzI7rzQpITaJYW0TNc8x7GJbxSeDaCUzV4svcMYzwY+bMQ2EKChnvh8W2uqY/SHaJd 72lm7JTns4JASA6mEjWyc7Tm7V9Bxp5ndx7Tso4RhGFQZyFv2f+FTtqB7fcm6dZm8spS 1miA/TINsfgVHqtGuoDVPNiAHvo6/GGh0CFh1ScZjLy2XsZMMSitk/AZxB+LMnxaW7jV suYJ2NVooLCBSQ/1p6SQG5VQ0bVZw71rwApIpQaITfkXThxvOvn7mH7eDVYE9DYQ+7+M J73w== X-Gm-Message-State: AOAM530CRqMXloOBu+X/ntcXMeNF6aK9/svvqlAzJGTZpy79AXPqaP0N jChTQdHW5FjWqy9O0xfVJ+fEGkCl3OkZzyrkJPF7YI7aCcBsOdEDinnE97T8XoB0z/KET1YfL8F 8127CRiVN7Dtq0Tkp3vO37GVx X-Received: by 2002:adf:ded1:: with SMTP id i17mr1079667wrn.83.1632344330225; Wed, 22 Sep 2021 13:58:50 -0700 (PDT) X-Received: by 2002:adf:ded1:: with SMTP id i17mr1079646wrn.83.1632344330023; Wed, 22 Sep 2021 13:58:50 -0700 (PDT) Received: from krava ([83.240.63.48]) by smtp.gmail.com with ESMTPSA id c185sm3320676wma.8.2021.09.22.13.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 13:58:49 -0700 (PDT) Date: Wed, 22 Sep 2021 22:58:47 +0200 From: Jiri Olsa To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , linux-kernel@vger.kernel.org, Andi Kleen , Jin Yao , John Garry , Paul Clarke , kajoljain , linux-perf-users@vger.kernel.org, Stephane Eranian , Sandeep Dasgupta Subject: Re: [PATCH v8 3/8] perf expr: Modify code layout Message-ID: References: <20210918063513.2356923-1-irogers@google.com> <20210918063513.2356923-4-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210918063513.2356923-4-irogers@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 17, 2021 at 11:35:08PM -0700, Ian Rogers wrote: > No functional change. Alter whitespace. Use helper macros that will be > made more complex in a later change. please split into more patches, with the spacing changes it's not easy to check there's no functional change thanks, jirka > > Signed-off-by: Ian Rogers > --- > tools/perf/util/expr.y | 149 +++++++++++++++++++++++------------------ > 1 file changed, 85 insertions(+), 64 deletions(-) > > diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y > index 41c9cd4efadd..51f4f0aa1955 100644 > --- a/tools/perf/util/expr.y > +++ b/tools/perf/util/expr.y > @@ -2,23 +2,10 @@ > %{ > #define YYDEBUG 1 > #include > -#include > -#include "util.h" > #include "util/debug.h" > -#include // strtod() > +#include "smt.h" > #define IN_EXPR_Y 1 > #include "expr.h" > -#include "smt.h" > -#include > - > -static double d_ratio(double val0, double val1) > -{ > - if (val1 == 0) { > - return 0; > - } > - return val0 / val1; > -} > - > %} > > %define api.pure full > @@ -33,11 +20,7 @@ static double d_ratio(double val0, double val1) > char *str; > } > > -%token EXPR_PARSE EXPR_OTHER EXPR_ERROR > -%token NUMBER > -%token ID > -%destructor { free ($$); } > -%token MIN MAX IF ELSE SMT_ON D_RATIO > +%token ID NUMBER MIN MAX IF ELSE SMT_ON D_RATIO EXPR_ERROR EXPR_PARSE EXPR_OTHER > %left MIN MAX IF > %left '|' > %left '^' > @@ -46,6 +29,9 @@ static double d_ratio(double val0, double val1) > %left '-' '+' > %left '*' '/' '%' > %left NEG NOT > +%type NUMBER > +%type ID > +%destructor { free ($$); } > %type expr if_expr > > %{ > @@ -57,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; > + > %} > %% > > @@ -78,49 +70,78 @@ MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/ > '<' | '>' | D_RATIO > > all_expr: if_expr { *final_val = $1; } > - ; > - > -if_expr: > - expr IF expr ELSE expr { $$ = $3 ? $1 : $5; } > - | expr > - ; > - > -expr: NUMBER > - | ID { > - struct expr_id_data *data; > - > - $$ = NAN; > - if (expr__resolve_id(ctx, $1, &data) == 0) > - $$ = expr_id_data__value(data); > - > - 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 { if ($3 == 0) { > - pr_debug("division by zero\n"); > - YYABORT; > - } > - $$ = $1 / $3; > - } > - | expr '%' expr { if ((long)$3 == 0) { > - pr_debug("division by zero\n"); > - YYABORT; > - } > - $$ = (long)$1 % (long)$3; > - } > - | '-' expr %prec NEG { $$ = -$2; } > - | '(' if_expr ')' { $$ = $2; } > - | MIN '(' expr ',' expr ')' { $$ = $3 < $5 ? $3 : $5; } > - | MAX '(' expr ',' expr ')' { $$ = $3 > $5 ? $3 : $5; } > - | SMT_ON { $$ = smt_on() > 0; } > - | D_RATIO '(' expr ',' expr ')' { $$ = d_ratio($3,$5); } > - ; > > -%% > +if_expr: expr IF expr ELSE expr > +{ > + $$ = $3 ? $1 : $5; > +} > +| expr > +; > + > +expr: NUMBER > +{ > + $$ = $1; > +} > +| ID > +{ > + struct expr_id_data *data; > + > + $$ = NAN; > + if (expr__resolve_id(ctx, $1, &data) == 0) > + $$ = expr_id_data__value(data); > + > + free($1); > +} > +| 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; > + } > + $$ = $1 / $3; > +} > +| expr '%' expr > +{ > + if ((long)$3 == 0) { > + pr_debug("division by zero\n"); > + YYABORT; > + } > + $$ = (long)$1 % (long)$3; > +} > +| D_RATIO '(' expr ',' expr ')' > +{ > + if ($5 == 0) { > + $$ = 0; > + } else { > + $$ = $3 / $5; > + } > +} > +| '-' expr %prec NEG > +{ > + $$ = -$2; > +} > +| '(' if_expr ')' > +{ > + $$ = $2; > +} > +| MIN '(' expr ',' expr ')' > +{ > + $$ = $3 < $5 ? $3 : $5; > +} > +| MAX '(' expr ',' expr ')' > +{ > + $$ = $3 > $5 ? $3 : $5; > +} > +| SMT_ON > +{ > + $$ = smt_on() > 0 ? 1.0 : 0.0; > +} > +; > -- > 2.33.0.464.g1972c5931b-goog >