2 Architecture Independent Base Memory Library Implementation.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: MemLibGeneric.c
15 The following BaseMemoryLib instances share the same version of this file:
24 Set Buffer to Value for Size bytes.
26 @param Buffer Memory to set.
27 @param Size Number of bytes to set
28 @param Value Value of the set operation.
42 Fills a target buffer with a 16-bit value, and returns the target buffer.
44 @param Buffer Pointer to the target buffer to fill.
45 @param Length Number of bytes in Buffer to fill.
46 @param Value Value with which to fill Length bytes of Buffer.
60 ((UINT16
*)Buffer
)[--Length
] = Value
;
61 } while (Length
!= 0);
66 Fills a target buffer with a 32-bit value, and returns the target buffer.
68 @param Buffer Pointer to the target buffer to fill.
69 @param Length Number of bytes in Buffer to fill.
70 @param Value Value with which to fill Length bytes of Buffer.
84 ((UINT32
*)Buffer
)[--Length
] = Value
;
85 } while (Length
!= 0);
90 Fills a target buffer with a 64-bit value, and returns the target buffer.
92 @param Buffer Pointer to the target buffer to fill.
93 @param Length Number of bytes in Buffer to fill.
94 @param Value Value with which to fill Length bytes of Buffer.
101 InternalMemSetMem64 (
108 ((UINT64
*)Buffer
)[--Length
] = Value
;
109 } while (Length
!= 0);
114 Set Buffer to 0 for Size bytes.
116 @param Buffer Memory to set.
117 @param Size Number of bytes to set
129 return InternalMemSetMem (Buffer
, Length
, 0);
133 Compares two memory buffers of a given length.
135 @param DestinationBuffer First memory buffer
136 @param SourceBuffer Second memory buffer
137 @param Length Length of DestinationBuffer and SourceBuffer memory
138 regions to compare. Must be non-zero.
140 @retval 0 if MemOne == MemTwo
145 InternalMemCompareMem (
146 IN CONST VOID
*DestinationBuffer
,
147 IN CONST VOID
*SourceBuffer
,
152 while ((--Length
!= 0) &&
153 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
154 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
155 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
157 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
161 Scans a target buffer for an 8-bit value, and returns a pointer to the
162 matching 8-bit value in the target buffer.
164 @param Buffer Pointer to the target buffer to scan.
165 @param Length Number of bytes in Buffer to scan. Must be non-zero.
166 @param Value Value to search for in the target buffer.
168 @return Pointer to the first occurrence or NULL if not found.
173 InternalMemScanMem8 (
174 IN CONST VOID
*Buffer
,
179 CONST UINT8
*Pointer
;
182 Pointer
= (CONST UINT8
*)Buffer
;
184 if (*(Pointer
++) == Value
) {
187 } while (--Length
!= 0);
192 Scans a target buffer for a 16-bit value, and returns a pointer to the
193 matching 16-bit value in the target buffer.
195 @param Buffer Pointer to the target buffer to scan.
196 @param Length Number of bytes in Buffer to scan. Must be non-zero.
197 @param Value Value to search for in the target buffer.
199 @return Pointer to the first occurrence or NULL if not found.
204 InternalMemScanMem16 (
205 IN CONST VOID
*Buffer
,
210 CONST UINT16
*Pointer
;
213 Pointer
= (CONST UINT16
*)Buffer
;
215 if (*(Pointer
++) == Value
) {
218 } while (--Length
!= 0);
223 Scans a target buffer for a 32-bit value, and returns a pointer to the
224 matching 32-bit value in the target buffer.
226 @param Buffer Pointer to the target buffer to scan.
227 @param Length Number of bytes in Buffer to scan. Must be non-zero.
228 @param Value Value to search for in the target buffer.
230 @return Pointer to the first occurrence or NULL if not found.
235 InternalMemScanMem32 (
236 IN CONST VOID
*Buffer
,
241 CONST UINT32
*Pointer
;
244 Pointer
= (CONST UINT32
*)Buffer
;
246 if (*(Pointer
++) == Value
) {
249 } while (--Length
!= 0);
254 Scans a target buffer for a 64-bit value, and returns a pointer to the
255 matching 64-bit value in the target buffer.
257 @param Buffer Pointer to the target buffer to scan.
258 @param Length Number of bytes in Buffer to scan. Must be non-zero.
259 @param Value Value to search for in the target buffer.
261 @return Pointer to the first occurrence or NULL if not found.
266 InternalMemScanMem64 (
267 IN CONST VOID
*Buffer
,
272 CONST UINT64
*Pointer
;
275 Pointer
= (CONST UINT64
*)Buffer
;
277 if (*(Pointer
++) == Value
) {
280 } while (--Length
!= 0);