From: Dave Hansen <dave.hansen@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Ingo Molnar <mingo@kernel.org>, Uros Bizjak <ubizjak@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Dennis Zhou <dennis@kernel.org>,
Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op()
Date: Wed, 16 Oct 2024 12:44:18 -0700 [thread overview]
Message-ID: <de705cdf-ccce-460f-846e-dfc63c63af1a@intel.com> (raw)
In-Reply-To: <20241016192011.GY17263@noisy.programming.kicks-ass.net>
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.
next prev parent reply other threads:[~2024-10-16 19:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 17:03 [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op() Andy Shevchenko
2024-10-16 13:37 ` Andy Shevchenko
2024-10-16 15:44 ` Dave Hansen
2024-10-16 17:03 ` Nick Desaulniers
2024-10-16 18:06 ` Andy Shevchenko
2024-10-16 18:20 ` Andy Shevchenko
2024-10-16 19:43 ` Dave Hansen
2024-10-16 19:20 ` Peter Zijlstra
2024-10-16 19:44 ` Dave Hansen [this message]
2024-10-17 18:18 ` Peter Zijlstra
2024-10-18 12:21 ` Andy Shevchenko
2024-10-22 19:53 ` Dave Hansen
2024-10-22 23:24 ` Christoph Lameter (Ampere)
2024-10-23 17:15 ` Dave Hansen
2024-10-23 21:40 ` H. Peter Anvin
2024-10-23 14:24 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de705cdf-ccce-460f-846e-dfc63c63af1a@intel.com \
--to=dave.hansen@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bp@alien8.de \
--cc=cl@linux.com \
--cc=dave.hansen@linux.intel.com \
--cc=dennis@kernel.org \
--cc=hpa@zytor.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.