- Implement RtlPrefectMemoryNonTemporal. Patch by Patrick Baggett <baggett.patrick...
authorAlex Ionescu <aionescu@gmail.com>
Tue, 29 Nov 2005 02:40:18 +0000 (02:40 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Tue, 29 Nov 2005 02:40:18 +0000 (02:40 +0000)
svn path=/trunk/; revision=19742

reactos/lib/rtl/i386/mem_asm.S
reactos/lib/rtl/mem.c
reactos/ntoskrnl/ke/i386/kernel.c

index 61a2912..5ad5a39 100644 (file)
@@ -1,11 +1,11 @@
 /* \r
  * COPYRIGHT:       See COPYING in the top level directory\r
  * PROJECT:         ReactOS kernel\r
- * FILE:  mem.asm\r
+ * FILE:            mem_asm.S\r
  * PURPOSE:         Memory functions\r
- * PROGRAMMER:      Magnus Olsen (magnusolsen@greatlord.com)\r
- * UPDATE HISTORY:\r
- *        Created 27/07/2005\r
+ * PROGRAMMERS:     Patrick Baggett (baggett.patrick@gmail.com)\r
+ *                  Alex Ionescu (alex@relsoft.net)\r
+ *                  Magnus Olsen (magnusolsen@greatlord.com)\r
  */\r
 \r
 .intel_syntax noprefix\r
@@ -17,6 +17,7 @@
 .globl  _RtlFillMemory@12         // [4]  (no bug)\r
 .globl  _RtlCompareMemoryUlong@12 // [5]  (no bug)  \r
 .globl  _RtlCompareMemory@12      // [4]  (no bug)\r
+.globl  @RtlPrefetchMemoryNonTemporal@8\r
 \r
 /* FUNCTIONS ***************************************************************/\r
 \r
@@ -145,3 +146,18 @@ _RtlCompareMemory@12:
      pop edi   \r
 3:       \r
      ret 12  // return count\r
+\r
+\r
+@RtlPrefetchMemoryNonTemporal@8:\r
+       ret         /* Overwritten by ntoskrnl/ke/i386/kernel.c if SSE is supported (see Ki386SetProcessorFeatures() ) */\r
+\r
+       mov eax, [_Ke386CacheGranularity]    // Get cache line size\r
+\r
+       // This is fastcall, so ecx = address, edx = size\r
+       fetch_next_line:\r
+       prefetchnta byte ptr [ecx]  // prefechnta(address)\r
+       sub edx, eax                // count = count - cache_line_size\r
+       add ecx, eax                // address = address + cache_line_size\r
+       cmp edx, 0                  // if(count) <= 0\r
+       ja fetch_next_line          //     goto fetch_next_line\r
+       ret\r
index 85ceba3..52c54e1 100644 (file)
@@ -140,7 +140,7 @@ RtlMoveMemory (
 }
 
 /*
-* @unimplemented
+* @implemented
 */
 VOID
 FASTCALL
@@ -149,7 +149,9 @@ RtlPrefetchMemoryNonTemporal(
        IN SIZE_T Length
        )
 {
-       UNIMPLEMENTED;
+       /* By nature of prefetch, this is non-portable. */
+       (void)Source;
+       (void)Length;
 }
 
 
index cf65530..8f40320 100644 (file)
@@ -22,6 +22,7 @@ static ULONG Ke386CpuidFlags2, Ke386CpuidExFlags, Ke386CpuidExMisc;
 ULONG Ke386CacheAlignment;
 CHAR Ke386CpuidModel[49] = {0,};
 ULONG Ke386L1CacheSize;
+ULONG Ke386CacheGranularity = 0x40;      /* FIXME: Default to 64 bytes for RtlPrefetchMemoryNonTemporal(), need real size */
 BOOLEAN Ke386NoExecute = FALSE;
 BOOLEAN Ke386Pae = FALSE;
 BOOLEAN Ke386GlobalPagesEnabled = FALSE;
@@ -476,6 +477,7 @@ KeInit2(VOID)
    DPRINT("Ke386CacheAlignment: %d\n", Ke386CacheAlignment);
    if (Ke386L1CacheSize)
    {
+
       DPRINT("Ke386L1CacheSize: %dkB\n", Ke386L1CacheSize);
    }
    if (Pcr->L2CacheSize)
@@ -497,7 +499,7 @@ Ki386SetProcessorFeatures(VOID)
    KEY_VALUE_PARTIAL_INFORMATION ValueData;
    NTSTATUS Status;
    ULONG FastSystemCallDisable = 0;
-
+   
    SharedUserData->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = FALSE;
    SharedUserData->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
    SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] =
@@ -516,6 +518,13 @@ Ki386SetProcessorFeatures(VOID)
    SharedUserData->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] =
       (Pcr->PrcbData.FeatureBits & X86_FEATURE_SSE2);
 
+   /* Does the CPU Support 'prefetchnta' (SSE)  */
+   if(Pcr->PrcbData.FeatureBits & X86_FEATURE_SSE)
+   {
+       /* Replace the ret by a nop */
+       *(PCHAR)RtlPrefetchMemoryNonTemporal = 0x90;
+   }
+
    /* Does the CPU Support Fast System Call? */
    if (Pcr->PrcbData.FeatureBits & X86_FEATURE_SYSCALL) {