From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22732C54E67 for ; Wed, 13 Mar 2024 17:27:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.692673.1080048 (Exim 4.92) (envelope-from ) id 1rkSO2-00031b-Cc; Wed, 13 Mar 2024 17:27:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 692673.1080048; Wed, 13 Mar 2024 17:27:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSO2-00031M-9I; Wed, 13 Mar 2024 17:27:30 +0000 Received: by outflank-mailman (input) for mailman id 692673; Wed, 13 Mar 2024 17:27:29 +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 1rkSO1-0001lR-2a for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:29 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f68109f2-e15e-11ee-a1ee-f123f15fe8a2; Wed, 13 Mar 2024 18:27:27 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5686677bda1so2152011a12.0 for ; Wed, 13 Mar 2024 10:27:27 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:25 -0700 (PDT) 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: f68109f2-e15e-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350846; x=1710955646; 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=bHB0TnvHPBNz/eBFlKRD6r+XgGXUhXiQaqNnXVkmHEM=; b=HdiEIEtty4EKP+6iQXwJ7Bt+loJ55OXEBPtpvmCYFUqN3Zef/4qEwlbqVl4y+sErbQ C5d1l+r2Hlloip+TdwNAW+s7lmnLgWbuC85Mpxppq+Q3SMeECWlQ+w72D/VQUlp85RBh YxFOAn7A0or7U7VSza9aFX2gqhvX3Wj0SRnzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350846; x=1710955646; 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=bHB0TnvHPBNz/eBFlKRD6r+XgGXUhXiQaqNnXVkmHEM=; b=Wm22WpHdZS+NjEkcb5Wi90FSbSDCp2Tu8h9JQzWvVkxLPiwDE+Ni11EpEDp822n/0W sPxLNq/kmtVKrATSZaCOj5IxEDXLLRnPOtVWaHcqpeo7G6do12XAdhcKisI+JMlp4o84 xWul3qLDQ7PPbXjjLHAIFeXirNHa5hXrYbTjKOxEdsg8UjcKYqWfYWD7NPzw0LwR73+b yeSJlYuMhbPnpiTHrpqT9it/0jfqlAhHuE0Ds/5CogU3RY9sHWsqdspJ3i7hzSfdqhgr tbUg1Fl4TeYA4gluIAsWtVxIkVjEJ3PZRPrmd3WeBTebKZ8MozQCJcmhKNLUj64S7pKM DoKg== X-Gm-Message-State: AOJu0YxI7yVkuGgvUNwM9/GZH0ccwjvVT/OxIv9JBGprZkpe8oTzfQht tHBQOMBP7jbsNbjVJScMVEYsU8klwSdyv3ywcvBVuFlLnEsQAvAcBtP6fdOak0uxoRVZftGBIUt S X-Google-Smtp-Source: AGHT+IGIO5zs05MQAfaMrOvXvlJvj/CQCBKQvepFuzD0oSVa3+Yg0TZEOonx3qZaJ0qsoNzwif8sQw== X-Received: by 2002:a17:906:b00f:b0:a44:806f:ad56 with SMTP id v15-20020a170906b00f00b00a44806fad56mr2736937ejy.11.1710350846637; Wed, 13 Mar 2024 10:27:26 -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 5/7] xen/bitops: Implement ffs64() in common logic Date: Wed, 13 Mar 2024 17:27:14 +0000 Message-Id: <20240313172716.2325427-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per ffs()/ffsl() in previous patches. Add tests for all interesting bit positions at 32bit boundaries. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné 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 --- xen/common/bitops.c | 12 ++++++++++++ xen/include/xen/bitops.h | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/common/bitops.c b/xen/common/bitops.c index eceffe5029d6..cd194fe672b7 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -47,6 +47,18 @@ static void test_ffs(void) CHECK(ffsl, 1UL << (BITS_PER_LONG - 1), BITS_PER_LONG); if ( BITS_PER_LONG > 32 ) CHECK(ffsl, 1UL << 32, 33); + + /* + * unsigned int ffs64(uint64_t) + * + * 32-bit builds of Xen have to split this into two adjacent operations, + * so test all interesting bit positions. + */ + CHECK(ffs64, 0, 0); + CHECK(ffs64, 1, 1); + CHECK(ffs64, (uint64_t)0x0000000080000000, 32); + CHECK(ffs64, (uint64_t)0x0000000100000000, 33); + CHECK(ffs64, (uint64_t)0x8000000000000000, 64); } static int __init cf_check test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index b85b35c40781..f14ad0d33aa3 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -96,6 +96,14 @@ static always_inline __pure unsigned int ffsl(unsigned long x) return arch_ffsl(x); } +static always_inline __pure unsigned int ffs64(uint64_t x) +{ + if ( BITS_PER_LONG == 64 ) + return ffsl(x); + else + return !x || (uint32_t)x ? ffs(x) : ffs(x >> 32) + 32; +} + /* --------------------- Please tidy below here --------------------- */ #ifndef find_next_bit @@ -148,15 +156,7 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #if BITS_PER_LONG == 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) { -- 2.30.2