[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8q6wPWXImCeGI8P@visitorckw-System-Product-Name>
Date: Fri, 7 Mar 2025 17:22:08 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: Jiri Slaby <jirislaby@...nel.org>
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, jk@...abs.org,
joel@....id.au, eajames@...ux.ibm.com, andrzej.hajda@...el.com,
neil.armstrong@...aro.org, rfoss@...nel.org,
maarten.lankhorst@...ux.intel.com, mripard@...nel.org,
tzimmermann@...e.de, airlied@...il.com, simona@...ll.ch,
dmitry.torokhov@...il.com, mchehab@...nel.org,
awalls@...metrocast.net, hverkuil@...all.nl,
miquel.raynal@...tlin.com, richard@....at, vigneshr@...com,
louis.peens@...igine.com, andrew+netdev@...n.ch,
davem@...emloft.net, edumazet@...gle.com, pabeni@...hat.com,
parthiban.veerasooran@...rochip.com, arend.vanspriel@...adcom.com,
johannes@...solutions.net, gregkh@...uxfoundation.org,
yury.norov@...il.com, akpm@...ux-foundation.org, hpa@...or.com,
alistair@...ple.id.au, linux@...musvillemoes.dk,
Laurent.pinchart@...asonboard.com, jonas@...boo.se,
jernej.skrabec@...il.com, kuba@...nel.org,
linux-kernel@...r.kernel.org, linux-fsi@...ts.ozlabs.org,
dri-devel@...ts.freedesktop.org, linux-input@...r.kernel.org,
linux-media@...r.kernel.org, linux-mtd@...ts.infradead.org,
oss-drivers@...igine.com, netdev@...r.kernel.org,
linux-wireless@...r.kernel.org, brcm80211@...ts.linux.dev,
brcm80211-dev-list.pdl@...adcom.com, linux-serial@...r.kernel.org,
bpf@...r.kernel.org, jserv@...s.ncku.edu.tw,
Yu-Chun Lin <eleanor15x@...il.com>
Subject: Re: [PATCH v3 00/16] Introduce and use generic parity16/32/64 helper
Hi Jiri,
On Fri, Mar 07, 2025 at 07:57:48AM +0100, Jiri Slaby wrote:
> On 06. 03. 25, 17:25, Kuan-Wei Chiu wrote:
> > Several parts of the kernel contain redundant implementations of parity
> > calculations for 16/32/64-bit values. Introduces generic
> > parity16/32/64() helpers in bitops.h, providing a standardized
> > and optimized implementation.
> >
> > Subsequent patches refactor various kernel components to replace
> > open-coded parity calculations with the new helpers, reducing code
> > duplication and improving maintainability.
> >
> > Co-developed-by: Yu-Chun Lin <eleanor15x@...il.com>
> > Signed-off-by: Yu-Chun Lin <eleanor15x@...il.com>
> > Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
> > ---
> > In v3, I use parityXX() instead of the parity() macro since the
> > parity() macro may generate suboptimal code and requires special hacks
> > to make GCC happy. If anyone still prefers a single parity() macro,
> > please let me know.
>
> What is suboptimal and where exactly it matters? Have you actually measured
> it?
>
In the previous thread, David and Yury had different opinions regarding
the implementation details of the parity() macro. I am trying to find a
solution that satisfies most people while keeping it as simple as
possible.
I cannot point to any specific users who are particularly concerned
about efficiency, so personally, I am not really concerned about the
generated code either. However, I am not a fan of the #if gcc #else
approach, and Yury also mentioned that he does not like the >> 16 >> 16
hack. At the same time, David pointed out that GCC might generate
double-register math. Given these concerns, I leaned toward reverting
to the parityXX() approach.
If you still prefer using the parity() macro, we can revisit and
discuss its implementation details further.
> > Additionally, I changed parityXX() << y users to !!parityXX() << y
> > because, unlike C++, C does not guarantee that true casts to int as 1.
>
> How comes? ANSI C99 exactly states:
> ===
> true
> which expands to the integer constant 1,
> ===
>
I gave a more detailed response in my reply to Peter. If we can confirm
that casting bool to int will only result in 1 or 0, I will remove the
!! hack in the next version.
Regards,
Kuan-Wei
Powered by blists - more mailing lists