From 9d0f3dd35d86fba542d38467ff679fd961e0f6f0 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Thu, 10 Oct 2024 15:40:12 -0700 Subject: [PATCH] ArmPkg: ArmArchTimerLib: Update operations to be 64 bit wide The existing operation in ArmArchTimerLib is operating on UINT32 or UINT64 based on the target system. This casting game originates from the fact that timer frequency is UINTN type. This change will simply promote all operations to UINT64 based, which will remove the casting and conditional #if in the code for better portability and readability. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Signed-off-by: Kun Qin --- .../Library/ArmArchTimerLib/ArmArchTimerLib.c | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c index cc1be0125b..8fb183a35d 100644 --- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c +++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c @@ -17,13 +17,6 @@ #define TICKS_PER_MICRO_SEC (ArmGenericTimerGetTimerFreq ()/1000000U) -// Select appropriate multiply function for platform architecture. -#ifdef MDE_CPU_ARM -#define MULT_U64_X_N MultU64x32 -#else -#define MULT_U64_X_N MultU64x64 -#endif - /** A local utility function that returns the PCD value, if specified. Otherwise it defaults to ArmGenericTimerGetTimerFreq. @@ -69,7 +62,7 @@ MicroSecondDelay ( // = MicroSeconds x TICKS_PER_MICRO_SEC // = MicroSeconds x Frequency.10^-6 TimerTicks64 = DivU64x32 ( - MULT_U64_X_N ( + MultU64x64 ( MicroSeconds, GetPlatformTimerFreq () ), @@ -205,8 +198,8 @@ GetTimeInNanoSecond ( ) { UINT64 NanoSeconds; - UINT32 Remainder; - UINT32 TimerFreq; + UINT64 Remainder; + UINT64 TimerFreq; TimerFreq = GetPlatformTimerFreq (); // @@ -214,8 +207,8 @@ GetTimeInNanoSecond ( // Time = --------- x 1,000,000,000 // Frequency // - NanoSeconds = MULT_U64_X_N ( - DivU64x32Remainder ( + NanoSeconds = MultU64x64 ( + DivU64x64Remainder ( Ticks, TimerFreq, &Remainder @@ -227,12 +220,13 @@ GetTimeInNanoSecond ( // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000) // will not overflow 64-bit. // - NanoSeconds += DivU64x32 ( - MULT_U64_X_N ( - (UINT64)Remainder, + NanoSeconds += DivU64x64Remainder ( + MultU64x64 ( + Remainder, 1000000000U ), - TimerFreq + TimerFreq, + NULL ); return NanoSeconds;