[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 4/5] x86: use POPCNT for hweight<N>() when available
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Wed, 26 Jul 2023 12:34:37 +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=b3P2K6SwCJdzJ1CDg60+v4aRD7vZ7uC3BReNRQD222Q8qeJFAhiFGS2oth9oZJFshJvSkFLsk4ijgzhl46LZpUa4KmR3A/wLzweFDFM0bGKI+fkjMmjT6HEAiOpVn519xYJwdTxUiO+uGqCwLIHthhG0Bsm73ZpxJGX+RC9Sop/xj/CU6xWoPlPTnVVAizYjNlm5EoyU/R+G94iaJ7uIFAs113R+B2hnzGIUF3txw5RUnuIqisPxjTF+SM95+6rPXlp3yGL40WA/Z/nZGTW4aNfURKRVnXPEj84GXI8EjuPyW+TuyT8QRFizi57zAXs/181fcomMjXsfJ79QZbIMqQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kki6fVBK4bJS/poodZ3FhNqFU38J2KWcqpy5QhAKDaeYBkVtqlKLOkexGP2M4azXVey2Y9bTYYmO7/G2GdXQyWmsu5VA8vyAgrSNhwlI8AwTZrnGcwqd0uHnfoD36dZ52jEDAwH9fCa5cDFaDINEpUjeNVsqGnzmKFA/HTHluDr9Dh/bDRtvvvGuFx5OPkEdclOdy7m1Kc6uX1x0kU+W2uqF0QbAsBaLRqKZPoEFmR+Qb2XraEfvvZvdKCgp4D+E9dgLd/SiXCNDFr30SESDFUNtZrOUThvq5acRKOIbdFXxxrwUsCW4eeB9hYH5yVZkW4bevBTnqaNO32QDBsveIA==
- 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, 26 Jul 2023 10:34:43 +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 */
|