[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/4] x86: use POPCNT for hweight<N>() when available
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Wed, 19 Jul 2023 11:44:36 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4bXX4UWXnWt29w89tvGp0cf+LqZaRKTS56ciKBNCO2k=; b=chJPDsN63bGiC5KKPXJoTd/Ee718+TJWIQz+N7KG/UXhGLVojZCGyXcn72ChWvAq40UPzXQbvyt/oeBrJO08GUyzMWx+TW+vOT3qRsa4DoP9HU63rnxmhMfDbGYWl9hwKjemLCwU1IAC+dmMsSVcFPmEcK+E1c7MMyLXMZvflRGyQV5kXl9jgid0Dh+rn6W0IZq83IJoJlNrch81ivk0x/owHrZNXvfXCJPGUk2Ye8aVsKsAMuq+kRc0+17LzuFIu8hiF2m9UwpqoQBToJ5L2f3jgSMVbqwjaWL0foOeynVUmMUe+eYhhSn0PcXCL5FGJodZ/9bqm3zfuVk3TXlCBw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fxhycjgnFzL0sauS7AGzGEQFRuZOGE8SGi7fFiBdSy5mvE4g0LlRZin0lJC57tbF9bZFkTfgaqujqdoEKTUQYeWx5ciYzmEz6ba7OZq6yt9MIxbcwZ0xiL2ne3acZLLByPmOIsPPWaomASKcpgXh+kDoHPvPmKv0N/t+MHqHh4qgvJrIlwSOUsB9b3WGJgGkvEJw3EUeD1lRd/sq7sfyb5Mp9hRU78jYJGhPTOWZfeQGox+lio6ggNw0WanlZcrl/VUIyDti9FGd+Lq8FGZCzUeEMjmGg+uVreaT2Qnz6UEpcBOBrcPV4YZiQ+knYBWbMRQS/1yYtV0rpLBEF5Ge7g==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
- Delivery-date: Wed, 19 Jul 2023 09:44:41 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
This is faster than using the software implementation, and the insn is
available on all half-way recent hardware. Use the respective compiler
builtins when available.
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Reviewed-by: Jason Andryuk <jandryuk@xxxxxxxxx>
--- a/xen/arch/x86/include/asm/bitops.h
+++ b/xen/arch/x86/include/asm/bitops.h
@@ -475,9 +475,16 @@ static inline int fls(unsigned int x)
*
* The Hamming Weight of a number is the total number of bits set in it.
*/
+#ifdef __POPCNT__
+#define hweight64(x) __builtin_popcountll(x)
+#define hweight32(x) __builtin_popcount(x)
+#define hweight16(x) __builtin_popcount((uint16_t)(x))
+#define hweight8(x) __builtin_popcount((uint8_t)(x))
+#else
#define hweight64(x) generic_hweight64(x)
#define hweight32(x) generic_hweight32(x)
#define hweight16(x) generic_hweight16(x)
#define hweight8(x) generic_hweight8(x)
+#endif
#endif /* _X86_BITOPS_H */
|