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