]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/Ia32/CopyMem.asm
Removed CommonHeader.h generated file from the MdePkg.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / Ia32 / CopyMem.asm
1 //
2 // Include common header file for this module.
3 //
4
5
6 ;------------------------------------------------------------------------------
7 ;
8 ; Copyright (c) 2006, Intel Corporation
9 ; All rights reserved. This program and the accompanying materials
10 ; are licensed and made available under the terms and conditions of the BSD License
11 ; which accompanies this distribution. The full text of the license may be found at
12 ; http://opensource.org/licenses/bsd-license.php
13 ;
14 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 ;
17 ; Module Name:
18 ;
19 ; CopyMem.asm
20 ;
21 ; Abstract:
22 ;
23 ; CopyMem function
24 ;
25 ; Notes:
26 ;
27 ;------------------------------------------------------------------------------
28
29 .686
30 .model flat,C
31 .xmm
32 .code
33
34 ;------------------------------------------------------------------------------
35 ; VOID *
36 ; InternalMemCopyMem (
37 ; IN VOID *Destination,
38 ; IN VOID *Source,
39 ; IN UINTN Count
40 ; );
41 ;------------------------------------------------------------------------------
42 InternalMemCopyMem PROC USES esi edi
43 mov esi, [esp + 16] ; esi <- Source
44 mov edi, [esp + 12] ; edi <- Destination
45 mov edx, [esp + 20] ; edx <- Count
46 lea eax, [esi + edx - 1] ; eax <- End of Source
47 cmp esi, edi
48 jae @F
49 cmp eax, edi ; Overlapped?
50 jae @CopyBackward ; Copy backward if overlapped
51 @@:
52 xor ecx, ecx
53 sub ecx, edi
54 and ecx, 15 ; ecx + edi aligns on 16-byte boundary
55 jz @F
56 cmp ecx, edx
57 cmova ecx, edx
58 sub edx, ecx ; edx <- remaining bytes to copy
59 rep movsb
60 @@:
61 mov ecx, edx
62 and edx, 15
63 shr ecx, 4 ; ecx <- # of DQwords to copy
64 jz @CopyBytes
65 add esp, -16
66 movdqu [esp], xmm0 ; save xmm0
67 @@:
68 movdqu xmm0, [esi] ; esi may not be 16-bytes aligned
69 movntdq [edi], xmm0 ; edi should be 16-bytes aligned
70 add esi, 16
71 add edi, 16
72 loop @B
73 mfence
74 movdqu xmm0, [esp] ; restore xmm0
75 add esp, 16 ; stack cleanup
76 jmp @CopyBytes
77 @CopyBackward:
78 mov esi, eax ; esi <- Last byte in Source
79 lea edi, [edi + edx - 1] ; edi <- Last byte in Destination
80 std
81 @CopyBytes:
82 mov ecx, edx
83 rep movsb
84 cld
85 mov eax, [esp + 12] ; eax <- Destination as return value
86 ret
87 InternalMemCopyMem ENDP
88
89 END