From nobody Wed Feb 11 06:31:19 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 70C17363C77 for ; Fri, 9 Jan 2026 16:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767976687; cv=none; b=vDgl2TD9oPSeibRC+p8y0E0GkkOZOHG+cm3JJrNQZ+jiqTQKwco/ULXPT/r/JzlBNaJ3+6HXylEuW7cZs2wbstMQRE6nuJRErMQcPZ/EOkI7Xy2lFzc96f+t0GDb0vQ2Pe+9nvPiU03w2zn8wMZUQ047HjO6JMGQi4CbPf6ibiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767976687; c=relaxed/simple; bh=JPp51UYXAdu5h5TZ9iFTxsw1s8VmAi+Cj1InFGSHlNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NNizK/RkTWmAbWCsCdcWHT4O3qq4vUdfopdfjWt4LdzNYeDhGieqKV8e/S93x1i6JF+nV3VWTqiW1i7pDsZHR8cLUTYZ1byJzXWmxjBIKS/SskzagSR9GlCDkYE/4nfWJJLiq+mxQLX0XkbyicqMKbIb3mei3FVU2BwTjGA9iyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=LZMcJ4M4; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="LZMcJ4M4" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4775dbde730so4054165e9.3 for ; Fri, 09 Jan 2026 08:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1767976682; x=1768581482; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TOsS0o5WhXmlABnZ+SEM7YDF3bMjaJp0tqP8URi3YSE=; b=LZMcJ4M4EfNGV+KtFK4KXvEFqmS+Siej4QFqhQvR8phxBHT1ZJCXyegA/nB70DlPWz cc98mNLwlKIf+nPOpIi/Od1esNP8P/Iy+pq8FxpZ8fTM4f5aJBJP5jxvM71a5OPlfg61 4U4PB6fWLXlxMda+MsXwWxA5c/gGilcHa5JX5Wa7wmkMLXGazhuppis+OxByDg201Ll5 GbKon8NCkcxxcgxvG8Omte29//j64ZZXKstWL6/vWjLX+OtlkHFzB+i8fGEG1ThV8BmR vpAoOfHxDN3bmUYkft92hAg0I24n7tEj4AoJkrl9fYre5x93laYDddNoS0PC5XPNvpvK oqVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767976682; x=1768581482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TOsS0o5WhXmlABnZ+SEM7YDF3bMjaJp0tqP8URi3YSE=; b=ornO/bZUIqPcb2sigujeXGQ+YbheK5wrHRlzZBVeaqqVVKbI2nqKgfzGP1xFIzQnci KU0bDgDrUMDPhyhef88o7y7UWSYK3wgI8khN2GXGuzzY1zGsJ6manyNxhBCA35AQyKuy aRE7iaewigoCzAFcf3zQIgoAMLxqnmsp5Oum4mJE1+3cORse6M2ynx/Xs/e+ettnW6m/ fyVr0KNSRD23TI2Pmdvt9T4GO4v/1/YmRiEkO7ia6Tiu8T0Z5aJHvhY00h2q2gOtji+L 0sseBBcxRIbjTBK1uv8XOAisUjzwynzgi8CzuZO9KDjGZaDqJIMIUE3a7bESNTpO+/VB EoMQ== X-Forwarded-Encrypted: i=1; AJvYcCUh4XMuygfwShts5rVBvN5law+AxcHMlOXQhKxF6d/3d7NIT68Gb5cGdbDUyDOwVS4K/asXvuqYtX1V89Q=@vger.kernel.org X-Gm-Message-State: AOJu0YybDPPj+2eRVYLtzRD95vcOqyFhU1T+CbHunkusoZEwE/T91v+0 WReQ6eKY0GSLSPTVS9WfSfZhmWSXuLhnLMv7zByIQojvpe3DQc9tcyX30oI3vTbOkLc= X-Gm-Gg: AY/fxX6aPe3TrgrdeziyeBEU/k/a3RhsR3UPwTLo1IvNw4R44LNpf65CcOC7fiR+fNj B/ZioY51ufTtYJxnzq71trBjtHQ5UVfbpixFU8g+3kwOLIY0FK69eqC95c2Egl6n07v794W2eTv 0X7LBZ3M+IV3UN7u8P14eUWMECK7U/DXgOfseoSRftzW74xOwUdvPtprzXzebn1EUQtK7Gre8FB 29+zD6s4HvNeTKZDJck6z8aUuea8fBiyQk6u+jdqJMSd9kujpRwkTiS37HRcN+YyZwqTSY2ESll 6ARkOoQMosgF3ObrSUS4PWjqNonVrdGYVX+14rNGRCjr3dJnHZ5L8/bOUyD9vK6SDNrzXjJJvvG xIyxmIkAzk6lBrRTcqiQn6j7B57OvvVCqhWC5oay7xhNscMINSgK4de2URYSPdjFIxCgGroHGs7 OI2DmBVWV5iS4uAHOv8VwJw+as/AiM/gm4ZZB5singdCUlnn1sMle+irJIQCdX8lH1HpXm4DElb 1HsrA== X-Google-Smtp-Source: AGHT+IFRiZEr4gA30761Oo3G+7mcb5dJTa4el2SKHgg6AE1oJTviaOcgofOte2zcQ8zPFgRyY0yCfQ== X-Received: by 2002:a05:600c:6489:b0:477:a6f1:499d with SMTP id 5b1f17b1804b1-47d84b338a0mr69543485e9.3.1767976681965; Fri, 09 Jan 2026 08:38:01 -0800 (PST) Received: from localhost (dynamic-2a00-1028-83b8-1e7a-3010-3bd6-8521-caf1.ipv6.o2.cz. [2a00:1028:83b8:1e7a:3010:3bd6:8521:caf1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d7f620ac8sm209009855e9.0.2026.01.09.08.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 08:38:01 -0800 (PST) From: Petr Tesarik 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@vger.kernel.org, Petr Tesarik Subject: [RFC PATCH 1/2] bits: introduce ffs_val() Date: Fri, 9 Jan 2026 17:37:56 +0100 Message-ID: <9767487fcab7dbe7a7282a48a492171629eb935b.1767975412.git.ptesarik@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a macro that can efficiently extract the least significant non-zero bit from a value. Interestingly, this bit-twiddling trick is open-coded in some places, but it also appears to be little known, leading to various inefficient implementations in other places. Let's make it part of the standard bitops arsenal. Define the macro in a separate header file included from , to allow using it in very low-level header files that may not want to include all of . Signed-off-by: Petr Tesarik --- MAINTAINERS | 1 + include/linux/bitops.h | 1 + include/linux/ffs_val.h | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 include/linux/ffs_val.h diff --git a/MAINTAINERS b/MAINTAINERS index a0dd762f5648b..8f15c76a67ea2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4466,6 +4466,7 @@ F: arch/*/lib/bitops.c F: include/asm-generic/bitops F: include/asm-generic/bitops.h F: include/linux/bitops.h +F: include/linux/ffs_val.h F: lib/hweight.c F: lib/test_bitops.c F: tools/*/bitops* diff --git a/include/linux/bitops.h b/include/linux/bitops.h index ea7898cc59039..209f0c3e07b9e 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -4,6 +4,7 @@ =20 #include #include +#include #include =20 #include diff --git a/include/linux/ffs_val.h b/include/linux/ffs_val.h new file mode 100644 index 0000000000000..193ec86d2b53b --- /dev/null +++ b/include/linux/ffs_val.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_LINUX_FFS_VAL_H_ +#define _ASM_LINUX_FFS_VAL_H_ + +/** + * ffs_val - find the value of the first set bit + * @x: the value to search + * + * Unlike ffs(), which returns a bit position, ffs_val() returns the bit + * value itself. + * + * Returns: + * least significant non-zero bit, 0 if all bits are zero + */ +#define ffs_val(x) \ +({ \ + const typeof(x) val__ =3D (x); \ + val__ & -val__; \ +}) + +#endif /* _ASM_LINUX_FFS_VAL_H_ */ --=20 2.52.0