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