From nobody Thu Dec 26 00:50:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1507798100613226.93744001754885; Thu, 12 Oct 2017 01:48:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D1C3C21F38829; Thu, 12 Oct 2017 01:44:45 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DFEFF21FC7497 for ; Thu, 12 Oct 2017 01:44:44 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 12 Oct 2017 01:48:15 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by FMSMGA003.fm.intel.com with ESMTP; 12 Oct 2017 01:48:14 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,365,1503385200"; d="scan'208";a="909212124" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 12 Oct 2017 16:48:08 +0800 Message-Id: <20171012084810.148196-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20171012084810.148196-1-ruiyu.ni@intel.com> References: <20171012084810.148196-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/4] UefiCpuPkg/MtrrLib: Optimize MtrrLibLeastAlignment() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The patch changes MtrrLibLeastAlignment() to MtrrLibBiggestAlignment() and optimizes the implementation to be more efficient. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Michael D Kinney Cc: Eric Dong --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/Mtrr= Lib/MtrrLib.c index 5b21fe11f1..0fecc0122c 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -656,7 +656,8 @@ MtrrGetMemoryAttributeInVariableMtrr ( } =20 /** - Return the least alignment of address. + Return the biggest alignment (lowest set bit) of address. + The function is equivalent to: 1 << LowBitSet64 (Address). =20 @param Address The address to return the alignment. @param Alignment0 The alignment to return when Address is 0. @@ -664,7 +665,7 @@ MtrrGetMemoryAttributeInVariableMtrr ( @return The least alignment of the Address. **/ UINT64 -MtrrLibLeastAlignment ( +MtrrLibBiggestAlignment ( UINT64 Address, UINT64 Alignment0 ) @@ -673,7 +674,7 @@ MtrrLibLeastAlignment ( return Alignment0; } =20 - return LShiftU64 (1, (UINTN) LowBitSet64 (Address)); + return Address & ((~Address) + 1); } =20 /** @@ -705,12 +706,12 @@ MtrrLibGetPositiveMtrrNumber ( // for (MtrrNumber =3D 0; Length !=3D 0; MtrrNumber++) { if (UseLeastAlignment) { - SubLength =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + SubLength =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); =20 if (SubLength > Length) { // // Set a flag when remaining length is too small - // so that MtrrLibLeastAlignment() is not called in following loo= ps. + // so that MtrrLibBiggestAlignment() is not called in following l= oops. // UseLeastAlignment =3D FALSE; } @@ -873,7 +874,7 @@ MtrrLibGetMtrrNumber ( // Left subtraction bit by bit, to find the optimal left subtraction s= olution. // for (SubtractiveMtrrNumber =3D 0, SubtractiveCount =3D 1; BaseAddress = !=3D 0; SubtractiveCount++) { - Alignment =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); =20 // // Check whether the memory type of [BaseAddress - Alignment, BaseAd= dress) can override Type. @@ -928,7 +929,7 @@ MtrrLibGetMtrrNumber ( // MiddleMtrrNumber =3D 0; while (Length !=3D 0) { - BaseAlignment =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + BaseAlignment =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); if (BaseAlignment > Length) { break; } @@ -953,7 +954,7 @@ MtrrLibGetMtrrNumber ( LeastRightMtrrNumber =3D MtrrLibGetPositiveMtrrNumber (BaseAddress, Leng= th, Alignment0); =20 for (SubtractiveCount =3D 1; Length < BaseAlignment; SubtractiveCount++)= { - Alignment =3D MtrrLibLeastAlignment (BaseAddress + Length, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress + Length, Alignment= 0); if (!MtrrLibSubstractable (Ranges, RangeCount, Type, BaseAddress + Len= gth, Alignment)) { break; } @@ -1644,7 +1645,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( } =20 while (SubtractiveLeft-- !=3D 0) { - Alignment =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); ASSERT (Alignment <=3D Length); =20 MtrrLibAddVariableMtrr (Ranges, RangeCount, VariableMtrr, VariableMtrr= Capacity, VariableMtrrCount, @@ -1654,7 +1655,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( } =20 while (Length !=3D 0) { - Alignment =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); if (Alignment > Length) { break; } @@ -1665,7 +1666,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( } =20 while (SubtractiveRight-- !=3D 0) { - Alignment =3D MtrrLibLeastAlignment (BaseAddress + Length, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress + Length, Alignment= 0); MtrrLibAddVariableMtrr (Ranges, RangeCount, VariableMtrr, VariableMtrr= Capacity, VariableMtrrCount, BaseAddress + Length, Alignment, CacheInvalid,= Alignment0); Length +=3D Alignment; @@ -1674,7 +1675,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( UseLeastAlignment =3D TRUE; while (Length !=3D 0) { if (UseLeastAlignment) { - Alignment =3D MtrrLibLeastAlignment (BaseAddress, Alignment0); + Alignment =3D MtrrLibBiggestAlignment (BaseAddress, Alignment0); if (Alignment > Length) { UseLeastAlignment =3D FALSE; } --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel