2c07d93e8b862ea6aca97e1e019e5bec83a69300
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 // Include common header file for this module.
28 #include "MemLibInternals.h"
31 Fills a target buffer with a 16-bit value, and returns the target buffer.
33 @param Buffer Pointer to the target buffer to fill.
34 @param Length Number of bytes in Buffer to fill.
35 @param Value Value with which to fill Length bytes of Buffer.
49 ((UINT16
*)Buffer
)[--Length
] = Value
;
50 } while (Length
!= 0);
55 Fills a target buffer with a 32-bit value, and returns the target buffer.
57 @param Buffer Pointer to the target buffer to fill.
58 @param Length Number of bytes in Buffer to fill.
59 @param Value Value with which to fill Length bytes of Buffer.
73 ((UINT32
*)Buffer
)[--Length
] = Value
;
74 } while (Length
!= 0);
79 Fills a target buffer with a 64-bit value, and returns the target buffer.
81 @param Buffer Pointer to the target buffer to fill.
82 @param Length Number of bytes in Buffer to fill.
83 @param Value Value with which to fill Length bytes of Buffer.
97 ((UINT64
*)Buffer
)[--Length
] = Value
;
98 } while (Length
!= 0);
103 Set Buffer to 0 for Size bytes.
105 @param Buffer Memory to set.
106 @param Size Number of bytes to set
118 return InternalMemSetMem (Buffer
, Length
, 0);
122 Compares two memory buffers of a given length.
124 @param DestinationBuffer First memory buffer
125 @param SourceBuffer Second memory buffer
126 @param Length Length of DestinationBuffer and SourceBuffer memory
127 regions to compare. Must be non-zero.
129 @retval 0 if MemOne == MemTwo
134 InternalMemCompareMem (
135 IN CONST VOID
*DestinationBuffer
,
136 IN CONST VOID
*SourceBuffer
,
140 while ((--Length
!= 0) &&
141 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
142 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
143 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
145 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
149 Scans a target buffer for an 8-bit value, and returns a pointer to the
150 matching 8-bit value in the target buffer.
152 @param Buffer Pointer to the target buffer to scan.
153 @param Length Number of bytes in Buffer to scan. Must be non-zero.
154 @param Value Value to search for in the target buffer.
156 @return Pointer to the first occurrence or NULL if not found.
161 InternalMemScanMem8 (
162 IN CONST VOID
*Buffer
,
167 CONST UINT8
*Pointer
;
169 Pointer
= (CONST UINT8
*)Buffer
;
171 if (*(Pointer
++) == Value
) {
174 } while (--Length
!= 0);
179 Scans a target buffer for a 16-bit value, and returns a pointer to the
180 matching 16-bit value in the target buffer.
182 @param Buffer Pointer to the target buffer to scan.
183 @param Length Number of bytes in Buffer to scan. Must be non-zero.
184 @param Value Value to search for in the target buffer.
186 @return Pointer to the first occurrence or NULL if not found.
191 InternalMemScanMem16 (
192 IN CONST VOID
*Buffer
,
197 CONST UINT16
*Pointer
;
199 Pointer
= (CONST UINT16
*)Buffer
;
201 if (*(Pointer
++) == Value
) {
204 } while (--Length
!= 0);
209 Scans a target buffer for a 32-bit value, and returns a pointer to the
210 matching 32-bit value in the target buffer.
212 @param Buffer Pointer to the target buffer to scan.
213 @param Length Number of bytes in Buffer to scan. Must be non-zero.
214 @param Value Value to search for in the target buffer.
216 @return Pointer to the first occurrence or NULL if not found.
221 InternalMemScanMem32 (
222 IN CONST VOID
*Buffer
,
227 CONST UINT32
*Pointer
;
229 Pointer
= (CONST UINT32
*)Buffer
;
231 if (*(Pointer
++) == Value
) {
234 } while (--Length
!= 0);
239 Scans a target buffer for a 64-bit value, and returns a pointer to the
240 matching 64-bit value in the target buffer.
242 @param Buffer Pointer to the target buffer to scan.
243 @param Length Number of bytes in Buffer to scan. Must be non-zero.
244 @param Value Value to search for in the target buffer.
246 @return Pointer to the first occurrence or NULL if not found.
251 InternalMemScanMem64 (
252 IN CONST VOID
*Buffer
,
257 CONST UINT64
*Pointer
;
259 Pointer
= (CONST UINT64
*)Buffer
;
261 if (*(Pointer
++) == Value
) {
264 } while (--Length
!= 0);