From patchwork Thu Feb 1 12:22:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 13540987 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31DA35F47D; Thu, 1 Feb 2024 12:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790285; cv=none; b=V9NSxMQdbG+3s8epdGVrnA5cqRSnD0bxSZ9hgIuIrveuDYlKtCFsXjpqLAuX9BujoEdWrHaQ4TVRJN5kEHzhl+RtyALSs/GvuLZo2J6LRweg7iIbVyvp5JgJ7VSKzV+yMLvCJQRKbyj9+dz1YmFePsw4xNBwdHZzYfycdYJOXvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790285; c=relaxed/simple; bh=DRgXZrBDaQAbpijEzgcXIBhu1l6MEbkbQ32hkGqS4H4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TwvYhVB/9UMzPibQcTyYxdBKFXnVVXLst5WHZ8nkxgMnUHzdA/Q30WdrjCCl8A8qm4Jl7dvs15m6v15nL3Uetbw2Q5DmiC3VkdDnpadYPJZsvk77zGfOg64f6DtCDcP6hIBzWPXXtA9Fokdb/I2uJkmkvv0JpYCp5e/b9chaaCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Mn2OEGCH; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Mn2OEGCH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706790285; x=1738326285; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DRgXZrBDaQAbpijEzgcXIBhu1l6MEbkbQ32hkGqS4H4=; b=Mn2OEGCHYc8KfseculiWtahpO4NTD1xd+Z3ovEevTP2lx/s85CIf0uRe 6AWzSfxcnRNUTn12kKZV3LVQl04vMR3OBpQx/0zYp/vEyCI3iEGtrLc0N sR8/JKwXzrQRnequHQfsbEYzw0/t4qyj8Mq5jjSLcD2KgtfvXEFTpkCzV Vwui/JUgMJHya9BdXl5RITTep8XPoDPtPiR5kVB+XXvMzOcF+UP3vdR9/ e1wSJzdIaJNyM2lQ+NghnoWQJSloMjDMLpENKrJM/QsxC2i8upjvyKKuL HwuTsobZutkkKg44WmNaWVVysQk/TDVULq/2LCDpQCME2FDPG4WI2aPoW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3747142" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="3747142" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 04:24:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="4499131" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa004.jf.intel.com with ESMTP; 01 Feb 2024 04:24:39 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Michal Swiatkowski , Marcin Szycik , Wojciech Drewek , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jiri Pirko , Ido Schimmel , Przemek Kitszel , Simon Horman , linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 14/21] lib/bitmap: add compile-time test for __assign_bit() optimization Date: Thu, 1 Feb 2024 13:22:09 +0100 Message-ID: <20240201122216.2634007-15-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201122216.2634007-1-aleksander.lobakin@intel.com> References: <20240201122216.2634007-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Commit dc34d5036692 ("lib: test_bitmap: add compile-time optimization/evaluations assertions") initially missed __assign_bit(), which led to that quite a time passed before I realized it doesn't get optimized at compilation time. Now that it does, add test for that just to make sure nothing will break one day. To make things more interesting, use bitmap_complement() and bitmap_full(), thus checking their compile-time evaluation as well. And remove the misleading comment mentioning the workaround removed recently in favor of adding the whole file to GCov exceptions. Reviewed-by: Przemek Kitszel Signed-off-by: Alexander Lobakin Signed-off-by: Yury Norov --- lib/test_bitmap.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index a6e92cf5266a..4ee1f8ceb51d 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -1204,14 +1204,7 @@ static void __init test_bitmap_const_eval(void) * in runtime. */ - /* - * Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }`. - * Clang on s390 optimizes bitops at compile-time as intended, but at - * the same time stops treating @bitmap and @bitopvar as compile-time - * constants after regular test_bit() is executed, thus triggering the - * build bugs below. So, call const_test_bit() there directly until - * the compiler is fixed. - */ + /* Equals to `unsigned long bitmap[1] = { GENMASK(6, 5), }` */ bitmap_clear(bitmap, 0, BITS_PER_LONG); if (!test_bit(7, bitmap)) bitmap_set(bitmap, 5, 2); @@ -1243,6 +1236,15 @@ static void __init test_bitmap_const_eval(void) /* ~BIT(25) */ BUILD_BUG_ON(!__builtin_constant_p(~var)); BUILD_BUG_ON(~var != ~BIT(25)); + + /* ~BIT(25) | BIT(25) == ~0UL */ + bitmap_complement(&var, &var, BITS_PER_LONG); + __assign_bit(25, &var, true); + + /* !(~(~0UL)) == 1 */ + res = bitmap_full(&var, BITS_PER_LONG); + BUILD_BUG_ON(!__builtin_constant_p(res)); + BUILD_BUG_ON(!res); } /*