]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/X64/EfiCopyMemSSE2.asm
Fixed issues compiling for Apple gcc on IA-32
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / X64 / EfiCopyMemSSE2.asm
CommitLineData
3eb9473e 1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2007, 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; EfiCommonLibCopyMem (\r
29; OUT VOID *Destination,\r
30; IN VOID *Source,\r
31; IN UINTN Count\r
32; );\r
33;------------------------------------------------------------------------------\r
34EfiCommonLibCopyMem PROC USES rsi rdi\r
35 cmp rdx, rcx ; if Source == Destination, do nothing\r
36 je @CopyMemDone\r
37 cmp r8, 0 ; if Count == 0, do nothing\r
38 je @CopyMemDone\r
39 mov rsi, rdx ; rsi <- Source\r
40 mov rdi, rcx ; rdi <- Destination\r
41 lea r9, [rsi + r8 - 1] ; r9 <- End of Source\r
42 cmp rsi, rdi\r
43 mov rax, rdi ; rax <- Destination as return value\r
44 jae @F ; Copy forward if Source > Destination\r
45 cmp r9, rdi ; Overlapped?\r
46 jae @CopyBackward ; Copy backward if overlapped\r
47@@:\r
48 xor rcx, rcx\r
49 sub rcx, rdi ; rcx <- -rdi\r
50 and rcx, 15 ; rcx + rsi should be 16 bytes aligned\r
51 jz @F ; skip if rcx == 0\r
52 cmp rcx, r8\r
53 cmova rcx, r8\r
54 sub r8, rcx\r
55 rep movsb\r
56@@:\r
57 mov rcx, r8\r
58 and r8, 15\r
59 shr rcx, 4 ; rcx <- # of DQwords to copy\r
60 jz @CopyBytes\r
61@@:\r
62 movdqu xmm0, [rsi] ; rsi may not be 16-byte aligned\r
63 movdqa [rdi], xmm0 ; rdi should be 16-byte aligned\r
64 add rsi, 16\r
65 add rdi, 16\r
66 loop @B\r
67 jmp @CopyBytes ; copy remaining bytes\r
68@CopyBackward:\r
69 mov rsi, r9 ; rsi <- Last byte of Source\r
70 lea rdi, [rdi + r8 - 1] ; rdi <- Last byte of Destination\r
71 std\r
72@CopyBytes:\r
73 mov rcx, r8\r
74 rep movsb\r
75 cld\r
76@CopyMemDone: \r
77 ret\r
78EfiCommonLibCopyMem ENDP\r
79\r
80 END\r