]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/Ia32/SetMem.nasm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / Ia32 / 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 SECTION .text
19
20 ;------------------------------------------------------------------------------
21 ; VOID *
22 ; EFIAPI
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 edi
32 mov edx, [esp + 12] ; edx <- Count
33 mov edi, [esp + 8] ; edi <- Buffer
34 mov al, [esp + 16] ; al <- Value
35 xor ecx, ecx
36 sub ecx, edi
37 and ecx, 15 ; ecx + edi aligns on 16-byte boundary
38 jz .0
39 cmp ecx, edx
40 cmova ecx, edx
41 sub edx, ecx
42 rep stosb
43 .0:
44 mov ecx, edx
45 and edx, 15
46 shr ecx, 4 ; ecx <- # of DQwords to set
47 jz @SetBytes
48 mov ah, al ; ax <- Value | (Value << 8)
49 add esp, -16
50 movdqu [esp], xmm0 ; save xmm0
51 movd xmm0, eax
52 pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times
53 movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times
54 .1:
55 movntdq [edi], xmm0 ; edi should be 16-byte aligned
56 add edi, 16
57 loop .1
58 mfence
59 movdqu xmm0, [esp] ; restore xmm0
60 add esp, 16 ; stack cleanup
61 @SetBytes:
62 mov ecx, edx
63 rep stosb
64 mov eax, [esp + 8] ; eax <- Buffer as return value
65 pop edi
66 ret
67