]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.nasm
MdePkg BaseMemoryLibMmx: Convert Ia32/CopyMem.asm to NASM
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / Ia32 / CopyMem.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
8 ;
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 ;
12 ; Module Name:
13 ;
14 ; CopyMem.nasm
15 ;
16 ; Abstract:
17 ;
18 ; CopyMem function
19 ;
20 ; Notes:
21 ;
22 ;------------------------------------------------------------------------------
23
24 SECTION .text
25
26 ;------------------------------------------------------------------------------
27 ; VOID *
28 ; EFIAPI
29 ; InternalMemCopyMem (
30 ; IN VOID *Destination,
31 ; IN VOID *Source,
32 ; IN UINTN Count
33 ; );
34 ;------------------------------------------------------------------------------
35 global ASM_PFX(InternalMemCopyMem)
36 ASM_PFX(InternalMemCopyMem):
37 push esi
38 push edi
39 mov esi, [esp + 16] ; esi <- Source
40 mov edi, [esp + 12] ; edi <- Destination
41 mov edx, [esp + 20] ; edx <- Count
42 lea eax, [esi + edx - 1] ; eax <- End of Source
43 cmp esi, edi
44 jae .0
45 cmp eax, edi ; Overlapped?
46 jae @CopyBackward ; Copy backward if overlapped
47 .0:
48 mov ecx, edx
49 and edx, 7
50 shr ecx, 3 ; ecx <- # of Qwords to copy
51 jz @CopyBytes
52 push eax
53 push eax
54 movq [esp], mm0 ; save mm0
55 .1:
56 movq mm0, [esi]
57 movq [edi], mm0
58 add esi, 8
59 add edi, 8
60 loop .1
61 movq mm0, [esp] ; restore mm0
62 pop ecx ; stack cleanup
63 pop ecx ; stack cleanup
64 jmp @CopyBytes
65 @CopyBackward:
66 mov esi, eax ; esi <- Last byte in Source
67 lea edi, [edi + edx - 1] ; edi <- Last byte in Destination
68 std
69 @CopyBytes:
70 mov ecx, edx
71 rep movsb
72 cld
73 mov eax, [esp + 12]
74 pop edi
75 pop esi
76 ret
77