TianoCore EDK2 master
Loading...
Searching...
No Matches
SetMem.c
Go to the documentation of this file.
1
15#include "MemLibInternals.h"
16
27VOID *
28EFIAPI
30 OUT VOID *Buffer,
31 IN UINTN Length,
32 IN UINT8 Value
33 )
34{
35 //
36 // Declare the local variables that actually move the data elements as
37 // volatile to prevent the optimizer from replacing this function with
38 // the intrinsic memset()
39 //
40 volatile UINT8 *Pointer8;
41 volatile UINT32 *Pointer32;
42 volatile UINT64 *Pointer64;
43 UINT32 Value32;
44 UINT64 Value64;
45
46 if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {
47 // Generate the 64bit value
48 Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
49 Value64 = LShiftU64 (Value32, 32) | Value32;
50
51 Pointer64 = (UINT64 *)Buffer;
52 while (Length >= 8) {
53 *(Pointer64++) = Value64;
54 Length -= 8;
55 }
56
57 // Finish with bytes if needed
58 Pointer8 = (UINT8 *)Pointer64;
59 } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {
60 // Generate the 32bit value
61 Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
62
63 Pointer32 = (UINT32 *)Buffer;
64 while (Length >= 4) {
65 *(Pointer32++) = Value32;
66 Length -= 4;
67 }
68
69 // Finish with bytes if needed
70 Pointer8 = (UINT8 *)Pointer32;
71 } else {
72 Pointer8 = (UINT8 *)Buffer;
73 }
74
75 while (Length-- > 0) {
76 *(Pointer8++) = Value;
77 }
78
79 return Buffer;
80}
UINT64 UINTN
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID *EFIAPI InternalMemSetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMem.c:29