From nobody Tue Dec 2 02:31:07 2025 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D574D2F5B for ; Wed, 19 Nov 2025 22:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763592147; cv=none; b=FmTb8Vbi1iMcMFPQ9rYac1ZihtdaHycUfXpIaxJNDh4bd5AB59k6za8eyFZ0zFftoX+8XTj1qe620uoZ5wQUUEdPrQc925FdTbYsdr607WBv1Cqs6uXmE2zB8jQplaJYe3n8qlf2hX2VBTjudWYwL7OYrCbRq08aJkEmkEf3oig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763592147; c=relaxed/simple; bh=6yWhhXYgGcUn4QL9ghlc+Ij4NW7mP0lIKRznCASuiwI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=un9t89pk5ri0/hQRKEbDRz5LPBmaKoxkr180K1lGUJNxLS2yMtr3PTTzv8hvfFkdiCBzEO/h9pkpJg6l8+N6zwdx93IqETienvbJua9OijgL6tZoWZo6UamgsHDYlb/XfX4jC0roi1z7T592fbdVPyMiU615ajZsedgw9rQc/4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=pTSbZE29; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="pTSbZE29" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vLqsP-006klz-Vz; Wed, 19 Nov 2025 23:42:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=E5Q/Ca74NTiVrvwxl/o3FqU3Ejo/I/sQOiFlEnXH7TE=; b=pTSbZE291mpIF33Oql0ZIyr7kF fkFBLAlpeY68Zsn3ti4+jN0nPby2+cDoBUzJ27NGRozmgJKG6/bKKyd0YHK1XdXCOR4oCZDx9VldQ bugZ9qH+PScmtQmSlxRBo+WWl4WG7aKj8z/CWY2ks9r5w+1REdSkivzOpjt4cVD/RwH7iYlg80M7C BFEpgBD8s9RMHWPYRMdXWokUDGE7reEkwdv2D3iSu9lVmFPX/+8FC+P3YtfFTjpFftq9Nx4lOK/rv +aNSE9ZuNnG2zYsXBV8eonS3XVcsiJMAaRjIZXbGNpzROkMEAfeTHo+5pRGrA/b8EOV8eXpRw8GSh JifZWE/Q==; Received: from [10.9.9.74] (helo=submission03.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vLqsP-0007ze-Md; Wed, 19 Nov 2025 23:42:13 +0100 Received: by submission03.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vLqsF-00Fos6-29; Wed, 19 Nov 2025 23:42:03 +0100 From: david.laight.linux@gmail.com To: linux-kernel@vger.kernel.org Cc: Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , x86@kernel.org, Yury Norov , David Laight Subject: [PATCH 01/44] x86/asm/bitops: Change the return type of variable__ffs() to unsigned int Date: Wed, 19 Nov 2025 22:40:57 +0000 Message-Id: <20251119224140.8616-2-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251119224140.8616-1-david.laight.linux@gmail.com> References: <20251119224140.8616-1-david.laight.linux@gmail.com> 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" From: David Laight The return type of variable__ffs() is currently 'unsigned long'. This makes the x86 __ffs() be 'unsigned long' whereas the generic version is 'unsigned int'. Similarly change variable_ffz() and ffz(). This may save some REX prefix on 64bit. Detected by some extra checks added to min_t() to detect possible truncation of large values. Signed-off-by: David Laight --- arch/x86/include/asm/bitops.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index c2ce213f2b9b..2e8a954d2e2d 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h @@ -240,7 +240,7 @@ arch_test_bit_acquire(unsigned long nr, const volatile = unsigned long *addr) variable_test_bit(nr, addr); } =20 -static __always_inline __attribute_const__ unsigned long variable__ffs(uns= igned long word) +static __always_inline __attribute_const__ unsigned int variable__ffs(unsi= gned long word) { asm("tzcnt %1,%0" : "=3Dr" (word) @@ -254,12 +254,10 @@ static __always_inline __attribute_const__ unsigned l= ong variable__ffs(unsigned * * Undefined if no bit exists, so code should check against 0 first. */ -#define __ffs(word) \ - (__builtin_constant_p(word) ? \ - (unsigned long)__builtin_ctzl(word) : \ - variable__ffs(word)) +#define __ffs(word) \ + (__builtin_constant_p(word) ? __builtin_ctzl(word) : variable__ffs(word)) =20 -static __always_inline __attribute_const__ unsigned long variable_ffz(unsi= gned long word) +static __always_inline __attribute_const__ unsigned int variable_ffz(unsig= ned long word) { return variable__ffs(~word); } @@ -270,10 +268,8 @@ static __always_inline __attribute_const__ unsigned lo= ng variable_ffz(unsigned l * * Undefined if no zero exists, so code should check against ~0UL first. */ -#define ffz(word) \ - (__builtin_constant_p(word) ? \ - (unsigned long)__builtin_ctzl(~word) : \ - variable_ffz(word)) +#define ffz(word) \ + (__builtin_constant_p(word) ? __builtin_ctzl(~word) : variable_ffz(word)) =20 /* * __fls: find last set bit in word @@ -281,7 +277,7 @@ static __always_inline __attribute_const__ unsigned lon= g variable_ffz(unsigned l * * Undefined if no set bit exists, so code should check against 0 first. */ -static __always_inline __attribute_const__ unsigned long __fls(unsigned lo= ng word) +static __always_inline __attribute_const__ unsigned int __fls(unsigned lon= g word) { if (__builtin_constant_p(word)) return BITS_PER_LONG - 1 - __builtin_clzl(word); --=20 2.39.5