]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/X64/CopyMem.S
Update copyright for files modified in this year
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / X64 / CopyMem.S
1 #
2 # ConvertAsm.py: Automatically generated from CopyMem.asm
3 #
4 #------------------------------------------------------------------------------
5 #
6 # Copyright (c) 2006 - 2008, Intel Corporation
7 # All rights reserved. This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
11 #
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #
15 # Module Name:
16 #
17 # CopyMem.S
18 #
19 # Abstract:
20 #
21 # CopyMem function
22 #
23 # Notes:
24 #
25 #------------------------------------------------------------------------------
26
27 #------------------------------------------------------------------------------
28 # VOID *
29 # EFIAPI
30 # InternalMemCopyMem (
31 # IN VOID *Destination,
32 # IN VOID *Source,
33 # IN UINTN Count
34 # )
35 #------------------------------------------------------------------------------
36 .intel_syntax noprefix
37 .globl ASM_PFX(InternalMemCopyMem)
38 ASM_PFX(InternalMemCopyMem):
39 push rsi
40 push rdi
41 mov rsi, rdx # rsi <- Source
42 mov rdi, rcx # rdi <- Destination
43 lea r9, [rsi + r8 - 1] # r9 <- Last byte of Source
44 cmp rsi, rdi
45 mov rax, rdi # rax <- Destination as return value
46 jae L0 # Copy forward if Source > Destination
47 cmp r9, rdi # Overlapped?
48 jae @CopyBackward # Copy backward if overlapped
49 L0:
50 xor rcx, rcx
51 sub rcx, rdi # rcx <- -rdi
52 and rcx, 15 # rcx + rsi should be 16 bytes aligned
53 jz L1 # skip if rcx == 0
54 cmp rcx, r8
55 cmova rcx, r8
56 sub r8, rcx
57 rep movsb
58 L1:
59 mov rcx, r8
60 and r8, 15
61 shr rcx, 4 # rcx <- # of DQwords to copy
62 jz L_CopyBytes
63 movdqa [rsp + 0x18], xmm0 # save xmm0 on stack
64 L2:
65 movdqu xmm0, [rsi] # rsi may not be 16-byte aligned
66 movntdq [rdi], xmm0 # rdi should be 16-byte aligned
67 add rsi, 16
68 add rdi, 16
69 loop L2
70 mfence
71 movdqa xmm0, [rsp + 0x18] # restore xmm0
72 jmp L_CopyBytes # copy remaining bytes
73 L_CopyBackward:
74 mov rsi, r9 # rsi <- Last byte of Source
75 lea rdi, [rdi + r8 - 1] # rdi <- Last byte of Destination
76 std
77 L_CopyBytes:
78 mov rcx, r8
79 rep movsb
80 cld
81 pop rdi
82 pop rsi
83 ret