]>
Commit | Line | Data |
---|---|---|
25402f5d HL |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2012-2013, ARM Ltd. All rights reserved.<BR>\r | |
4 | \r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\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 Memory to set.\r | |
21 | @param Length Number of bytes to set\r | |
22 | @param Value 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 = (((UINT64)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 | while (Length-- > 0) {\r | |
60 | *(Pointer8++) = Value;\r | |
61 | }\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 | while (Length-- > 0) {\r | |
75 | *(Pointer8++) = Value;\r | |
76 | }\r | |
77 | } else {\r | |
78 | Pointer8 = (UINT8*)Buffer;\r | |
79 | while (Length-- > 0) {\r | |
80 | *(Pointer8++) = Value;\r | |
81 | }\r | |
82 | }\r | |
83 | return Buffer;\r | |
84 | }\r |