Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.7 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*
  15. * ctiming.h
  16. *
  17. * DESCRIPTION:
  18. * Common timing functions.
  19. *
  20. * I extracted this code from meantime.h in HQV's decode directory.
  21. */
  22. // $Header: S:\h26x\src\common\ctiming.h_v 1.2 26 Dec 1995 17:43:06 DBRUCKS $
  23. // $Log: S:\h26x\src\common\ctiming.h_v $
  24. ;//
  25. ;// Rev 1.2 26 Dec 1995 17:43:06 DBRUCKS
  26. ;// changed bTimerIsOn to bTimerIsActive
  27. ;//
  28. ;// Rev 1.1 26 Dec 1995 12:40:54 DBRUCKS
  29. ;// added higher level macros to simplify use
  30. ;//
  31. ;// Rev 1.0 20 Dec 1995 15:06:14 DBRUCKS
  32. ;// Initial revision.
  33. #ifndef __CTIMING_H__
  34. #define __CTIMING_H__
  35. /* The following timing overhead numbers were generated by Tom Walsh
  36. * based on static variables for startlow, starthigh, and elapsed.
  37. *
  38. * When timing sections of code with low clock numbers be careful to
  39. * minimize the timing overhead. Store the sub totals to a stack variable
  40. * instead of to the instance via a pointer indirection and offset.
  41. */
  42. #define P5TIMING_OVERHEAD 13
  43. #define P6TIMING_OVERHEAD 33
  44. /* Low Level Macros
  45. */
  46. #define __RDTSC__ __asm { __asm __emit 0Fh __asm __emit 31h }
  47. #define STARTCLOCK(startlow,starthigh) { \
  48. __asm { \
  49. __asm __RDTSC__ \
  50. __asm mov startlow, eax \
  51. __asm mov starthigh, edx \
  52. } \
  53. }
  54. #define STOPCLOCKP5(startlow,starthigh,elapsed) { \
  55. __asm { \
  56. __asm __RDTSC__ \
  57. __asm sub eax, startlow \
  58. __asm sbb edx, starthigh \
  59. __asm sub eax, P5TIMING_OVERHEAD \
  60. __asm sbb edx, 0 \
  61. __asm mov elapsed,eax \
  62. } \
  63. }
  64. #define STOPCLOCKP6(startlow,starthigh,elapsed) { \
  65. __asm { \
  66. __asm __RDTSC__ \
  67. __asm sub eax, startlow \
  68. __asm sbb edx, starthigh \
  69. __asm sub eax, P6TIMING_OVERHEAD \
  70. __asm sbb edx, 0 \
  71. __asm mov elapsed,eax \
  72. } \
  73. }
  74. /* High Level Macros
  75. *
  76. * Call TIMER_START and TIMER_STOP in the main function that you wish to time.
  77. * TIMER_BEFORE and TIMER_AFTER should be used inside of that main function.
  78. * Fo example:
  79. *
  80. * TIMER_START
  81. * TIMER_BEFORE
  82. * TIMER_AFTER_P5
  83. * TIMER_BEFORE
  84. * TIMER_AFTER_P5
  85. * TIMER_STOP
  86. *
  87. * Variable Definitions
  88. * U32 uStartLow; // temporary set in TIMER_START
  89. * U32 uStartHigh; // temporary set in TIMER_START
  90. * U32 uElapsed; // temporary used in TIMER_AFTER_*
  91. * U32 uBefore; // temporary used in TIMER_BEFORE and TIMER_AFTER_*
  92. * U32 uResult; // result variable
  93. * int bTimerIsActive // boolean - true if timing this frame
  94. *
  95. * WARNING: TIMER_AFTER_P5 and TIMER_AFTER_P6 add to the result variable.
  96. */
  97. #define TIMER_START(bTimerIsActive,uStartLow,uStartHigh) \
  98. { \
  99. bTimerIsActive = 1; \
  100. STARTCLOCK(uStartLow,uStartHigh); \
  101. }
  102. #define TIMER_BEFORE(bTimerIsActive,uStartLow,uStartHigh,uBefore) \
  103. { \
  104. if (bTimerIsActive) \
  105. { \
  106. STOPCLOCKP5(uStartLow,uStartHigh,uBefore); \
  107. } \
  108. }
  109. #define TIMER_AFTER_P5(bTimerIsActive,uStartLow,uStartHigh,uBefore,uElapsed,uResult) \
  110. { \
  111. if (bTimerIsActive) \
  112. { \
  113. STOPCLOCKP5(uStartLow,uStartHigh,uElapsed); \
  114. uResult += uElapsed - uBefore; \
  115. } \
  116. }
  117. #define TIMER_STOP(bTimerIsActive,uStartLow,uStartHigh,uResult) \
  118. { \
  119. if (bTimerIsActive) \
  120. { \
  121. STOPCLOCKP5(uStartLow,uStartHigh,uResult); \
  122. } \
  123. }
  124. #endif /* __CTIMING_H__ */