X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseMemoryLib%2FSetMem.c;h=b6fb811c388a0e1115ae2ef080d24b15f9199712;hp=0ad994c104ebd41f8ba8c857129847c5893fd0d3;hb=5ea2bad0d9ab6a2465195badd323313553baa61b;hpb=f734a10ab104f1072f94cab66a5489e0fd8fce8a diff --git a/MdePkg/Library/BaseMemoryLib/SetMem.c b/MdePkg/Library/BaseMemoryLib/SetMem.c index 0ad994c104..b6fb811c38 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem.c @@ -4,22 +4,21 @@ build for a particular platform easily if an optimized version is desired. - Copyright (c) 2006, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + http://opensource.org/licenses/bsd-license.php. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - Module Name: SetMem.c - **/ -// -// Include common header file for this module. -// + #include "MemLibInternals.h" @@ -27,9 +26,9 @@ /** Set Buffer to Value for Size bytes. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. + @param Buffer The memory to set. + @param Length The number of bytes to set. + @param Value The value of the set operation. @return Buffer @@ -37,8 +36,8 @@ VOID * EFIAPI InternalMemSetMem ( - IN VOID *Buffer, - IN UINTN Size, + OUT VOID *Buffer, + IN UINTN Length, IN UINT8 Value ) { @@ -47,11 +46,42 @@ InternalMemSetMem ( // volatile to prevent the optimizer from replacing this function with // the intrinsic memset() // - volatile UINT8 *Pointer; + volatile UINT8 *Pointer8; + volatile UINT32 *Pointer32; + volatile UINT64 *Pointer64; + UINT32 Value32; + UINT64 Value64; + + if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) { + // Generate the 64bit value + Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value; + Value64 = LShiftU64 (Value32, 32) | Value32; - Pointer = (UINT8*)Buffer; - while (Size-- != 0) { - *(Pointer++) = Value; + Pointer64 = (UINT64*)Buffer; + while (Length >= 8) { + *(Pointer64++) = Value64; + Length -= 8; + } + + // Finish with bytes if needed + Pointer8 = (UINT8*)Pointer64; + } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) { + // Generate the 32bit value + Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value; + + Pointer32 = (UINT32*)Buffer; + while (Length >= 4) { + *(Pointer32++) = Value32; + Length -= 4; + } + + // Finish with bytes if needed + Pointer8 = (UINT8*)Pointer32; + } else { + Pointer8 = (UINT8*)Buffer; + } + while (Length-- > 0) { + *(Pointer8++) = Value; } return Buffer; }