]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/SetMem.c
2 Implementation of the EfiSetMem routine. This function is broken
3 out into its own source file so that it can be excluded from a
4 build for a particular platform easily if an optimized version
7 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
8 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
9 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include "MemLibInternals.h"
21 Set Buffer to Value for Size bytes.
23 @param Buffer The memory to set.
24 @param Length The number of bytes to set.
25 @param Value The value of the set operation.
39 // Declare the local variables that actually move the data elements as
40 // volatile to prevent the optimizer from replacing this function with
41 // the intrinsic memset()
43 volatile UINT8
*Pointer8
;
44 volatile UINT32
*Pointer32
;
45 volatile UINT64
*Pointer64
;
49 if ((((UINTN
)Buffer
& 0x7) == 0) && (Length
>= 8)) {
50 // Generate the 64bit value
51 Value32
= (Value
<< 24) | (Value
<< 16) | (Value
<< 8) | Value
;
52 Value64
= LShiftU64 (Value32
, 32) | Value32
;
54 Pointer64
= (UINT64
*)Buffer
;
56 *(Pointer64
++) = Value64
;
60 // Finish with bytes if needed
61 Pointer8
= (UINT8
*)Pointer64
;
62 } else if ((((UINTN
)Buffer
& 0x3) == 0) && (Length
>= 4)) {
63 // Generate the 32bit value
64 Value32
= (Value
<< 24) | (Value
<< 16) | (Value
<< 8) | Value
;
66 Pointer32
= (UINT32
*)Buffer
;
68 *(Pointer32
++) = Value32
;
72 // Finish with bytes if needed
73 Pointer8
= (UINT8
*)Pointer32
;
75 Pointer8
= (UINT8
*)Buffer
;
77 while (Length
-- > 0) {
78 *(Pointer8
++) = Value
;