public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] Helper to isolate least-significant bit
@ 2026-01-09 16:41 Petr Tesarik
  2026-01-09 16:37 ` [RFC PATCH 1/2] bits: introduce ffs_val() Petr Tesarik
                   ` (3 more replies)
  0 siblings, 4 replies; 36+ messages in thread
From: Petr Tesarik @ 2026-01-09 16:41 UTC (permalink / raw)
  To: Yury Norov, Rasmus Villemoes
  Cc: 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, Kuan-Wei Chiu, Andrew Morton, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Pablo Neira Ayuso,
	Florian Westphal, linux-kernel, Petr Tesarik

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.

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


^ permalink raw reply	[flat|nested] 36+ messages in thread
* [RFC PATCH 0/2] Helper to isolate least-significant bit
@ 2026-01-09 16:37 Petr Tesarik
  2026-01-09 19:11 ` Geert Uytterhoeven
  0 siblings, 1 reply; 36+ messages in thread
From: Petr Tesarik @ 2026-01-09 16:37 UTC (permalink / raw)
  To: Yury Norov, Rasmus Villemoes
  Cc: 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, Kuan-Wei Chiu, Andrew Morton, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Pablo Neira Ayuso,
	Florian Westphal, linux-kernel, Petr Tesarik

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.

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


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2026-01-13  1:40 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-09 16:41 [RFC PATCH 0/2] Helper to isolate least-significant bit Petr Tesarik
2026-01-09 16:37 ` [RFC PATCH 1/2] bits: introduce ffs_val() Petr Tesarik
2026-01-09 17:01   ` Arnd Bergmann
2026-01-09 23:54     ` David Laight
2026-01-09 17:16   ` Yury Norov
2026-01-09 17:46     ` Petr Tesarik
2026-01-09 18:26       ` Yury Norov
2026-01-09 19:27         ` Petr Tesarik
2026-01-09 19:44           ` Yury Norov
2026-01-09 18:50       ` Arnd Bergmann
2026-01-10 10:50   ` David Laight
2026-01-12  8:15   ` Thomas Zimmermann
2026-01-12  8:58     ` Petr Tesarik
2026-01-12 11:22     ` David Laight
2026-01-13  1:40       ` Maciej W. Rozycki
2026-01-09 16:37 ` [RFC PATCH 2/2] treewide, bits: use ffs_val() where it is open-coded Petr Tesarik
2026-01-09 18:19   ` Yury Norov
2026-01-09 19:32     ` Petr Tesarik
2026-01-09 20:19       ` Yury Norov
2026-01-10 10:36     ` Maciej W. Rozycki
2026-01-10 11:54       ` David Laight
2026-01-11  3:15         ` Maciej W. Rozycki
2026-01-11 10:40           ` David Laight
2026-01-11 21:22             ` Maciej W. Rozycki
2026-01-11 23:57               ` David Laight
2026-01-12 11:21                 ` Maciej W. Rozycki
2026-01-12 13:23                   ` David Laight
2026-01-10 16:42       ` Kuan-Wei Chiu
2026-01-10 22:23         ` David Laight
2026-01-11 14:41           ` Kuan-Wei Chiu
2026-01-11 21:22             ` Maciej W. Rozycki
2026-01-09 17:20 ` [RFC PATCH 0/2] Helper to isolate least-significant bit Kuan-Wei Chiu
2026-01-09 18:59   ` Petr Tesarik
2026-01-09 19:26 ` Andrew Cooper
  -- strict thread matches above, loose matches on Subject: below --
2026-01-09 16:37 Petr Tesarik
2026-01-09 19:11 ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox