[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <de705cdf-ccce-460f-846e-dfc63c63af1a@intel.com>
Date: Wed, 16 Oct 2024 12:44:18 -0700
From: Dave Hansen <dave.hansen@...el.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Ingo Molnar <mingo@...nel.org>, Uros Bizjak <ubizjak@...il.com>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
Dennis Zhou <dennis@...nel.org>, Tejun Heo <tj@...nel.org>,
Christoph Lameter <cl@...ux.com>, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>, Bill Wendling
<morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>
Subject: Re: [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when
comparing in percpu_add_op()
On 10/16/24 12:20, Peter Zijlstra wrote:
> The code as is, is wrong, I don't think we'll ever end up in the dec
> case for 'short' unsigned types. Clang is just clever enough to realize
> this and issues a warning.
Ahhh, that's the key to it. Thanks, Peter.
> Something like so might work:
>
> const int pao_ID__ = __builtin_constant_p(val) ?
> ((typeof(var))(val) == 1 ? 1 :
> ((typeof(var))(val) == (typeof(var))-1 ? -1 : 0 )) : 0;
Would anybody hate if we broke this up a bit, like:
const typeof(var) _val = val;
const int paoconst = __builtin_constant_p(val);
const int paoinc = paoconst && ((_val) == 1);
const int paodec = paoconst && ((_val) == (typeof(var))-1);
and then did
if (paoinc)
percpu_unary_op(size, qual, "inc", var);
...
Or even:
#define PAOINC 1234
const int pao_ID__ = __builtin_constant_p(val) ?
((typeof(var))(val) == 1 ? PAOINC :
...
if (PAOINC)
percpu_unary_op(size, qual, "inc", var);
Since the 1 and -1 ternary results end up just being magic numbers
anyway. Otherwise that pao_ID__ expression is pretty gnarly.
Powered by blists - more mailing lists