+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
-; This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution. The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-;\r
-; Module Name:\r
-;\r
-; CopyMem.asm\r
-;\r
-; Abstract:\r
-;\r
-; memcpy function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID *\r
-; memcpy (\r
-; OUT VOID *DestinationBuffer,\r
-; IN CONST VOID *SourceBuffer,\r
-; IN UINTN Length\r
-; );\r
-;------------------------------------------------------------------------------\r
-memcpy PROC USES rsi rdi\r
- mov rax, rcx ; rax <- Destination as return value\r
- cmp rdx, rcx ; if Source == Destination, do nothing\r
- je @CopyMemDone\r
- cmp r8, 0 ; if Count == 0, do nothing\r
- je @CopyMemDone\r
- mov rsi, rdx ; rsi <- Source\r
- mov rdi, rcx ; rdi <- Destination\r
- lea r9, [rsi + r8 - 1] ; r9 <- Last byte of Source\r
- cmp rsi, rdi\r
- jae @F ; Copy forward if Source > Destination\r
- cmp r9, rdi ; Overlapped?\r
- jae @CopyBackward ; Copy backward if overlapped\r
-@@:\r
- xor rcx, rcx\r
- sub rcx, rdi ; rcx <- -rdi\r
- and rcx, 15 ; rcx + rsi should be 16 bytes aligned\r
- jz @F ; skip if rcx == 0\r
- cmp rcx, r8\r
- cmova rcx, r8\r
- sub r8, rcx\r
- rep movsb\r
-@@:\r
- mov rcx, r8\r
- and r8, 15\r
- shr rcx, 4 ; rcx <- # of DQwords to copy\r
- jz @CopyBytes\r
-@@:\r
- movdqu xmm0, [rsi] ; rsi may not be 16-byte aligned\r
- movdqa [rdi], xmm0 ; rdi should be 16-byte aligned\r
- add rsi, 16\r
- add rdi, 16\r
- loop @B\r
- jmp @CopyBytes ; copy remaining bytes\r
-@CopyBackward:\r
- mov rsi, r9 ; rsi <- Last byte of Source\r
- lea rdi, [rdi + r8 - 1] ; rdi <- Last byte of Destination\r
- std\r
-@CopyBytes:\r
- mov rcx, r8\r
- rep movsb\r
- cld\r
-@CopyMemDone: \r
- ret\r
-memcpy ENDP\r
-\r
- END\r