]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.nasm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / X64 / SetMem.nasm
CommitLineData
e8758b6a
JJ
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
9344f092 4; SPDX-License-Identifier: BSD-2-Clause-Patent\r
e8758b6a
JJ
5;\r
6; Module Name:\r
7;\r
8; SetMem.nasm\r
9;\r
10; Abstract:\r
11;\r
12; SetMem function\r
13;\r
14; Notes:\r
15;\r
16;------------------------------------------------------------------------------\r
17\r
18 DEFAULT REL\r
19 SECTION .text\r
20\r
21;------------------------------------------------------------------------------\r
22; VOID *\r
23; InternalMemSetMem (\r
24; IN VOID *Buffer,\r
25; IN UINTN Count,\r
26; IN UINT8 Value\r
27; )\r
28;------------------------------------------------------------------------------\r
29global ASM_PFX(InternalMemSetMem)\r
30ASM_PFX(InternalMemSetMem):\r
31 push rdi\r
32 mov rdi, rcx ; rdi <- Buffer\r
33 mov al, r8b ; al <- Value\r
34 mov r9, rdi ; r9 <- Buffer as return value\r
35 xor rcx, rcx\r
36 sub rcx, rdi\r
37 and rcx, 15 ; rcx + rdi aligns on 16-byte boundary\r
38 jz .0\r
39 cmp rcx, rdx\r
40 cmova rcx, rdx\r
41 sub rdx, rcx\r
42 rep stosb\r
43.0:\r
44 mov rcx, rdx\r
45 and rdx, 15\r
46 shr rcx, 4\r
47 jz @SetBytes\r
48 mov ah, al ; ax <- Value repeats twice\r
49 movdqa [rsp + 0x10], xmm0 ; save xmm0\r
50 movd xmm0, eax ; xmm0[0..16] <- Value repeats twice\r
51 pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times\r
52 movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times\r
53.1:\r
54 movntdq [rdi], xmm0 ; rdi should be 16-byte aligned\r
55 add rdi, 16\r
56 loop .1\r
57 mfence\r
58 movdqa xmm0, [rsp + 0x10] ; restore xmm0\r
59@SetBytes:\r
60 mov ecx, edx ; high 32 bits of rcx are always zero\r
61 rep stosb\r
62 mov rax, r9 ; rax <- Return value\r
63 pop rdi\r
64 ret\r
65\r