diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2017-09-27 17:47:37 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2017-10-16 13:09:45 +0800 |
commit | 1416ecb4a96fd6e4999db2a9977e8384a2a7f8c8 (patch) | |
tree | 98bfb6be143d5d0f21b419c3ac09d2bab4c0651b /UefiCpuPkg | |
parent | 5fbb5adea821efdc036b70f9d9d4d318d5c4b5c7 (diff) | |
download | edk2-1416ecb4a96fd6e4999db2a9977e8384a2a7f8c8.zip edk2-1416ecb4a96fd6e4999db2a9977e8384a2a7f8c8.tar.gz edk2-1416ecb4a96fd6e4999db2a9977e8384a2a7f8c8.tar.bz2 |
UefiCpuPkg/MtrrLib: Optimize MtrrLibLeastAlignment()
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 <ruiyu.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r-- | UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 5b21fe1..0fecc01 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -656,7 +656,8 @@ MtrrGetMemoryAttributeInVariableMtrr ( }
/**
- Return the least alignment of address.
+ Return the biggest alignment (lowest set bit) of address.
+ The function is equivalent to: 1 << LowBitSet64 (Address).
@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;
}
- return LShiftU64 (1, (UINTN) LowBitSet64 (Address));
+ return Address & ((~Address) + 1);
}
/**
@@ -705,12 +706,12 @@ MtrrLibGetPositiveMtrrNumber ( //
for (MtrrNumber = 0; Length != 0; MtrrNumber++) {
if (UseLeastAlignment) {
- SubLength = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ SubLength = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
if (SubLength > Length) {
//
// Set a flag when remaining length is too small
- // so that MtrrLibLeastAlignment() is not called in following loops.
+ // so that MtrrLibBiggestAlignment() is not called in following loops.
//
UseLeastAlignment = FALSE;
}
@@ -873,7 +874,7 @@ MtrrLibGetMtrrNumber ( // Left subtraction bit by bit, to find the optimal left subtraction solution.
//
for (SubtractiveMtrrNumber = 0, SubtractiveCount = 1; BaseAddress != 0; SubtractiveCount++) {
- Alignment = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
//
// Check whether the memory type of [BaseAddress - Alignment, BaseAddress) can override Type.
@@ -928,7 +929,7 @@ MtrrLibGetMtrrNumber ( //
MiddleMtrrNumber = 0;
while (Length != 0) {
- BaseAlignment = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ BaseAlignment = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
if (BaseAlignment > Length) {
break;
}
@@ -953,7 +954,7 @@ MtrrLibGetMtrrNumber ( LeastRightMtrrNumber = MtrrLibGetPositiveMtrrNumber (BaseAddress, Length, Alignment0);
for (SubtractiveCount = 1; Length < BaseAlignment; SubtractiveCount++) {
- Alignment = MtrrLibLeastAlignment (BaseAddress + Length, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress + Length, Alignment0);
if (!MtrrLibSubstractable (Ranges, RangeCount, Type, BaseAddress + Length, Alignment)) {
break;
}
@@ -1644,7 +1645,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( }
while (SubtractiveLeft-- != 0) {
- Alignment = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
ASSERT (Alignment <= Length);
MtrrLibAddVariableMtrr (Ranges, RangeCount, VariableMtrr, VariableMtrrCapacity, VariableMtrrCount,
@@ -1654,7 +1655,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( }
while (Length != 0) {
- Alignment = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
if (Alignment > Length) {
break;
}
@@ -1665,7 +1666,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( }
while (SubtractiveRight-- != 0) {
- Alignment = MtrrLibLeastAlignment (BaseAddress + Length, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress + Length, Alignment0);
MtrrLibAddVariableMtrr (Ranges, RangeCount, VariableMtrr, VariableMtrrCapacity, VariableMtrrCount,
BaseAddress + Length, Alignment, CacheInvalid, Alignment0);
Length += Alignment;
@@ -1674,7 +1675,7 @@ MtrrLibSetMemoryAttributeInVariableMtrr ( UseLeastAlignment = TRUE;
while (Length != 0) {
if (UseLeastAlignment) {
- Alignment = MtrrLibLeastAlignment (BaseAddress, Alignment0);
+ Alignment = MtrrLibBiggestAlignment (BaseAddress, Alignment0);
if (Alignment > Length) {
UseLeastAlignment = FALSE;
}
|