]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibMmx/ia32/CopyMem.asm
Initial import.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / ia32 / CopyMem.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006, Intel Corporation
4 ; All rights reserved. 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.asm
15 ;
16 ; Abstract:
17 ;
18 ; CopyMem function
19 ;
20 ; Notes:
21 ;
22 ;------------------------------------------------------------------------------
23
24 .686
25 .model flat,C
26 .xmm
27 .code
28
29 ;------------------------------------------------------------------------------
30 ; VOID *
31 ; _mem_CopyMem (
32 ; IN VOID *Destination,
33 ; IN VOID *Source,
34 ; IN UINTN Count
35 ; )
36 ;------------------------------------------------------------------------------
37 InternalMemCopyMem PROC USES esi edi
38 mov esi, [esp + 16] ; esi <- Source
39 mov edi, [esp + 12] ; edi <- Destination
40 mov edx, [esp + 20] ; edx <- Count
41 lea eax, [edi + edx - 1] ; eax <- End of Destination
42 cmp esi, edi
43 jae @F
44 cmp eax, esi ; Overlapped?
45 jae @CopyBackward ; Copy backward if overlapped
46 @@:
47 xor ecx, ecx
48 sub ecx, esi
49 and ecx, 7 ; ecx + esi aligns on 8-byte boundary
50 jz @F
51 cmp ecx, edx
52 cmova ecx, edx
53 sub edx, ecx ; edx <- remaining bytes to copy
54 rep movsb
55 @@:
56 mov ecx, edx
57 and edx, 7
58 shr ecx, 3 ; ecx <- # of Qwords to copy
59 jz @CopyBytes
60 push eax
61 push eax
62 movq [esp], mm0 ; save mm0
63 @@:
64 movq mm0, [esi]
65 movntq [edi], mm0
66 add esi, 8
67 add edi, 8
68 loop @B
69 mfence
70 movq mm0, [esp] ; restore mm0
71 pop ecx ; stack cleanup
72 pop ecx ; stack cleanup
73 jmp @CopyBytes
74 @CopyBackward:
75 mov edi, eax ; edi <- Last byte in Destination
76 lea esi, [esi + edx - 1] ; esi <- Last byte in Source
77 std
78 @CopyBytes:
79 mov ecx, edx
80 rep movsb
81 cld
82 mov eax, [esp + 12]
83 ret
84 InternalMemCopyMem ENDP
85
86 END