]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/Ia32/SetMem.asm
f41d19cc8219884c0a4dbd79e0256148df926408
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / Ia32 / SetMem.asm
1 //
2 // Include common header file for this module.
3 //
4 #include "CommonHeader.h"
5
6 ;------------------------------------------------------------------------------
7 ;
8 ; Copyright (c) 2006, Intel Corporation
9 ; All rights reserved. This program and the accompanying materials
10 ; are licensed and made available under the terms and conditions of the BSD License
11 ; which accompanies this distribution. The full text of the license may be found at
12 ; http://opensource.org/licenses/bsd-license.php
13 ;
14 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 ;
17 ; Module Name:
18 ;
19 ; SetMem.asm
20 ;
21 ; Abstract:
22 ;
23 ; SetMem function
24 ;
25 ; Notes:
26 ;
27 ;------------------------------------------------------------------------------
28
29 .686
30 .model flat,C
31 .xmm
32 .code
33
34 ;------------------------------------------------------------------------------
35 ; VOID *
36 ; EFIAPI
37 ; InternalMemSetMem (
38 ; IN VOID *Buffer,
39 ; IN UINTN Count,
40 ; IN UINT8 Value
41 ; );
42 ;------------------------------------------------------------------------------
43 InternalMemSetMem PROC USES edi
44 mov edx, [esp + 12] ; edx <- Count
45 mov edi, [esp + 8] ; edi <- Buffer
46 mov al, [esp + 16] ; al <- Value
47 xor ecx, ecx
48 sub ecx, edi
49 and ecx, 15 ; ecx + edi aligns on 16-byte boundary
50 jz @F
51 cmp ecx, edx
52 cmova ecx, edx
53 sub edx, ecx
54 rep stosb
55 @@:
56 mov ecx, edx
57 and edx, 15
58 shr ecx, 4 ; ecx <- # of DQwords to set
59 jz @SetBytes
60 mov ah, al ; ax <- Value | (Value << 8)
61 add esp, -16
62 movdqu [esp], xmm0 ; save xmm0
63 movd xmm0, eax
64 pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times
65 movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times
66 @@:
67 movntdq [edi], xmm0 ; edi should be 16-byte aligned
68 add edi, 16
69 loop @B
70 mfence
71 movdqu xmm0, [esp] ; restore xmm0
72 add esp, 16 ; stack cleanup
73 @SetBytes:
74 mov ecx, edx
75 rep stosb
76 mov eax, [esp + 8] ; eax <- Buffer as return value
77 ret
78 InternalMemSetMem ENDP
79
80 END