From: Yury Norov <yury.norov@gmail.com>
To: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, jk@ozlabs.org,
joel@jms.id.au, eajames@linux.ibm.com, andrzej.hajda@intel.com,
neil.armstrong@linaro.org, rfoss@kernel.org,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
dmitry.torokhov@gmail.com, mchehab@kernel.org,
awalls@md.metrocast.net, hverkuil@xs4all.nl,
miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
louis.peens@corigine.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
parthiban.veerasooran@microchip.com,
arend.vanspriel@broadcom.com, johannes@sipsolutions.net,
gregkh@linuxfoundation.org, jirislaby@kernel.org,
akpm@linux-foundation.org, hpa@zytor.com, alistair@popple.id.au,
linux@rasmusvillemoes.dk, Laurent.pinchart@ideasonboard.com,
jonas@kwiboo.se, jernej.skrabec@gmail.com, kuba@kernel.org,
linux-kernel@vger.kernel.org, linux-fsi@lists.ozlabs.org,
dri-devel@lists.freedesktop.org, linux-input@vger.kernel.org,
linux-media@vger.kernel.org, linux-mtd@lists.infradead.org,
oss-drivers@corigine.com, netdev@vger.kernel.org,
linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev,
brcm80211-dev-list.pdl@broadcom.com,
linux-serial@vger.kernel.org, bpf@vger.kernel.org,
jserv@ccns.ncku.edu.tw, david.laight.linux@gmail.com,
andrew.cooper3@citrix.com, Yu-Chun Lin <eleanor15x@gmail.com>
Subject: Re: [PATCH v2 01/18] lib/parity: Add __builtin_parity() fallback implementations
Date: Sat, 1 Mar 2025 22:10:20 -0500 [thread overview]
Message-ID: <Z8PMHLYHOkCZJpOh@thinkpad> (raw)
In-Reply-To: <20250301142409.2513835-2-visitorckw@gmail.com>
On Sat, Mar 01, 2025 at 10:23:52PM +0800, Kuan-Wei Chiu wrote:
> Add generic C implementations of __paritysi2(), __paritydi2(), and
> __parityti2() as fallback functions in lib/parity.c. These functions
> compute the parity of a given integer using a bitwise approach and are
> marked with __weak, allowing architecture-specific implementations to
> override them.
>
> This patch serves as preparation for using __builtin_parity() by
> ensuring a fallback mechanism is available when the compiler does not
> inline the __builtin_parity().
>
> Co-developed-by: Yu-Chun Lin <eleanor15x@gmail.com>
> Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>
> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> ---
> lib/Makefile | 2 +-
> lib/parity.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 49 insertions(+), 1 deletion(-)
> create mode 100644 lib/parity.c
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 7bab71e59019..45affad85ee4 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -51,7 +51,7 @@ obj-y += bcd.o sort.o parser.o debug_locks.o random32.o \
> bsearch.o find_bit.o llist.o lwq.o memweight.o kfifo.o \
> percpu-refcount.o rhashtable.o base64.o \
> once.o refcount.o rcuref.o usercopy.o errseq.o bucket_locks.o \
> - generic-radix-tree.o bitmap-str.o
> + generic-radix-tree.o bitmap-str.o parity.o
> obj-y += string_helpers.o
> obj-y += hexdump.o
> obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
> diff --git a/lib/parity.c b/lib/parity.c
> new file mode 100644
> index 000000000000..a83ff8d96778
> --- /dev/null
> +++ b/lib/parity.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * lib/parity.c
> + *
> + * Copyright (C) 2025 Kuan-Wei Chiu <visitorckw@gmail.com>
> + * Copyright (C) 2025 Yu-Chun Lin <eleanor15x@gmail.com>
> + *
> + * __parity[sdt]i2 can be overridden by linking arch-specific versions.
> + */
> +
> +#include <linux/export.h>
> +#include <linux/kernel.h>
> +
> +/*
> + * One explanation of this algorithm:
> + * https://funloop.org/codex/problem/parity/README.html
I already asked you not to spread this link. Is there any reason to
ignore it?
> + */
> +int __weak __paritysi2(u32 val);
> +int __weak __paritysi2(u32 val)
> +{
> + val ^= val >> 16;
> + val ^= val >> 8;
> + val ^= val >> 4;
> + return (0x6996 >> (val & 0xf)) & 1;
> +}
> +EXPORT_SYMBOL(__paritysi2);
> +
> +int __weak __paritydi2(u64 val);
> +int __weak __paritydi2(u64 val)
> +{
> + val ^= val >> 32;
> + val ^= val >> 16;
> + val ^= val >> 8;
> + val ^= val >> 4;
> + return (0x6996 >> (val & 0xf)) & 1;
> +}
> +EXPORT_SYMBOL(__paritydi2);
> +
> +int __weak __parityti2(u64 val);
> +int __weak __parityti2(u64 val)
> +{
> + val ^= val >> 32;
> + val ^= val >> 16;
> + val ^= val >> 8;
> + val ^= val >> 4;
> + return (0x6996 >> (val & 0xf)) & 1;
> +}
> +EXPORT_SYMBOL(__parityti2);
OK, it seems I wasn't clear enough on the previous round, so I'll try
to be very straightforward now.
To begin with, the difference between __parityti2 and __paritydi2
doesn't exist. I'm seriously. I put them side by side, and there's
no difference at all.
Next, this all is clearly an overengineering. You bake all those weak,
const and (ironically, missing) high-efficient arch implementations.
But you show no evidence that:
- it improves on code generation,
- the drivers care about parity()'s performance, and
- show no perf tests at all.
So you end up with +185/-155 LOCs.
Those +30 lines add no new functionality. You copy-paste the same
algorithm again and again in very core kernel files. This is a no-go
for a nice consolidation series.
In the previous round reviewers gave you quite a few nice suggestions.
H. Peter Anvin suggested to switch the function to return a boolean, I
suggested to make it a macro and even sent you a patch, Jiri and David
also spent their time trying to help you, and became ignored.
Nevertheless. NAK for the series. Whatever you end up, if it comes to
v3, please make it simple, avoid code duplication and run checkpatch.
Thanks,
Yury
next prev parent reply other threads:[~2025-03-02 3:10 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 14:23 [PATCH v2 00/18] Introduce and use generic parity16/32/64 helper Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 01/18] lib/parity: Add __builtin_parity() fallback implementations Kuan-Wei Chiu
2025-03-02 3:10 ` Yury Norov [this message]
2025-03-02 8:20 ` Kuan-Wei Chiu
2025-03-02 16:02 ` Yury Norov
2025-03-02 17:29 ` Kuan-Wei Chiu
2025-03-02 19:09 ` David Laight
2025-03-03 2:47 ` Kuan-Wei Chiu
2025-03-03 12:41 ` David Laight
2025-03-03 15:43 ` Yury Norov
2025-03-03 16:54 ` Kuan-Wei Chiu
2025-03-03 15:25 ` Yury Norov
2025-03-03 15:15 ` Yury Norov
2025-03-03 19:37 ` David Laight
2025-03-01 14:23 ` [PATCH v2 02/18] bitops: Optimize parity8() using __builtin_parity() Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 03/18] bitops: Add parity16(), parity32(), and parity64() helpers Kuan-Wei Chiu
2025-03-05 16:20 ` Simon Horman
2025-03-01 14:23 ` [PATCH v2 04/18] media: media/test_drivers: Replace open-coded parity calculation with parity8() Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 05/18] media: pci: cx18-av-vbi: " Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 06/18] media: saa7115: " Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 07/18] serial: max3100: " Kuan-Wei Chiu
2025-03-01 14:23 ` [PATCH v2 08/18] lib/bch: Replace open-coded parity calculation with parity32() Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 09/18] Input: joystick - " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 10/18] net: ethernet: oa_tc6: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 11/18] wifi: brcm80211: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 12/18] drm/bridge: dw-hdmi: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 13/18] mtd: ssfdc: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 14/18] fsi: i2cr: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 15/18] fsi: i2cr: Replace open-coded parity calculation with parity64() Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 16/18] Input: joystick - " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 17/18] nfp: bpf: " Kuan-Wei Chiu
2025-03-01 14:24 ` [PATCH v2 18/18] bitops: Add parity() macro for automatic type-based selection Kuan-Wei Chiu
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=Z8PMHLYHOkCZJpOh@thinkpad \
--to=yury.norov@gmail.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alistair@popple.id.au \
--cc=andrew+netdev@lunn.ch \
--cc=andrew.cooper3@citrix.com \
--cc=andrzej.hajda@intel.com \
--cc=arend.vanspriel@broadcom.com \
--cc=awalls@md.metrocast.net \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=brcm80211-dev-list.pdl@broadcom.com \
--cc=brcm80211@lists.linux.dev \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eajames@linux.ibm.com \
--cc=edumazet@google.com \
--cc=eleanor15x@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=hverkuil@xs4all.nl \
--cc=jernej.skrabec@gmail.com \
--cc=jirislaby@kernel.org \
--cc=jk@ozlabs.org \
--cc=joel@jms.id.au \
--cc=johannes@sipsolutions.net \
--cc=jonas@kwiboo.se \
--cc=jserv@ccns.ncku.edu.tw \
--cc=kuba@kernel.org \
--cc=linux-fsi@lists.ozlabs.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=louis.peens@corigine.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mchehab@kernel.org \
--cc=mingo@redhat.com \
--cc=miquel.raynal@bootlin.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@corigine.com \
--cc=pabeni@redhat.com \
--cc=parthiban.veerasooran@microchip.com \
--cc=rfoss@kernel.org \
--cc=richard@nod.at \
--cc=simona@ffwll.ch \
--cc=tglx@linutronix.de \
--cc=tzimmermann@suse.de \
--cc=vigneshr@ti.com \
--cc=visitorckw@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).