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