]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibOptDxe/Ia32/CopyMem.nasm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / Ia32 / CopyMem.nasm
CommitLineData
1b7c54f8
JJ
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
9344f092 4; SPDX-License-Identifier: BSD-2-Clause-Patent\r
1b7c54f8
JJ
5;\r
6; Module Name:\r
7;\r
8; CopyMem.nasm\r
9;\r
10; Abstract:\r
11;\r
12; CopyMem function\r
13;\r
14; Notes:\r
15;\r
16;------------------------------------------------------------------------------\r
17\r
18 SECTION .text\r
19\r
20;------------------------------------------------------------------------------\r
21; VOID *\r
22; InternalMemCopyMem (\r
23; IN VOID *Destination,\r
24; IN VOID *Source,\r
25; IN UINTN Count\r
26; );\r
27;------------------------------------------------------------------------------\r
28global ASM_PFX(InternalMemCopyMem)\r
29ASM_PFX(InternalMemCopyMem):\r
30 push esi\r
31 push edi\r
32 mov esi, [esp + 16] ; esi <- Source\r
33 mov edi, [esp + 12] ; edi <- Destination\r
34 mov edx, [esp + 20] ; edx <- Count\r
35 lea eax, [esi + edx - 1] ; eax <- End of Source\r
36 cmp esi, edi\r
37 jae .0\r
38 cmp eax, edi ; Overlapped?\r
39 jae @CopyBackward ; Copy backward if overlapped\r
40.0:\r
41 xor ecx, ecx\r
42 sub ecx, edi\r
43 and ecx, 15 ; ecx + edi aligns on 16-byte boundary\r
44 jz .1\r
45 cmp ecx, edx\r
46 cmova ecx, edx\r
47 sub edx, ecx ; edx <- remaining bytes to copy\r
48 rep movsb\r
49.1:\r
50 mov ecx, edx\r
51 and edx, 15\r
52 shr ecx, 4 ; ecx <- # of DQwords to copy\r
53 jz @CopyBytes\r
54 add esp, -16\r
55 movdqu [esp], xmm0 ; save xmm0\r
56.2:\r
57 movdqu xmm0, [esi] ; esi may not be 16-bytes aligned\r
58 movntdq [edi], xmm0 ; edi should be 16-bytes aligned\r
59 add esi, 16\r
60 add edi, 16\r
61 loop .2\r
62 mfence\r
63 movdqu xmm0, [esp] ; restore xmm0\r
64 add esp, 16 ; stack cleanup\r
65 jmp @CopyBytes\r
66@CopyBackward:\r
67 mov esi, eax ; esi <- Last byte in Source\r
68 lea edi, [edi + edx - 1] ; edi <- Last byte in Destination\r
69 std\r
70@CopyBytes:\r
71 mov ecx, edx\r
72 rep movsb\r
73 cld\r
74 mov eax, [esp + 12] ; eax <- Destination as return value\r
75 pop edi\r
76 pop esi\r
77 ret\r
78\r