From nobody Sat Nov 23 15:16:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1724882673; cv=none; d=zohomail.com; s=zohoarc; b=bvgaxjXpJ76bmIVmN5edzRuTC3fFOsZ+DmEjlLWBSOpwSKhqifcFCI+y5esPR339ysSulyJLx7kJhvtO6zitEkdNqTk9tVDYidebcxYmTc5rxiPR937QEhHMo1N5AB5zB8QW3tz6gxpHY8hCG80EHwRNM5xbCMVTHgiWYB+IyB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724882673; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RsrqcBVubseMkc2czg+d/Lcx765jVnGIyUSplcSJKR4=; b=K79ANaT3umn4Sg3F+SWlxRJg1L2bmK35XPSekv6MbZyIkwSRBjnzO5dOLIcp6AgGD1teY9XVLzchcHf6DRDIzji4UEAJTtosZE97UdxZZX7GK5XHCRoUnhIFCiZ+f+HTQ0JsSkn1GtG7itKSgC9Qxw845xdZmYO8utLPrcslDPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724882673968656.8036252905243; Wed, 28 Aug 2024 15:04:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.785173.1194666 (Exim 4.92) (envelope-from ) id 1sjQlz-0000bD-0V; Wed, 28 Aug 2024 22:04:15 +0000 Received: by outflank-mailman (output) from mailman id 785173.1194666; Wed, 28 Aug 2024 22:04:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sjQly-0000b1-Sn; Wed, 28 Aug 2024 22:04:14 +0000 Received: by outflank-mailman (input) for mailman id 785173; Wed, 28 Aug 2024 22:04:13 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sjQlw-0006E8-Sa for xen-devel@lists.xenproject.org; Wed, 28 Aug 2024 22:04:12 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7474ae6a-6589-11ef-99a0-01e77a169b0f; Thu, 29 Aug 2024 00:04:11 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4280ca0791bso65455495e9.1 for ; Wed, 28 Aug 2024 15:04:11 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2d2esm2695898a12.16.2024.08.28.15.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 15:04:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7474ae6a-6589-11ef-99a0-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1724882650; x=1725487450; darn=lists.xenproject.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=RsrqcBVubseMkc2czg+d/Lcx765jVnGIyUSplcSJKR4=; b=D3CKCn9t1BNiwkxkuLB+WwvPpw6Z8+6Lv73F3ZbjFcxLTqE7sJsLZXmbf3DoYTqCBv pFBV+/xjXWrPpVPbltFHpDpiM4efF25Ja+hA5Tqd6c5Tcm+Zuvdb7jNGHv0FQZIo9zLW 5jOY3XwvAu/sqs3HIbRyRL+0/AiSociLXnE2A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724882650; x=1725487450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RsrqcBVubseMkc2czg+d/Lcx765jVnGIyUSplcSJKR4=; b=RZfJnFEddSefUo7KtSwOQHkhZ2FeqKTsr8trj2g5EuLa0pLTm4iksrfKcgcopDQbhV l44moESqNRBBIeXsrCeYQuGyXEcgy5KPa6Dfpfd6zwWYKZO9qKrYi1wjhypqIAy7cTmy 8FMR8cTC0CdJBZVZZzcIkNZhLUtUQ4TKn4tn0HFt/AKEAqJCC83R299kISL37nSo8pZ2 zWPUXTkinkt7XtMpyYH2sTWQNNy9clqqHKU4o91HICDEc2YmTkS3logEQ5vHyyiaPHtW Hfs0+EWoca+FgayY/UR5gTiZMMzZUGI8pT1MU979+ZcVVM7D3sd3+H2XjsUtRax6Vg5N 2Tcg== X-Gm-Message-State: AOJu0YwioL/bi11+y0f3b4GyZui6fhckNTdZ8iy8WOQ+8qQHMKudbx2X /GxQonCu7IOvsLcd6aaNWtinV1Ccmlvfi3m3JmKWY1fB490EoqfaXIvataDmcAi1ZExW0OQmzih K X-Google-Smtp-Source: AGHT+IH9thU/Kzrpd446ZuHrwCQxl0T9VP7RRAW0814zcCW2MU0Qfv9Jbyb29dJP8AwWWDR2moSOtQ== X-Received: by 2002:a05:6000:b89:b0:371:846d:12b3 with SMTP id ffacd0b85a97d-3749b54d1abmr469774f8f.28.1724882649798; Wed, 28 Aug 2024 15:04:09 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio Subject: [PATCH v2 10/11] xen/bitops: Implement hweight64() in terms of hweight{l,32}() Date: Wed, 28 Aug 2024 23:03:50 +0100 Message-Id: <20240828220351.2686408-11-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828220351.2686408-1-andrew.cooper3@citrix.com> References: <20240828220351.2686408-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1724882675506116600 ... and drop generic_hweight{32,64}(). This is identical on all architectures except ARM32. Add one extra SELF_TE= ST to check that hweight64() works when the input is split in half. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio v2: * Reorder with respect to the hweight32() patch * s/__pure/attr_const/ --- xen/arch/arm/include/asm/bitops.h | 8 ------ xen/arch/ppc/include/asm/bitops.h | 8 ------ xen/arch/x86/include/asm/bitops.h | 8 ------ xen/common/bitops.c | 3 +++ xen/include/xen/bitops.h | 45 ++++++------------------------- 5 files changed, 11 insertions(+), 61 deletions(-) diff --git a/xen/arch/arm/include/asm/bitops.h b/xen/arch/arm/include/asm/b= itops.h index b28c25b3d52d..f163d9bb4578 100644 --- a/xen/arch/arm/include/asm/bitops.h +++ b/xen/arch/arm/include/asm/bitops.h @@ -78,14 +78,6 @@ bool clear_mask16_timeout(uint16_t mask, volatile void *= p, #define arch_fls(x) ((x) ? 32 - __builtin_clz(x) : 0) #define arch_flsl(x) ((x) ? BITS_PER_LONG - __builtin_clzl(x) : 0) =20 -/** - * hweightN - returns the hamming weight of a N-bit word - * @x: the word to weigh - * - * The Hamming Weight of a number is the total number of bits set in it. - */ -#define hweight64(x) generic_hweight64(x) - #endif /* _ARM_BITOPS_H */ /* * Local variables: diff --git a/xen/arch/ppc/include/asm/bitops.h b/xen/arch/ppc/include/asm/b= itops.h index f488a7c03425..c942e9432e20 100644 --- a/xen/arch/ppc/include/asm/bitops.h +++ b/xen/arch/ppc/include/asm/bitops.h @@ -126,12 +126,4 @@ static inline int test_and_set_bit(unsigned int nr, vo= latile void *addr) =20 #define arch_hweightl(x) __builtin_popcountl(x) =20 -/** - * hweightN - returns the hamming weight of a N-bit word - * @x: the word to weigh - * - * The Hamming Weight of a number is the total number of bits set in it. - */ -#define hweight64(x) __builtin_popcountll(x) - #endif /* _ASM_PPC_BITOPS_H */ diff --git a/xen/arch/x86/include/asm/bitops.h b/xen/arch/x86/include/asm/b= itops.h index 507b043b8a86..642d8e58b288 100644 --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -475,12 +475,4 @@ static always_inline unsigned int arch_flsl(unsigned l= ong x) } #define arch_flsl arch_flsl =20 -/** - * hweightN - returns the hamming weight of a N-bit word - * @x: the word to weigh - * - * The Hamming Weight of a number is the total number of bits set in it. - */ -#define hweight64(x) generic_hweight64(x) - #endif /* _X86_BITOPS_H */ diff --git a/xen/common/bitops.c b/xen/common/bitops.c index 5e5d20d225d7..91ae961440af 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -144,6 +144,9 @@ static void __init test_hweight(void) =20 CHECK(hweightl, 1 | (1UL << (BITS_PER_LONG - 1)), 2); CHECK(hweightl, -1UL, BITS_PER_LONG); + + /* unsigned int hweight64(uint64_t) */ + CHECK(hweight64, -1ULL, 64); } =20 static void __init __constructor test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index a462c3065158..c4cb432eed23 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -331,6 +331,14 @@ static always_inline attr_const unsigned int hweight32= (uint32_t x) return hweightl(x); } =20 +static always_inline attr_const unsigned int hweight64(uint64_t x) +{ + if ( BITS_PER_LONG =3D=3D 64 ) + return hweightl(x); + else + return hweight32(x >> 32) + hweight32(x); +} + /* --------------------- Please tidy below here --------------------- */ =20 #ifndef find_next_bit @@ -399,43 +407,6 @@ static inline int get_count_order(unsigned int count) return order; } =20 -/* - * hweightN: returns the hamming weight (i.e. the number - * of bits set) of a N-bit word - */ - -static inline unsigned int generic_hweight32(unsigned int w) -{ - w -=3D (w >> 1) & 0x55555555; - w =3D (w & 0x33333333) + ((w >> 2) & 0x33333333); - w =3D (w + (w >> 4)) & 0x0f0f0f0f; - - if ( IS_ENABLED(CONFIG_HAS_FAST_MULTIPLY) ) - return (w * 0x01010101) >> 24; - - w +=3D w >> 8; - - return (w + (w >> 16)) & 0xff; -} - -static inline unsigned int generic_hweight64(uint64_t w) -{ - if ( BITS_PER_LONG < 64 ) - return generic_hweight32(w >> 32) + generic_hweight32(w); - - w -=3D (w >> 1) & 0x5555555555555555UL; - w =3D (w & 0x3333333333333333UL) + ((w >> 2) & 0x3333333333333333UL); - w =3D (w + (w >> 4)) & 0x0f0f0f0f0f0f0f0fUL; - - if ( IS_ENABLED(CONFIG_HAS_FAST_MULTIPLY) ) - return (w * 0x0101010101010101UL) >> 56; - - w +=3D w >> 8; - w +=3D w >> 16; - - return (w + (w >> 32)) & 0xFF; -} - /* * rol32 - rotate a 32-bit value left * --=20 2.39.2