xref: /reactos/sdk/lib/crt/mem/i386/memmove_asm.s (revision cdf90707)
1/*
2 * void *memcpy (void *to, const void *from, size_t count)
3 *
4 */
5
6#include <asm.inc>
7#include <ks386.inc>
8
9PUBLIC _memcpy
10PUBLIC _memmove
11.code
12
13_memcpy:
14FUNC _memmove
15	FPO 0, 3, 5, 2, 1, FRAME_NONFPO
16	push ebp
17	CFI_ADJUST_CFA_OFFSET 4
18	CFI_REL_OFFSET ebp, 0
19	mov ebp, esp
20	CFI_DEF_CFA_REGISTER ebp
21
22	push esi
23	CFI_REL_OFFSET esi, -4
24	push edi
25	CFI_REL_OFFSET edi, -8
26
27	mov	edi, [ebp + 8]
28	mov	esi, [ebp + 12]
29	mov	ecx, [ebp + 16]
30
31	cmp	edi, esi
32	jbe	.CopyUp
33	mov	eax, ecx
34	add	eax, esi
35	cmp	edi, eax
36	jb .CopyDown
37
38.CopyUp:
39	cld
40
41	cmp	ecx, 16
42	jb .L1
43	mov edx, ecx
44	test edi, 3
45	je .L2
46/*
47 * Make the destination dword aligned
48 */
49	mov ecx, edi
50	and ecx, 3
51	sub ecx, 5
52	not ecx
53	sub edx, ecx
54	rep movsb
55	mov ecx, edx
56.L2:
57	shr ecx, 2
58	rep movsd
59	mov ecx, edx
60	and ecx, 3
61.L1:
62	test ecx, ecx
63	je .L3
64	rep movsb
65.L3:
66	mov eax, [ebp + 8]
67	pop edi
68	CFI_SAME_VALUE edi
69	pop esi
70	CFI_SAME_VALUE esi
71	leave
72	CFI_ADJUST_CFA_OFFSET -4
73	CFI_SAME_VALUE ebp
74	CFI_DEF_CFA_REGISTER esp
75	ret
76
77.CopyDown:
78	std
79
80	add edi, ecx
81	add esi, ecx
82
83	cmp ecx, 16
84	jb .L4
85	mov edx, ecx
86	test edi, 3
87	je .L5
88
89/*
90 * Make the destination dword aligned
91 */
92	mov ecx, edi
93	and ecx, 3
94	sub edx, ecx
95	dec esi
96	dec edi
97	rep movsb
98	mov ecx, edx
99
100	sub esi, 3
101	sub edi, 3
102.L6:
103	shr ecx, 2
104	rep movsd
105	mov ecx, edx
106	and ecx, 3
107	je .L7
108	add esi, 3
109	add edi, 3
110.L8:
111	rep movsb
112.L7:
113	cld
114	mov eax, [ebp + 8]
115	pop edi
116	CFI_SAME_VALUE edi
117	pop esi
118	CFI_SAME_VALUE esi
119	leave
120	CFI_ADJUST_CFA_OFFSET -4
121	CFI_SAME_VALUE ebp
122	CFI_DEF_CFA_REGISTER esp
123	ret
124.L5:
125	sub edi, 4
126	sub esi, 4
127	jmp .L6
128
129.L4:
130	test ecx, ecx
131	je .L7
132	dec esi
133	dec edi
134	jmp .L8
135ENDFUNC
136
137END
138