]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm
372c36520381d00f9b176a5e66fbec5aced90f94
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / X64 / 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 .code
25
26 InternalMemCopyMem PROC USES rsi rdi
27 mov rsi, rdx ; rsi <- Source
28 mov rdi, rcx ; rdi <- Destination
29 lea r9, [rdi + r8 - 1] ; r9 <- End of Destination
30 cmp rsi, rdi
31 mov rax, rdi ; rax <- Destination as return value
32 jae @F
33 cmp r9, rsi
34 jae @CopyBackward ; Copy backward if overlapped
35 @@:
36 xor rcx, rcx
37 sub rcx, rsi
38 and rcx, 7 ; rcx + rsi aligns on 8-byte boundary
39 jz @F
40 cmp rcx, r8
41 cmova rcx, r8
42 sub r8, rcx ; r8 <- remaining bytes to copy
43 rep movsb
44 @@:
45 mov rcx, r8
46 and r8, 7
47 shr rcx, 3 ; rcx <- # of Qwords to copy
48 jz @CopyBytes
49 @@:
50 DB 48h, 0fh, 6fh, 06h ; movq mm0, [rsi]
51 DB 48h, 0fh, 0e7h, 07h ; movntq [rdi], mm0
52 add rsi, 8
53 add rdi, 8
54 loop @B
55 mfence
56 jmp @CopyBytes
57 @CopyBackward:
58 mov rdi, r9 ; rdi <- End of Destination
59 lea rsi, [rsi + r8 - 1] ; rsi <- End of Source
60 std ; set direction flag
61 @CopyBytes:
62 mov rcx, r8
63 rep movsb ; Copy bytes backward
64 cld
65 ret
66 InternalMemCopyMem ENDP
67
68 END