[RTL] Fix amd64 version of DebugService2
[reactos.git] / sdk / lib / rtl / amd64 / rtlmem.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Run-Time Library
4 * PURPOSE: Memory functions for amd64
5 * FILE: lib/rtl/amd64/rtlmem.S
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <asm.inc>
12
13 /* FUNCTIONS *****************************************************************/
14
15 .code64
16
17 /* SIZE_T
18 * RtlCompareMemory(
19 * IN CONST VOID *Source1, <rcx>
20 * IN CONST VOID *Source2, <rdx>
21 * IN SIZE_T Length <r8>
22 * );
23 */
24 .proc RtlCompareMemory
25
26 /* Save registers */
27 push rsi
28 .pushreg rsi
29 push rdi
30 .pushreg rdi
31 .ENDPROLOG
32
33 /* Setup registers for compare */
34 mov rsi, rcx
35 mov rdi, rdx
36
37 /* Clear direction flag */
38 cli
39
40 /* Get number of qwords */
41 mov rcx, r8
42 shr rcx, 3
43 jz RtlCompareMemory2
44
45 /* Compare qwords */
46 repe cmpsq
47 jnz RtlCompareMemory4
48
49 RtlCompareMemory2:
50 /* Compare rest */
51 mov rcx, r8
52 and rcx, 7
53 jz RtlCompareMemory3
54
55 repe cmpsb
56 jnz RtlCompareMemory5
57
58 RtlCompareMemory3:
59 /* All equal */
60 /* Return the full count */
61 mov rax, rcx
62 jmp RtlCompareMemory6
63
64 RtlCompareMemory4:
65 /* Not equal after comparing qwords */
66 /* Compare the last qword */
67 sub rsi, 8
68 sub rdi, 8
69 mov rcx, 8
70 repe cmpsb
71
72 RtlCompareMemory5:
73 /* Not equal after comparing bytes */
74 /* Return difference */
75 sub rdi, rdx
76 dec rdi
77 mov rax, rdi
78
79 RtlCompareMemory6:
80 /* Cleanup and return */
81 pop rdi
82 pop rsi
83 ret
84 .endp
85
86 END
87