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.

204 lines
7.0 KiB

  1. #ifndef _PREFETCH_HPP_
  2. #define _PREFETCH_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include "Global.hpp"
  24. #include "Assembly.hpp"
  25. /********************************************************************/
  26. /* */
  27. /* Prefetch a cache line. */
  28. /* */
  29. /* Support of data prefetch on the Pentium III or better. */
  30. /* */
  31. /********************************************************************/
  32. class PREFETCH : public ASSEMBLY
  33. {
  34. #ifdef ASSEMBLY_X86
  35. //
  36. // Staic private data.
  37. //
  38. STATIC BOOLEAN Active;
  39. #endif
  40. public:
  41. //
  42. // Public inline functions.
  43. //
  44. PREFETCH( VOID )
  45. { /* void */ }
  46. STATIC INLINE VOID L1( CHAR *Address,SBIT32 Size );
  47. STATIC INLINE VOID L2( CHAR *Address,SBIT32 Size );
  48. STATIC INLINE VOID L3( CHAR *Address,SBIT32 Size );
  49. STATIC INLINE VOID Nta( CHAR *Address,SBIT32 Size );
  50. ~PREFETCH( VOID )
  51. { /* void */ }
  52. private:
  53. //
  54. // Disabled operations.
  55. //
  56. PREFETCH( CONST PREFETCH & Copy );
  57. VOID operator=( CONST PREFETCH & Copy );
  58. };
  59. /********************************************************************/
  60. /* */
  61. /* Prefetch to the L1. */
  62. /* */
  63. /* Prefetch an area of memory to the L1 cache if the processor */
  64. /* supports this feature. */
  65. /* */
  66. /********************************************************************/
  67. VOID PREFETCH::L1( CHAR *Address,SBIT32 Size )
  68. {
  69. #ifdef ASSEMBLY_X86
  70. //
  71. // We ensure the processor has prefetch functionality
  72. // otherwise the instruction will fail.
  73. //
  74. if ( Active )
  75. {
  76. //
  77. // We execute a prefetch for each cache line
  78. // (which assumes things are alignment).
  79. //
  80. for
  81. (
  82. /* void */;
  83. Size > 0;
  84. Address += CacheLineSize, Size -= CacheLineSize
  85. )
  86. { PrefetchL1( Address ); }
  87. }
  88. #endif
  89. }
  90. /********************************************************************/
  91. /* */
  92. /* Prefetch to the L2. */
  93. /* */
  94. /* Prefetch an area of memory to the L2 cache if the processor */
  95. /* supports this feature. */
  96. /* */
  97. /********************************************************************/
  98. VOID PREFETCH::L2( CHAR *Address,SBIT32 Size )
  99. {
  100. #ifdef ASSEMBLY_X86
  101. //
  102. // We ensure the processor has prefetch functionality
  103. // otherwise the instruction will fail.
  104. //
  105. if ( Active )
  106. {
  107. //
  108. // We execute a prefetch for each cache line
  109. // (which assumes things are alignment).
  110. //
  111. for
  112. (
  113. /* void */;
  114. Size > 0;
  115. Address += CacheLineSize, Size -= CacheLineSize
  116. )
  117. { PrefetchL2( Address ); }
  118. }
  119. #endif
  120. }
  121. /********************************************************************/
  122. /* */
  123. /* Prefetch to the L3. */
  124. /* */
  125. /* Prefetch an area of memory to the L3 cache if the processor */
  126. /* supports this feature. */
  127. /* */
  128. /********************************************************************/
  129. VOID PREFETCH::L3( CHAR *Address,SBIT32 Size )
  130. {
  131. #ifdef ASSEMBLY_X86
  132. //
  133. // We ensure the processor has prefetch functionality
  134. // otherwise the instruction will fail.
  135. //
  136. if ( Active )
  137. {
  138. //
  139. // We execute a prefetch for each cache line
  140. // (which assumes things are alignment).
  141. //
  142. for
  143. (
  144. /* void */;
  145. Size > 0;
  146. Address += CacheLineSize, Size -= CacheLineSize
  147. )
  148. { PrefetchL3( Address ); }
  149. }
  150. #endif
  151. }
  152. /********************************************************************/
  153. /* */
  154. /* Prefetch to the L1. */
  155. /* */
  156. /* Prefetch an area of memory to the L1 cache if the processor */
  157. /* supports this feature. */
  158. /* */
  159. /********************************************************************/
  160. VOID PREFETCH::Nta( CHAR *Address,SBIT32 Size )
  161. {
  162. #ifdef ASSEMBLY_X86
  163. //
  164. // We ensure the processor has prefetch functionality
  165. // otherwise the instruction will fail.
  166. //
  167. if ( Active )
  168. {
  169. //
  170. // We execute a prefetch for each cache line
  171. // (which assumes things are alignment).
  172. //
  173. for
  174. (
  175. /* void */;
  176. Size > 0;
  177. Address += CacheLineSize, Size -= CacheLineSize
  178. )
  179. { PrefetchNta( Address ); }
  180. }
  181. #endif
  182. }
  183. #endif