/* This function will ASSERT if the APIC timer intial count returned from GetApicTimerInitCount() is zero. */
VOID EFIAPI InternalX86Delay(IN UINT32 Delay)
/* This function will ASSERT if the APIC timer intial count returned from GetApicTimerInitCount() is zero. */
VOID EFIAPI InternalX86Delay(IN UINT32 Delay)
{
  INT32   Ticks;
  UINT32  Times;
  UINT32  InitCount;
  UINT32  StartTick;
  InitCount = GetApicTimerInitCount ();
  ASSERT (InitCount != 0);
  Times = Delay / (InitCount / 2);
  Delay = Delay % (InitCount / 2);
  StartTick = GetApicTimerCurrentCount ();
  do {
    do {
      CpuPause ();
      Ticks = StartTick - GetApicTimerCurrentCount ();
      if (Ticks < 0) {
        Ticks += InitCount;
      }
    } while ((UINT32)Ticks < Delay);
    StartTick -= (StartTick > Delay) ?  Delay : (Delay - InitCount);
    Delay      = InitCount / 2;
  } while (Times-- > 0);
}