From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC7A366DA3 for ; Fri, 9 Jan 2026 17:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767979271; cv=none; b=Rkfa4rf/YdUkq7ygLVusvvDWKdYhQEJxm7+Hna+O6q5htzqqdyJELJZzM6lAVfeDrzLHW5xIn++6oniNrxaC7/ukYMD4PzaKnBdEkozq7wIz4Kc8XjMW8yfUIyc1viSXl7A3ScUTSvfpfNu4YX71E7QRBSwy/BvxVpwl97LMJuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767979271; c=relaxed/simple; bh=nLBxt5TGUXjFp9haq3ep5e7WSOmBrSEo6sao3QxcieQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P376aYca/V/nVE9JZk6wOF7HoTUxR0fThWi/ACA6IRLKqXWV1tPXhR5Wsp8QGMnh57/KPQYW58s9Iw3rNIyarFUWs0Pev7eeyq00ASZt5nhaeozAFo/EPVis09kKf5pPhmHIggwnOZa+76rkDFOUQxAcSqqQylAg3KiI4kmrml4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N5Uiah6Q; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N5Uiah6Q" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2a0d06ffa2aso33443585ad.3 for ; Fri, 09 Jan 2026 09:21:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767979268; x=1768584068; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Oz+ASrkMs+p8l9SaMQc/LhZ4ox/WnQfCGetmdDHPpxc=; b=N5Uiah6QqhQizI5VdkWI0ICWpF5ykA+LCbsR0lQ2E59WHEIzE08bUmVV6iFE/ir3oJ MCrfQmFrjx7wjqMT+PRu4Sj06fYociKhbFz57cYcb0otC/vAQ+Gz+qVWvNsHMZZF8R22 DLMufhC3c8NtPNix5mY40TNTHJONmT4y03Do/QTxnd3KwRhWstC8t73hpU5dXRF3AqCT ddnpER8bHolUHABjTjdbHNxhxDoaSB0Y7EcxdPfPrdJgm1x7KY0Myl1ZB9yIiYR6D+Vv 94llS6Ehsx9N2JlNTduvUrp8B6Sb7VM3K2+ywFUS8FuEXvVyAc3AtRmnlpIBgXVsLYIE dDEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767979268; x=1768584068; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oz+ASrkMs+p8l9SaMQc/LhZ4ox/WnQfCGetmdDHPpxc=; b=EzPmptQ7PbysN7V3z9l2wO2mY2x2LfIfXL+POR/6ZPlAi/zq05+KU84eGZgvsFb+vI zcoNn7lGNNH1vWbFbdvC2zP28N9ZNgDjVx8CvReTCuhhMp92IEFyzYhLDuQxGU+4BnqI 1wOBPQClvvcYW0KetpZR3YXa06CYBjE/j3mnrkUh7hwq4RgbgstL8DhKY6dqaXwljSyf 2LKtkVv70YI7vRh3cKrTaT6liSgG5DGux57SFSX2fkDDeoLusDA3TjYqz1MhKql00cay luilIS7E9E567YVHbqhWtHgd4TEdx3Xw5HK8X70mxgnkFrn4vQyQYJa9977JpUELvOzF Fh7A== X-Forwarded-Encrypted: i=1; AJvYcCVX3BkUrRpwZlphjPzdouvbnx/yohh24+TZtfdk+mdZsRtuiN1wt+XFkRSsGhLpiUxqclP03mPsTs8U7fc=@vger.kernel.org X-Gm-Message-State: AOJu0YzfpCYO6KtNl6d5wAyFQydM00SUxuUzbQxijfk3m/g4tqCdvVzp btCSk7fU+Ow4BLWshdIlHO2MZWOssWjGcNIQlFNQVZ9EHMmEeJctoJvH X-Gm-Gg: AY/fxX6ETPciADUBSolbUngIXmlK5rxdqF3WvWfkx/YUnEmYvve6fQJ74tjkqR3vI6l MNaKjYKrZLzSJ1eBlh1iE6GytCFxpL/vjAxjRSR87ApCPLqeYD5BuwkDhGg7HfJr4iIo8Nk/zvk bOf7IamU0J21W+T6J3vvSkL3ZgIRfbBV6FU/vdWwWjQxZjzt/NwBlep7ayJKYbf+HJvkAVSHeQg cQp4bUJJ5f5ne/J2R+yTHSVIdrVbjJzxfsZSVifm/9S5SsPo/ybprcSRpv/x618Vmoqptzt4j68 yn9oOH1k92vxEsRdQFbqFVmO2kcADIzM+1N6hFgUGJsnkxO21PY07Hvw9kV2DxTCJFKlQS8R/7c MSXYr12Sg4T9b2HFjwhfsgwT/BlBzYRVIJO9IrmLvy2YdW3EbiEE72Rzu2LqDkCvRdXyaiqVhpL v8B72IuLG+l6e8xbPnM1IYZTjSZkuEgF7liP9g7aNcJ9Wj56IsmUAszMatGAAEmBwlhw== X-Google-Smtp-Source: AGHT+IHkcGoOICplH42Oc04x6Of42F9z/4pZQFgfOxhxsHSmX1YZXjLRV04lKz4elPQb6/PAgZpJuQ== X-Received: by 2002:a17:902:f70e:b0:295:ed0:f7bf with SMTP id d9443c01a7336-2a3ee4c3231mr99597575ad.58.1767979267856; Fri, 09 Jan 2026 09:21:07 -0800 (PST) Received: from google.com (61-230-10-74.dynamic-ip.hinet.net. [61.230.10.74]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cc8d76sm110052025ad.84.2026.01.09.09.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 09:21:07 -0800 (PST) Date: Sat, 10 Jan 2026 01:20:59 +0800 From: Kuan-Wei Chiu To: Petr Tesarik Cc: Yury Norov , Rasmus Villemoes , Richard Henderson , Matt Turner , Magnus Lindholm , Vineet Gupta , Geert Uytterhoeven , "Maciej W. Rozycki" , Thomas Bogendoerfer , Madhavan Srinivasan , Michael Ellerman , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Chris Zankel , Max Filippov , Patrik Jakobsson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Robin Murphy , Joerg Roedel , Will Deacon , Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Oliver Neukum , Arnd Bergmann , Andrew Morton , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Pablo Neira Ayuso , Florian Westphal , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 0/2] Helper to isolate least-significant bit Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Hi Petr, On Fri, Jan 09, 2026 at 05:41:34PM +0100, Petr Tesarik wrote: > Isolation of the least significant bit can be achieved with 3 basic > ALU operations which are already open-coded in various places in the > kernel. > > However, since other places less efficient constructs, for example > `1UL << ffs(x)`, I assume the trick is known only to some authors, and > it's worth adding a helper to promote its use. Just out of curiosity, are there any existing users employing 1 << ffs(x) (or other inefficient variants) in performance-critical hotpaths? >From a quick grep, I only found one instance in drivers/clk/ti/mux.c matching the 1 << ffs(x) pattern. However, this doesn't appear to be a bottleneck since it is followed by ti_clk_ll_ops->clk_writel(...). The latency of the MMIO write would likely overshadow the savings of a few ALU cycles. Additionally, it seems that patch #2 focuses on replacing the x & -x implementation with the new API, rather than converting inefficient constructs like 1 << ffs(x) to use ffs_val(). Regards, Kuan-Wei > > Petr Tesarik (2): > bits: introduce ffs_val() > treewide, bits: use ffs_val() where it is open-coded > > arch/alpha/include/asm/bitops.h | 2 +- > arch/alpha/kernel/core_cia.c | 2 +- > arch/alpha/kernel/smp.c | 2 +- > arch/arc/include/asm/bitops.h | 2 +- > arch/m68k/include/asm/bitops.h | 12 +++++------ > arch/mips/dec/ecc-berr.c | 2 +- > arch/mips/include/asm/bitops.h | 4 ++-- > arch/mips/pci/pci-malta.c | 4 ++-- > arch/powerpc/include/asm/bitops.h | 4 ++-- > arch/powerpc/kvm/e500_mmu_host.c | 2 +- > arch/powerpc/lib/sstep.c | 2 +- > arch/powerpc/xmon/ppc-dis.c | 3 ++- > arch/powerpc/xmon/ppc-opc.c | 6 +++--- > arch/s390/include/asm/bitops.h | 2 +- > arch/xtensa/include/asm/bitops.h | 6 +++--- > arch/xtensa/kernel/traps.c | 2 +- > drivers/gpu/drm/gma500/psb_intel_sdvo.c | 2 +- > drivers/iommu/dma-iommu.c | 2 +- > drivers/net/ethernet/netronome/nfp/bpf/jit.c | 2 +- > drivers/net/usb/cdc_ncm.c | 4 ++-- > include/asm-generic/div64.h | 4 ++-- > include/linux/bitfield.h | 3 ++- > include/linux/bitops.h | 1 + > include/linux/ffs_val.h | 21 ++++++++++++++++++++ > include/linux/log2.h | 2 +- > include/linux/min_heap.h | 5 +++-- > lib/math/gcd.c | 4 ++-- > lib/sort.c | 3 ++- > net/bluetooth/mgmt.c | 2 +- > net/netfilter/nft_set_pipapo.c | 2 +- > 30 files changed, 70 insertions(+), 44 deletions(-) > create mode 100644 include/linux/ffs_val.h > > -- > 2.52.0 >