From nobody Fri Nov 22 19:02:40 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=1716581063; cv=none; d=zohomail.com; s=zohoarc; b=Mho1fvbMu1zwLwtPElNDcy/OBqYdg+T0xATIOY9JrQHUjg/L9Ioy64kzduWgy1rKcJp4yIuC/dH8arFLXNbvknN9P89hvukWM5uLtQGd+/buF65gTcdXo5lDIN92mLG1N8dAWVzY1LdXHiIUa8hen0eioyhQ/8gDU5z53mFqlHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716581063; 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=0OUrbEItmp/7smeXVfEuek5P5UjrbBJNpLNlS999tow=; b=by6ft59wsjuNJQhOl1ta8/DCYGPBVWOerYUh05/3h99SR6joHuODL9dOS7m29/IdisflLooPNTKBGx/ro9NsEPEQCkNxFBWsfeG1UNY6xv1TIzVoCtH4qhIQ+HSmEPW0yvYPSX1EtRGw0SLtlN+E6VaUd2L6XUEdN6T4Pp2wZno= 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 1716581063778283.1897344317339; Fri, 24 May 2024 13:04:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.729756.1135101 (Exim 4.92) (envelope-from ) id 1sAb8x-0001f0-RS; Fri, 24 May 2024 20:03:59 +0000 Received: by outflank-mailman (output) from mailman id 729756.1135101; Fri, 24 May 2024 20:03:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sAb8x-0001e3-AW; Fri, 24 May 2024 20:03:59 +0000 Received: by outflank-mailman (input) for mailman id 729756; Fri, 24 May 2024 20:03:57 +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 1sAb8v-000773-Eb for xen-devel@lists.xenproject.org; Fri, 24 May 2024 20:03:57 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c01d67a2-1a08-11ef-b4bb-af5377834399; Fri, 24 May 2024 22:03:55 +0200 (CEST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a59a609dd3fso649410766b.0 for ; Fri, 24 May 2024 13:03:55 -0700 (PDT) Received: from andrewcoop.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c9377d8sm173553066b.55.2024.05.24.13.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 13:03:54 -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: c01d67a2-1a08-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716581035; x=1717185835; 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=0OUrbEItmp/7smeXVfEuek5P5UjrbBJNpLNlS999tow=; b=u+aF8XMjIi9Fnwe7rnYtGFtvSyasc/4Qvlnxsuz4Ubw+8Y4TfXwt7RvTNBKwerXNB+ zVlnRRtoGYJdivfzyYAg/kzQFenKpxMMOv7VL+gdZt5bNPiUZqf2+5YS+xgt2B4hAtjQ Q72uhwQ7EJxf1QX1BfUhhrZMf9UdnIAXsAfyE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716581035; x=1717185835; 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=0OUrbEItmp/7smeXVfEuek5P5UjrbBJNpLNlS999tow=; b=c9sRBk9pReIdHVEmlzB3wAluzBEeWXksyATgeV0zxOFN2CjranK1Z6cHQ1yqxEnFt2 equzeV+cmwB8REz0HOWA0rPFUMlA2NyFSYuN/39JzLw0mFKm+MsIBur47tamaz5lBvIU rUwOrlBX/i+wI7mg5lDQFtW0V0MpJpEhRharIsRKQ7e4N/kgnARiZqS9GS0itTUosSU2 w9OYP3B9p+6WVe+iXUuZrZ7TEMn/VtC578GGghKmO7W/LObHedwt7Pzo52EnOmLPwrht 62SpIs+NkZTEJP4Zik3YNhemaxt05cLPhjJbrLm/YvF39cauSLTZc2zWj2sKadL4XrNg 8qvQ== X-Gm-Message-State: AOJu0YyXLGoJ9to+O3CBg5HLoh6A5HvBbKylEsTspt9skiYHqmY5z2Du dr2GxnIQW0HBFsz9ZDWY9jxR7j8x6x/qTqMLWXFEYtjA2dPyu/k6PYzUbOSwbix4zVvsdzP7rj+ 4HA8= X-Google-Smtp-Source: AGHT+IFDepIWI/VDxApQZRZYemyfm2VE+hQJWb/SbSRzW6+QTax//5EAno8CL93TfAhRjnW5+HYXQQ== X-Received: by 2002:a17:906:a04e:b0:a62:44e1:3f56 with SMTP id a640c23a62f3a-a6244e14068mr444618466b.37.1716581035180; Fri, 24 May 2024 13:03:55 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH v2 12/13] xen/bitops: Clean up ffs64()/fls64() definitions Date: Fri, 24 May 2024 21:03:37 +0100 Message-Id: <20240524200338.1232391-13-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240524200338.1232391-1-andrew.cooper3@citrix.com> References: <20240524200338.1232391-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: 1716581064661100003 Implement ffs64() and fls64() as plain static inlines, dropping the ifdefary and intermediate generic_f?s64() forms. Add tests for all interesting bit positions at 32bit boundaries. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini v2: * Use ULL rather than a uint64_t cast. * Extend to fls64() too. --- xen/common/bitops.c | 32 ++++++++++++++++++++++++++++++ xen/include/xen/bitops.h | 42 +++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/xen/common/bitops.c b/xen/common/bitops.c index b4845d9e84d1..5482e5a1218d 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -24,6 +24,22 @@ static void __init test_ffs(void) CHECK(ffsl, 1UL << 32, 33); CHECK(ffsl, 1UL << 63, 64); #endif + + /* + * unsigned int ffs64(uint64_t) + * + * 32-bit builds of Xen have to split this into two adjacent operation= s, + * so test all interesting bit positions across the divide. + */ + CHECK(ffs64, 0, 0); + CHECK(ffs64, 1, 1); + CHECK(ffs64, 3, 1); + CHECK(ffs64, 7, 1); + CHECK(ffs64, 6, 2); + + CHECK(ffs64, 0x8000000080000000ULL, 32); + CHECK(ffs64, 0x8000000100000000ULL, 33); + CHECK(ffs64, 0x8000000000000000ULL, 64); } =20 static void __init test_fls(void) @@ -48,6 +64,22 @@ static void __init test_fls(void) CHECK(flsl, 1 | (1UL << 32), 33); CHECK(flsl, 1 | (1UL << 63), 64); #endif + + /* + * unsigned int ffl64(uint64_t) + * + * 32-bit builds of Xen have to split this into two adjacent operation= s, + * so test all interesting bit positions across the divide. + */ + CHECK(fls64, 0, 0); + CHECK(fls64, 1, 1); + CHECK(fls64, 3, 2); + CHECK(fls64, 7, 3); + CHECK(fls64, 6, 3); + + CHECK(fls64, 0x0000000080000001ULL, 32); + CHECK(fls64, 0x0000000100000001ULL, 33); + CHECK(fls64, 0x8000000000000001ULL, 64); } =20 static void __init __constructor test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index e7df6377372d..c5518d2c8552 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -60,6 +60,14 @@ static always_inline __pure unsigned int ffsl(unsigned l= ong x) #endif } =20 +static always_inline __pure unsigned int ffs64(uint64_t x) +{ + if ( BITS_PER_LONG =3D=3D 64 ) + return ffsl(x); + else + return !x || (uint32_t)x ? ffs(x) : ffs(x >> 32) + 32; +} + static always_inline __pure unsigned int fls(unsigned int x) { if ( __builtin_constant_p(x) ) @@ -84,6 +92,18 @@ static always_inline __pure unsigned int flsl(unsigned l= ong x) #endif } =20 +static always_inline __pure unsigned int fls64(uint64_t x) +{ + if ( BITS_PER_LONG =3D=3D 64 ) + return flsl(x); + else + { + uint32_t h =3D x >> 32; + + return h ? fls(h) + 32 : fls(x); + } +} + /* --------------------- Please tidy below here --------------------- */ =20 #ifndef find_next_bit @@ -134,28 +154,6 @@ extern unsigned long find_first_zero_bit(const unsigne= d long *addr, unsigned long size); #endif =20 -#if BITS_PER_LONG =3D=3D 64 -# define fls64 flsl -# define ffs64 ffsl -#else -# ifndef ffs64 -static inline int generic_ffs64(__u64 x) -{ - return !x || (__u32)x ? ffs(x) : ffs(x >> 32) + 32; -} -# define ffs64 generic_ffs64 -# endif -# ifndef fls64 -static inline int generic_fls64(__u64 x) -{ - __u32 h =3D x >> 32; - - return h ? fls(h) + 32 : fls(x); -} -# define fls64 generic_fls64 -# endif -#endif - static inline int get_bitmask_order(unsigned int count) { int order; --=20 2.30.2