X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseMemoryLib%2FSetMem.c;h=b6fb811c388a0e1115ae2ef080d24b15f9199712;hp=dee44f61cecbe1e9bc8983aa0c13bbea63f44c41;hb=5ea2bad0d9ab6a2465195badd323313553baa61b;hpb=5d7ceba3579c67a392519f65a96bb02a2d04c2ec diff --git a/MdePkg/Library/BaseMemoryLib/SetMem.c b/MdePkg/Library/BaseMemoryLib/SetMem.c index dee44f61ce..b6fb811c38 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem.c @@ -4,11 +4,14 @@ 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. @@ -23,9 +26,9 @@ /** Set Buffer to Value for Size bytes. - @param Buffer Memory to set. - @param Length 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 @@ -33,7 +36,7 @@ VOID * EFIAPI InternalMemSetMem ( - IN VOID *Buffer, + OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value ) @@ -43,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; + + Pointer64 = (UINT64*)Buffer; + while (Length >= 8) { + *(Pointer64++) = Value64; + Length -= 8; + } - Pointer = (UINT8*)Buffer; - while (Length-- != 0) { - *(Pointer++) = Value; + // 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; }