]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bitfield: wire __bf_shf to __builtin_ctzll
authorYury Norov <ynorov@nvidia.com>
Mon, 27 Apr 2026 22:57:05 +0000 (18:57 -0400)
committerYury Norov <ynorov@nvidia.com>
Wed, 20 May 2026 15:18:27 +0000 (11:18 -0400)
__bf_shf() is currently based on built-in ffsll. It's more
straightforward to wire it to __builtin_ctzll, which makes it a pure
rename.

Worth to notice that __builtin_ffsll() is buggy on GCC before 14.1:

  int main() {
      sizeof(struct {
          int t : !(__builtin_ffsll(~0ULL) + 1 < 0);
      });
  }

  test.c: In function 'main':
  test.c:3:21: error: bit-field 't' width not an integer constant
      3 |                 int t : !(__builtin_ffsll(~0ULL) + 1 < 0);
        |                     ^

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124699
Reported-by: Matt Coster <matt.coster@imgtec.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202603222211.A2XiR1YU-lkp@intel.com/
Signed-off-by: Yury Norov <ynorov@nvidia.com>
include/linux/bitfield.h

index 989c214ec8a57a4eb97adf73da2974184e1e2ed7..14f86e455a678b04a4588e80789ab74902324c9c 100644 (file)
@@ -44,7 +44,7 @@
  *  FIELD_MODIFY(REG_FIELD_C, &reg, c);
  */
 
-#define __bf_shf(x) (__builtin_ffsll(x) - 1)
+#define __bf_shf __builtin_ctzll
 
 #define __scalar_type_to_unsigned_cases(type)                          \
                unsigned type:  (unsigned type)0,                       \