]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 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 | |
2fcf0abf | 7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
01f688be AB |
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 | |
9344f092 | 11 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e1f414b6 | 12 | \r |
e1f414b6 | 13 | **/\r |
14 | \r | |
1efcc4ae | 15 | \r |
f734a10a | 16 | \r |
e1f414b6 | 17 | \r |
18 | #include "MemLibInternals.h"\r | |
19 | \r | |
20 | /**\r | |
21 | Set Buffer to Value for Size bytes.\r | |
22 | \r | |
15c952e7 | 23 | @param Buffer The memory to set.\r |
24 | @param Length The number of bytes to set.\r | |
25 | @param Value The value of the set operation.\r | |
e1f414b6 | 26 | \r |
27 | @return Buffer\r | |
28 | \r | |
29 | **/\r | |
30 | VOID *\r | |
31 | EFIAPI\r | |
32 | InternalMemSetMem (\r | |
ea6898b9 | 33 | OUT VOID *Buffer,\r |
0827d304 | 34 | IN UINTN Length,\r |
e1f414b6 | 35 | IN UINT8 Value\r |
36 | )\r | |
37 | {\r | |
38 | //\r | |
39 | // Declare the local variables that actually move the data elements as\r | |
40 | // volatile to prevent the optimizer from replacing this function with\r | |
41 | // the intrinsic memset()\r | |
42 | //\r | |
01f688be AB |
43 | volatile UINT8 *Pointer8;\r |
44 | volatile UINT32 *Pointer32;\r | |
45 | volatile UINT64 *Pointer64;\r | |
46 | UINT32 Value32;\r | |
47 | UINT64 Value64;\r | |
48 | \r | |
49 | if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {\r | |
50 | // Generate the 64bit value\r | |
51 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
52 | Value64 = LShiftU64 (Value32, 32) | Value32;\r | |
53 | \r | |
54 | Pointer64 = (UINT64*)Buffer;\r | |
55 | while (Length >= 8) {\r | |
56 | *(Pointer64++) = Value64;\r | |
57 | Length -= 8;\r | |
58 | }\r | |
e1f414b6 | 59 | \r |
01f688be AB |
60 | // Finish with bytes if needed\r |
61 | Pointer8 = (UINT8*)Pointer64;\r | |
62 | } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {\r | |
63 | // Generate the 32bit value\r | |
64 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
65 | \r | |
66 | Pointer32 = (UINT32*)Buffer;\r | |
67 | while (Length >= 4) {\r | |
68 | *(Pointer32++) = Value32;\r | |
69 | Length -= 4;\r | |
70 | }\r | |
71 | \r | |
72 | // Finish with bytes if needed\r | |
73 | Pointer8 = (UINT8*)Pointer32;\r | |
74 | } else {\r | |
75 | Pointer8 = (UINT8*)Buffer;\r | |
76 | }\r | |
7efb1d89 | 77 | while (Length-- > 0) {\r |
01f688be | 78 | *(Pointer8++) = Value;\r |
e1f414b6 | 79 | }\r |
80 | return Buffer;\r | |
81 | }\r |