]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation of the EfiSetMem routine. This function is broken\r | |
3 | out into its own source file so that it can be excluded from a\r | |
4 | build for a particular platform easily if an optimized version\r | |
5 | is desired.\r | |
6 | \r | |
7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
8 | Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r | |
9 | Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r | |
10 | \r | |
11 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "MemLibInternals.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Set Buffer to Value for Size bytes.\r | |
19 | \r | |
20 | @param Buffer The memory to set.\r | |
21 | @param Length The number of bytes to set.\r | |
22 | @param Value The value of the set operation.\r | |
23 | \r | |
24 | @return Buffer\r | |
25 | \r | |
26 | **/\r | |
27 | VOID *\r | |
28 | EFIAPI\r | |
29 | InternalMemSetMem (\r | |
30 | OUT VOID *Buffer,\r | |
31 | IN UINTN Length,\r | |
32 | IN UINT8 Value\r | |
33 | )\r | |
34 | {\r | |
35 | //\r | |
36 | // Declare the local variables that actually move the data elements as\r | |
37 | // volatile to prevent the optimizer from replacing this function with\r | |
38 | // the intrinsic memset()\r | |
39 | //\r | |
40 | volatile UINT8 *Pointer8;\r | |
41 | volatile UINT32 *Pointer32;\r | |
42 | volatile UINT64 *Pointer64;\r | |
43 | UINT32 Value32;\r | |
44 | UINT64 Value64;\r | |
45 | \r | |
46 | if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {\r | |
47 | // Generate the 64bit value\r | |
48 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
49 | Value64 = LShiftU64 (Value32, 32) | Value32;\r | |
50 | \r | |
51 | Pointer64 = (UINT64 *)Buffer;\r | |
52 | while (Length >= 8) {\r | |
53 | *(Pointer64++) = Value64;\r | |
54 | Length -= 8;\r | |
55 | }\r | |
56 | \r | |
57 | // Finish with bytes if needed\r | |
58 | Pointer8 = (UINT8 *)Pointer64;\r | |
59 | } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {\r | |
60 | // Generate the 32bit value\r | |
61 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
62 | \r | |
63 | Pointer32 = (UINT32 *)Buffer;\r | |
64 | while (Length >= 4) {\r | |
65 | *(Pointer32++) = Value32;\r | |
66 | Length -= 4;\r | |
67 | }\r | |
68 | \r | |
69 | // Finish with bytes if needed\r | |
70 | Pointer8 = (UINT8 *)Pointer32;\r | |
71 | } else {\r | |
72 | Pointer8 = (UINT8 *)Buffer;\r | |
73 | }\r | |
74 | \r | |
75 | while (Length-- > 0) {\r | |
76 | *(Pointer8++) = Value;\r | |
77 | }\r | |
78 | \r | |
79 | return Buffer;\r | |
80 | }\r |