From aaa1e579a5109a868863c8a3c7a51580f83b4c38 Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Wed, 20 Apr 2016 16:58:24 +0800 Subject: [PATCH] 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 --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) 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; }