https://git.reactos.org/?p=reactos.git;a=commitdiff;h=42bec35f65813fa9fc287…
commit 42bec35f65813fa9fc287edd80314ec64f9fe41f
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Fri Jun 25 10:24:04 2021 +0200
Commit: Jérôme Gardou <zefklop(a)users.noreply.github.com>
CommitDate: Wed Aug 4 17:48:39 2021 +0200
[NTOS:KE] Also rewrite KeZeroPages in assembly for amd64
Let's stick with "rep movsq" until we are able to have more precise
benchmarks
---
ntoskrnl/ke/amd64/stubs.c | 10 ----------
ntoskrnl/ke/amd64/zeropage.S | 45 ++++++++++++++++++++++++++++++++++++++++++++
ntoskrnl/ntos.cmake | 3 ++-
3 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/ntoskrnl/ke/amd64/stubs.c b/ntoskrnl/ke/amd64/stubs.c
index 0683ce73aa4..7aa5866b978 100644
--- a/ntoskrnl/ke/amd64/stubs.c
+++ b/ntoskrnl/ke/amd64/stubs.c
@@ -88,16 +88,6 @@ KiDpcInterruptHandler(VOID)
KeLowerIrql(OldIrql);
}
-
-VOID
-FASTCALL
-KeZeroPages(IN PVOID Address,
- IN ULONG Size)
-{
- /* Not using XMMI in this routine */
- RtlZeroMemory(Address, Size);
-}
-
PVOID
KiSwitchKernelStackHelper(
LONG_PTR StackOffset,
diff --git a/ntoskrnl/ke/amd64/zeropage.S b/ntoskrnl/ke/amd64/zeropage.S
new file mode 100644
index 00000000000..c663efe04b5
--- /dev/null
+++ b/ntoskrnl/ke/amd64/zeropage.S
@@ -0,0 +1,45 @@
+/*
+ * PROJECT: ReactOS Kernel
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Fast zeroing of pages
+ * COPYRIGHT: Copyright 2021 Jérôme Gardou <jerome.gardou(a)reactos.org>
+ */
+
+#include <asm.inc>
+
+/* FUNCTIONS ****************************************************************/
+.code
+
+/* Benchmarking from Timo on some AMD machine:
+ rep movsq : 128
+ movaps 175
+ movnti 620
+ movntdq: 620
+ movntps: 620
+ MS KeZeroPages (movnti unrolled): 883
+ MS KeZeroSinglePage (mov): 346
+
+ whole discussion in
https://github.com/reactos/reactos/pull/3765
+ We stick with rep stosq.
+*/
+
+/*
+ * VOID
+ * KeZeroPages(PVOID Ptr, ULONG Size);
+ */
+PUBLIC KeZeroPages
+FUNC KeZeroPages
+ push rdi
+ .PUSHREG rdi
+ .ENDPROLOG
+
+ mov rdi, rcx
+ mov ecx, edx
+ shr ecx, 3
+ xor rax, rax
+ rep stosq
+ pop rdi
+ ret
+ENDFUNC
+
+END
diff --git a/ntoskrnl/ntos.cmake b/ntoskrnl/ntos.cmake
index 7803e4c812e..50e965f610a 100644
--- a/ntoskrnl/ntos.cmake
+++ b/ntoskrnl/ntos.cmake
@@ -328,7 +328,8 @@ elseif(ARCH STREQUAL "amd64")
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/boot.S
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/ctxswitch.S
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/trap.S
- ${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/usercall_asm.S)
+ ${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/usercall_asm.S
+ ${REACTOS_SOURCE_DIR}/ntoskrnl/ke/amd64/zeropage.S)
list(APPEND SOURCE
${REACTOS_SOURCE_DIR}/ntoskrnl/config/i386/cmhardwr.c
${REACTOS_SOURCE_DIR}/ntoskrnl/mm/i386/page.c