]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/Ia32/CopyMem.S
Import some basic libraries instances for Mde Packages.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / Ia32 / CopyMem.S
1 //
2 // Include common header file for this module.
3 //
4 #include "CommonHeader.h"
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 .globl _InternalMemCopyMem
30
31 #------------------------------------------------------------------------------
32 # VOID *
33 # EFIAPI
34 # InternalMemCopyMem (
35 # IN VOID *Destination,
36 # IN VOID *Source,
37 # IN UINTN Count
38 # );
39 #------------------------------------------------------------------------------
40 _InternalMemCopyMem:
41 push %esi
42 push %edi
43 movl 16(%esp), %esi # esi <- Source
44 movl 12(%esp), %edi # edi <- Destination
45 movl 20(%esp), %edx # edx <- Count
46 leal -1(%esi,%edx,), %eax # eax <- End of Source
47 cmpl %edi, %esi
48 jae L0
49 cmpl %edi, %eax # Overlapped?
50 jae L_CopyBackward # Copy backward if overlapped
51 L0:
52 xorl %ecx, %ecx
53 subl %edi, %ecx
54 andl $15, %ecx # ecx + edi aligns on 16-byte boundary
55 jz L1
56 cmpl %edx, %ecx
57 cmova %edx, %ecx
58 subl %ecx, %edx # edx <- remaining bytes to copy
59 rep
60 movsb
61 L1:
62 movl %edx, %ecx
63 andl $15, %edx
64 shrl $4, %ecx # ecx <- # of DQwords to copy
65 jz L_CopyBytes
66 addl $-16, %esp
67 movdqu %xmm0, (%esp)
68 L2:
69 movdqu (%esi), %xmm0
70 movntdq %xmm0, (%edi)
71 addl $16, %esi
72 addl $16, %edi
73 loop L2
74 mfence
75 movdqu (%esp),%xmm0
76 addl $16, %esp # stack cleanup
77 jmp L_CopyBytes
78 L_CopyBackward:
79 movl %eax, %esi # esi <- Last byte in Source
80 leal -1(%edi,%edx,), %edi # edi <- Last byte in Destination
81 std
82 L_CopyBytes:
83 movl %edx, %ecx
84 rep
85 movsb
86 cld
87 movl 12(%esp), %eax # eax <- Destination as return value
88 pop %edi
89 pop %esi
90 ret