X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseMemoryLib%2FSetMem.c;h=c079d75a18692395679f992233da78921dcf80e0;hb=HEAD;hp=90780deb51baa2c019aae6b3655329664b630391;hpb=d5b86e43cf23787da85fcf862807c1f6714bfac2;p=mirror_edk2.git diff --git a/MdePkg/Library/BaseMemoryLib/SetMem.c b/MdePkg/Library/BaseMemoryLib/SetMem.c index 90780deb51..c079d75a18 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem.c @@ -4,30 +4,22 @@ 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 - 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 + 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.
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ -// -// Include common header file for this module. -// - - #include "MemLibInternals.h" /** 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 @@ -35,9 +27,9 @@ VOID * EFIAPI InternalMemSetMem ( - IN VOID *Buffer, - IN UINTN Size, - IN UINT8 Value + OUT VOID *Buffer, + IN UINTN Length, + IN UINT8 Value ) { // @@ -45,11 +37,44 @@ 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; + + 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; - Pointer = (UINT8*)Buffer; - while (Size-- != 0) { - *(Pointer++) = 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; }