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 <quic_llindhol@quicinc.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Kun Qin <kun.qin@microsoft.com>
This commit is contained in:
parent
77d32b1796
commit
9d0f3dd35d
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue