--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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 <- End of Source\r
+ cmp rsi, rdi\r
+ jae @F\r
+ cmp r9, rdi\r
+ jae @CopyBackward ; Copy backward if overlapped\r
+@@:\r
+ mov rcx, r8\r
+ and r8, 7\r
+ shr rcx, 3 ; rcx <- # of Qwords to copy\r
+ jz @CopyBytes\r
+ DB 49h, 0fh, 7eh, 0c2h ; movd r10, mm0 (Save mm0 in r10)\r
+@@:\r
+ DB 0fh, 6fh, 06h ; movd mm0, [rsi]\r
+ DB 48h, 0fh, 7eh, 07h ; movd [rdi], mm0\r
+ add rsi, 8\r
+ add rdi, 8\r
+ loop @B\r
+ DB 49h, 0fh, 6eh, 0c2h ; movd mm0, r10 (Restore mm0)\r
+ jmp @CopyBytes\r
+@CopyBackward:\r
+ mov rsi, r9 ; rsi <- End of Source\r
+ lea rdi, [rdi + r8 - 1] ; rdi <- End of Destination\r
+ std ; set direction flag\r
+@CopyBytes:\r
+ mov rcx, r8\r
+ rep movsb ; Copy bytes backward\r
+ cld\r
+@CopyMemDone: \r
+ ret\r
+memcpy ENDP\r
+\r
+ END\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; memcpyRep1.asm\r
+;\r
+; Abstract:\r
+;\r
+; CopyMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; memcpy (\r
+; OUT VOID *Destination,\r
+; IN VOID *Source,\r
+; IN UINTN Count\r
+; );\r
+;------------------------------------------------------------------------------\r
+memcpy PROC USES rsi rdi\r
+ mov rax, rcx\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 <- End of Source\r
+ cmp rsi, rdi\r
+ jae @F\r
+ cmp r9, rdi\r
+ jb @F ; Copy backward if overlapped\r
+ mov rsi, r9 ; rsi <- End of Source\r
+ lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
+ std ; set direction flag\r
+@@:\r
+ mov rcx, r8\r
+ rep movsb ; Copy bytes backward\r
+ cld\r
+@CopyMemDone:\r
+ ret\r
+memcpy ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; memcpyRep8.asm\r
+;\r
+; Abstract:\r
+;\r
+; CopyMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; memcpy (\r
+; OUT VOID *Destination,\r
+; IN VOID *Source,\r
+; IN UINTN Count\r
+; );\r
+;------------------------------------------------------------------------------\r
+memcpy PROC USES rsi rdi\r
+ mov rax, rcx\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 <- End of Source\r
+ cmp rsi, rdi\r
+ jae @F\r
+ cmp r9, rdi\r
+ jae @CopyBackward ; Copy backward if overlapped\r
+@@:\r
+ mov rcx, r8\r
+ and r8, 3\r
+ shr rcx, 2\r
+ rep movsd ; Copy as many Dwords as possible\r
+ jmp @CopyBytes\r
+@CopyBackward:\r
+ mov rsi, r9 ; rsi <- End of Source\r
+ lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
+ std ; set direction flag\r
+@CopyBytes:\r
+ mov rcx, r8\r
+ rep movsb ; Copy bytes backward\r
+ cld\r
+@CopyMemDone:\r
+ ret\r
+memcpy ENDP\r
+\r
+ END\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; memcpyRep8.asm\r
+;\r
+; Abstract:\r
+;\r
+; CopyMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; memcpy (\r
+; OUT VOID *Destination,\r
+; IN VOID *Source,\r
+; IN UINTN Count\r
+; );\r
+;------------------------------------------------------------------------------\r
+memcpy PROC USES rsi rdi\r
+ mov rax, rcx\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 <- End of Source\r
+ cmp rsi, rdi\r
+ jae @F\r
+ cmp r9, rdi\r
+ jae @CopyBackward ; Copy backward if overlapped\r
+@@:\r
+ mov rcx, r8\r
+ and r8, 7\r
+ shr rcx, 3\r
+ rep movsq ; Copy as many Qwords as possible\r
+ jmp @CopyBytes\r
+@CopyBackward:\r
+ mov rsi, r9 ; rsi <- End of Source\r
+ lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
+ std ; set direction flag\r
+@CopyBytes:\r
+ mov rcx, r8\r
+ rep movsb ; Copy bytes backward\r
+ cld\r
+@CopyMemDone:\r
+ ret\r
+memcpy ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; SetMem.asm\r
+;\r
+; Abstract:\r
+;\r
+; memset function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID *\r
+; memset (\r
+; OUT VOID *Buffer, --> rcx\r
+; IN UINT8 Value, --> rdx\r
+; IN UINTN Length --> r8\r
+; );\r
+;------------------------------------------------------------------------------\r
+memset PROC USES rdi\r
+ mov rax, rcx \r
+ cmp r8, 0 ; if Size == 0, do nothing\r
+ je @SetDone\r
+ mov rax, rdx ; rdx <-> r8\r
+ mov rdx, r8 ; rdx <- Length\r
+ mov r8, rax ; r8 <- Value\r
+ mov ah, al\r
+ DB 48h, 0fh, 6eh, 0c0h ; movd mm0, rax\r
+ mov r8, rcx\r
+ mov rdi, r8 ; rdi <- Buffer\r
+ mov rcx, rdx\r
+ and edx, 7\r
+ shr rcx, 3\r
+ jz @SetBytes\r
+ DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h\r
+@@:\r
+ DB 48h, 0fh, 7eh, 07h ; movd [rdi], mm0\r
+ add rdi, 8\r
+ loop @B\r
+@SetBytes:\r
+ mov ecx, edx\r
+ rep stosb\r
+ mov rax, r8\r
+@SetDone:\r
+ ret\r
+memset ENDP\r
+\r
+ END\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; memsetRep1.asm\r
+;\r
+; Abstract:\r
+;\r
+; SetMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID *\r
+; memset (\r
+; OUT VOID *Buffer,\r
+; IN UINTN Size,\r
+; IN UINT8 Value\r
+; );\r
+;------------------------------------------------------------------------------\r
+memset PROC USES rdi\r
+ cmp rdx, 0 ; if Size == 0, do nothing\r
+ mov r9, rcx\r
+ je @SetDone\r
+ mov rax, r8\r
+ mov rdi, rcx\r
+ mov rcx, rdx\r
+ rep stosb\r
+@SetDone:\r
+ mov rax, r9\r
+ ret\r
+memset ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; SetMem.asm\r
+;\r
+; Abstract:\r
+;\r
+; memset function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID *\r
+; memset (\r
+; OUT VOID *Buffer,\r
+; IN UINT8 Value,\r
+; IN UINTN Count\r
+; )\r
+;------------------------------------------------------------------------------\r
+memset PROC USES rdi\r
+ cmp r8, 0 ; if Size == 0, do nothing\r
+ mov r9, rcx\r
+ je @SetDone\r
+ mov al, dl\r
+ mov ah, al\r
+ shrd edx, eax, 16\r
+ shld eax, edx, 16\r
+ mov rdi, rcx\r
+ mov rcx, r8\r
+ shr rcx, 2\r
+ rep stosd\r
+ mov rcx, r8\r
+ and rcx, 3\r
+ rep stosb\r
+@SetDone:\r
+ mov rax, r9\r
+ ret\r
+memset ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; memsetRep8.asm\r
+;\r
+; Abstract:\r
+;\r
+; SetMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; memset (\r
+; OUT VOID *Buffer,\r
+; IN UINT8 Value,\r
+; IN UINTN Length\r
+; );\r
+;------------------------------------------------------------------------------\r
+memset PROC USES rdi rbx\r
+ cmp r8, 0 ; if Size == 0, do nothing\r
+ mov r9, rcx\r
+ je @SetDone\r
+ mov rax, rdx\r
+ mov bl, al\r
+ mov bh, bl\r
+ mov ax, bx\r
+ shl rax, 10h\r
+ mov ax, bx\r
+ mov ebx, eax\r
+ shl rax, 20h\r
+ mov eax, ebx\r
+ mov rdi, rcx\r
+ mov rcx, r8\r
+ shr rcx, 3\r
+ rep stosq\r
+ mov rcx, rdx\r
+ and rcx, 7\r
+ rep stosb\r
+@SetDone:\r
+ mov rax, r9\r
+ ret\r
+memset ENDP\r
+\r
+ END\r
+\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; SetMem.asm\r
+;\r
+; Abstract:\r
+;\r
+; memset function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID *\r
+; memset (\r
+; OUT VOID *Buffer, --> rcx\r
+; IN UINT8 Value, --> rdx\r
+; IN UINTN Length --> r8\r
+; );\r
+;------------------------------------------------------------------------------\r
+memset PROC USES rdi\r
+ mov rax, rcx \r
+ cmp r8, 0 ; if Size == 0, do nothing\r
+ je @SetDone \r
+ mov rax, rdx ; rdx <-> r8\r
+ mov rdx, r8 ; rdx <- Length\r
+ mov r8, rax ; r8 <- Value\r
+ \r
+ mov rdi, rcx ; rdi <- Buffer\r
+ mov al, r8b ; al <- Value\r
+ mov r9, rdi ; r9 <- Buffer as return value\r
+ xor rcx, rcx\r
+ sub rcx, rdi\r
+ and rcx, 15 ; rcx + rdi aligns on 16-byte boundary\r
+ jz @F\r
+ cmp rcx, rdx\r
+ cmova rcx, rdx\r
+ sub rdx, rcx\r
+ rep stosb\r
+@@:\r
+ mov rcx, rdx\r
+ and rdx, 15\r
+ shr rcx, 4\r
+ jz @SetBytes\r
+ mov ah, al ; ax <- Value repeats twice\r
+ movd xmm0, eax ; xmm0[0..16] <- Value repeats twice\r
+ pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times\r
+ movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times\r
+@@:\r
+ movdqa [rdi], xmm0 ; rdi should be 16-byte aligned\r
+ add rdi, 16\r
+ loop @B\r
+@SetBytes:\r
+ mov ecx, edx ; high 32 bits of rcx are always zero\r
+ rep stosb\r
+ mov rax, r9 ; rax <- Return value\r
+@SetDone:\r
+ ret\r
+memset ENDP\r
+\r
+ END\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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 <- End of Source\r
- cmp rsi, rdi\r
- jae @F\r
- cmp r9, rdi\r
- jae @CopyBackward ; Copy backward if overlapped\r
-@@:\r
- mov rcx, r8\r
- and r8, 7\r
- shr rcx, 3 ; rcx <- # of Qwords to copy\r
- jz @CopyBytes\r
- DB 49h, 0fh, 7eh, 0c2h ; movd r10, mm0 (Save mm0 in r10)\r
-@@:\r
- DB 0fh, 6fh, 06h ; movd mm0, [rsi]\r
- DB 48h, 0fh, 7eh, 07h ; movd [rdi], mm0\r
- add rsi, 8\r
- add rdi, 8\r
- loop @B\r
- DB 49h, 0fh, 6eh, 0c2h ; movd mm0, r10 (Restore mm0)\r
- jmp @CopyBytes\r
-@CopyBackward:\r
- mov rsi, r9 ; rsi <- End of Source\r
- lea rdi, [rdi + r8 - 1] ; rdi <- End of Destination\r
- std ; set direction flag\r
-@CopyBytes:\r
- mov rcx, r8\r
- rep movsb ; Copy bytes backward\r
- cld\r
-@CopyMemDone: \r
- ret\r
-memcpy ENDP\r
-\r
- END\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; memcpyRep1.asm\r
-;\r
-; Abstract:\r
-;\r
-; CopyMem function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; memcpy (\r
-; OUT VOID *Destination,\r
-; IN VOID *Source,\r
-; IN UINTN Count\r
-; );\r
-;------------------------------------------------------------------------------\r
-memcpy PROC USES rsi rdi\r
- mov rax, rcx\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 <- End of Source\r
- cmp rsi, rdi\r
- jae @F\r
- cmp r9, rdi\r
- jb @F ; Copy backward if overlapped\r
- mov rsi, r9 ; rsi <- End of Source\r
- lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
- std ; set direction flag\r
-@@:\r
- mov rcx, r8\r
- rep movsb ; Copy bytes backward\r
- cld\r
-@CopyMemDone:\r
- ret\r
-memcpy ENDP\r
-\r
- END\r
-\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; memcpyRep8.asm\r
-;\r
-; Abstract:\r
-;\r
-; CopyMem function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; memcpy (\r
-; OUT VOID *Destination,\r
-; IN VOID *Source,\r
-; IN UINTN Count\r
-; );\r
-;------------------------------------------------------------------------------\r
-memcpy PROC USES rsi rdi\r
- mov rax, rcx\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 <- End of Source\r
- cmp rsi, rdi\r
- jae @F\r
- cmp r9, rdi\r
- jae @CopyBackward ; Copy backward if overlapped\r
-@@:\r
- mov rcx, r8\r
- and r8, 3\r
- shr rcx, 2\r
- rep movsd ; Copy as many Dwords as possible\r
- jmp @CopyBytes\r
-@CopyBackward:\r
- mov rsi, r9 ; rsi <- End of Source\r
- lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
- std ; set direction flag\r
-@CopyBytes:\r
- mov rcx, r8\r
- rep movsb ; Copy bytes backward\r
- cld\r
-@CopyMemDone:\r
- ret\r
-memcpy ENDP\r
-\r
- END\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; memcpyRep8.asm\r
-;\r
-; Abstract:\r
-;\r
-; CopyMem function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; memcpy (\r
-; OUT VOID *Destination,\r
-; IN VOID *Source,\r
-; IN UINTN Count\r
-; );\r
-;------------------------------------------------------------------------------\r
-memcpy PROC USES rsi rdi\r
- mov rax, rcx\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 <- End of Source\r
- cmp rsi, rdi\r
- jae @F\r
- cmp r9, rdi\r
- jae @CopyBackward ; Copy backward if overlapped\r
-@@:\r
- mov rcx, r8\r
- and r8, 7\r
- shr rcx, 3\r
- rep movsq ; Copy as many Qwords as possible\r
- jmp @CopyBytes\r
-@CopyBackward:\r
- mov rsi, r9 ; rsi <- End of Source\r
- lea rdi, [rdi + r8 - 1] ; esi <- End of Destination\r
- std ; set direction flag\r
-@CopyBytes:\r
- mov rcx, r8\r
- rep movsb ; Copy bytes backward\r
- cld\r
-@CopyMemDone:\r
- ret\r
-memcpy ENDP\r
-\r
- END\r
-\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; SetMem.asm\r
-;\r
-; Abstract:\r
-;\r
-; memset function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID *\r
-; memset (\r
-; OUT VOID *Buffer, --> rcx\r
-; IN UINT8 Value, --> rdx\r
-; IN UINTN Length --> r8\r
-; );\r
-;------------------------------------------------------------------------------\r
-memset PROC USES rdi\r
- mov rax, rcx \r
- cmp r8, 0 ; if Size == 0, do nothing\r
- je @SetDone\r
- mov rax, rdx ; rdx <-> r8\r
- mov rdx, r8 ; rdx <- Length\r
- mov r8, rax ; r8 <- Value\r
- mov ah, al\r
- DB 48h, 0fh, 6eh, 0c0h ; movd mm0, rax\r
- mov r8, rcx\r
- mov rdi, r8 ; rdi <- Buffer\r
- mov rcx, rdx\r
- and edx, 7\r
- shr rcx, 3\r
- jz @SetBytes\r
- DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h\r
-@@:\r
- DB 48h, 0fh, 7eh, 07h ; movd [rdi], mm0\r
- add rdi, 8\r
- loop @B\r
-@SetBytes:\r
- mov ecx, edx\r
- rep stosb\r
- mov rax, r8\r
-@SetDone:\r
- ret\r
-memset ENDP\r
-\r
- END\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; memsetRep1.asm\r
-;\r
-; Abstract:\r
-;\r
-; SetMem function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID *\r
-; memset (\r
-; OUT VOID *Buffer,\r
-; IN UINTN Size,\r
-; IN UINT8 Value\r
-; );\r
-;------------------------------------------------------------------------------\r
-memset PROC USES rdi\r
- cmp rdx, 0 ; if Size == 0, do nothing\r
- mov r9, rcx\r
- je @SetDone\r
- mov rax, r8\r
- mov rdi, rcx\r
- mov rcx, rdx\r
- rep stosb\r
-@SetDone:\r
- mov rax, r9\r
- ret\r
-memset ENDP\r
-\r
- END\r
-\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; SetMem.asm\r
-;\r
-; Abstract:\r
-;\r
-; memset function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID *\r
-; memset (\r
-; OUT VOID *Buffer,\r
-; IN UINT8 Value,\r
-; IN UINTN Count\r
-; )\r
-;------------------------------------------------------------------------------\r
-memset PROC USES rdi\r
- cmp r8, 0 ; if Size == 0, do nothing\r
- mov r9, rcx\r
- je @SetDone\r
- mov al, dl\r
- mov ah, al\r
- shrd edx, eax, 16\r
- shld eax, edx, 16\r
- mov rdi, rcx\r
- mov rcx, r8\r
- shr rcx, 2\r
- rep stosd\r
- mov rcx, r8\r
- and rcx, 3\r
- rep stosb\r
-@SetDone:\r
- mov rax, r9\r
- ret\r
-memset ENDP\r
-\r
- END\r
-\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; memsetRep8.asm\r
-;\r
-; Abstract:\r
-;\r
-; SetMem function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID\r
-; memset (\r
-; OUT VOID *Buffer,\r
-; IN UINT8 Value,\r
-; IN UINTN Length\r
-; );\r
-;------------------------------------------------------------------------------\r
-memset PROC USES rdi rbx\r
- cmp r8, 0 ; if Size == 0, do nothing\r
- mov r9, rcx\r
- je @SetDone\r
- mov rax, rdx\r
- mov bl, al\r
- mov bh, bl\r
- mov ax, bx\r
- shl rax, 10h\r
- mov ax, bx\r
- mov ebx, eax\r
- shl rax, 20h\r
- mov eax, ebx\r
- mov rdi, rcx\r
- mov rcx, r8\r
- shr rcx, 3\r
- rep stosq\r
- mov rcx, rdx\r
- and rcx, 7\r
- rep stosb\r
-@SetDone:\r
- mov rax, r9\r
- ret\r
-memset ENDP\r
-\r
- END\r
-\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2007, Intel Corporation\r
-; All rights reserved. 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
-; SetMem.asm\r
-;\r
-; Abstract:\r
-;\r
-; memset function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
-\r
-;------------------------------------------------------------------------------\r
-; VOID *\r
-; memset (\r
-; OUT VOID *Buffer, --> rcx\r
-; IN UINT8 Value, --> rdx\r
-; IN UINTN Length --> r8\r
-; );\r
-;------------------------------------------------------------------------------\r
-memset PROC USES rdi\r
- mov rax, rcx \r
- cmp r8, 0 ; if Size == 0, do nothing\r
- je @SetDone \r
- mov rax, rdx ; rdx <-> r8\r
- mov rdx, r8 ; rdx <- Length\r
- mov r8, rax ; r8 <- Value\r
- \r
- mov rdi, rcx ; rdi <- Buffer\r
- mov al, r8b ; al <- Value\r
- mov r9, rdi ; r9 <- Buffer as return value\r
- xor rcx, rcx\r
- sub rcx, rdi\r
- and rcx, 15 ; rcx + rdi aligns on 16-byte boundary\r
- jz @F\r
- cmp rcx, rdx\r
- cmova rcx, rdx\r
- sub rdx, rcx\r
- rep stosb\r
-@@:\r
- mov rcx, rdx\r
- and rdx, 15\r
- shr rcx, 4\r
- jz @SetBytes\r
- mov ah, al ; ax <- Value repeats twice\r
- movd xmm0, eax ; xmm0[0..16] <- Value repeats twice\r
- pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times\r
- movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times\r
-@@:\r
- movdqa [rdi], xmm0 ; rdi should be 16-byte aligned\r
- add rdi, 16\r
- loop @B\r
-@SetBytes:\r
- mov ecx, edx ; high 32 bits of rcx are always zero\r
- rep stosb\r
- mov rax, r9 ; rax <- Return value\r
-@SetDone:\r
- ret\r
-memset ENDP\r
-\r
- END\r