From: Jeff Fan Date: Wed, 20 Apr 2016 08:58:24 +0000 (+0800) Subject: UefiCpuPkg/MtrrLib: Remove the loop of calculating byte offset in MSR X-Git-Tag: edk2-stable201903~7225 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=aaa1e579a5109a868863c8a3c7a51580f83b4c38 UefiCpuPkg/MtrrLib: Remove the loop of calculating byte offset in MSR Calculate byte offset in MSR directly and removing the loop. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Feng Tian --- diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 609aca5c3e..06a361bd84 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -486,18 +486,10 @@ ProgramFixedMtrr ( // // We found the fixed MTRR to be programmed // - for (ByteShift = 0; ByteShift < 8; ByteShift++) { - if (*Base == - ( - mMtrrLibFixedMtrrTable[MsrNum].BaseAddress + - (ByteShift * mMtrrLibFixedMtrrTable[MsrNum].Length) - ) - ) { - break; - } - } + ByteShift = ((UINT32)*Base - mMtrrLibFixedMtrrTable[MsrNum].BaseAddress) + / mMtrrLibFixedMtrrTable[MsrNum].Length; - if (ByteShift == 8) { + if (ByteShift >= 8) { return RETURN_UNSUPPORTED; }