1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
16 ;------------------------------------------------------------------------------
21 ;------------------------------------------------------------------------------
24 ; InternalMemCopyMem (
25 ; IN VOID *Destination,
29 ;------------------------------------------------------------------------------
30 global ASM_PFX(InternalMemCopyMem)
31 ASM_PFX(InternalMemCopyMem):
34 mov rsi, rdx ; rsi <- Source
35 mov rdi, rcx ; rdi <- Destination
36 lea r9, [rsi + r8 - 1] ; r9 <- Last byte of Source
38 mov rax, rdi ; rax <- Destination as return value
39 jae .0 ; Copy forward if Source > Destination
40 cmp r9, rdi ; Overlapped?
41 jae @CopyBackward ; Copy backward if overlapped
44 sub rcx, rdi ; rcx <- -rdi
45 and rcx, 15 ; rcx + rsi should be 16 bytes aligned
46 jz .1 ; skip if rcx == 0
54 shr rcx, 4 ; rcx <- # of DQwords to copy
56 movdqa [rsp + 0x18], xmm0 ; save xmm0 on stack
58 movdqu xmm0, [rsi] ; rsi may not be 16-byte aligned
59 movntdq [rdi], xmm0 ; rdi should be 16-byte aligned
64 movdqa xmm0, [rsp + 0x18] ; restore xmm0
65 jmp @CopyBytes ; copy remaining bytes
67 mov rsi, r9 ; rsi <- Last byte of Source
68 lea rdi, [rdi + r8 - 1] ; rdi <- Last byte of Destination