]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseMemoryLib/SetMem.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLib / SetMem.c
index 9d7b0ec55ea7acd604b2f7fb8332428471908ebf..d42abb12873e41aeb9a818a7b9cb2c5cd570a009 100644 (file)
@@ -4,14 +4,11 @@
   build for a particular platform easily if an optimized version\r
   is desired.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -23,9 +20,9 @@
 /**\r
   Set Buffer to Value for Size bytes.\r
 \r
-  @param  Buffer   Memory to set.\r
-  @param  Length   Number of bytes to set\r
-  @param  Value    Value of the set operation.\r
+  @param  Buffer   The memory to set.\r
+  @param  Length   The number of bytes to set.\r
+  @param  Value    The value of the set operation.\r
 \r
   @return Buffer\r
 \r
@@ -33,7 +30,7 @@
 VOID *\r
 EFIAPI\r
 InternalMemSetMem (\r
-  IN      VOID                      *Buffer,\r
+  OUT     VOID                      *Buffer,\r
   IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
@@ -43,11 +40,42 @@ InternalMemSetMem (
   // volatile to prevent the optimizer from replacing this function with\r
   // the intrinsic memset()\r
   //\r
-  volatile UINT8                    *Pointer;\r
+  volatile UINT8                    *Pointer8;\r
+  volatile UINT32                   *Pointer32;\r
+  volatile UINT64                   *Pointer64;\r
+  UINT32                            Value32;\r
+  UINT64                            Value64;\r
 \r
-  Pointer = (UINT8*)Buffer;\r
-  while (Length-- != 0) {\r
-    *(Pointer++) = Value;\r
+  if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {\r
+    // Generate the 64bit value\r
+    Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r
+    Value64 = LShiftU64 (Value32, 32) | Value32;\r
+\r
+    Pointer64 = (UINT64*)Buffer;\r
+    while (Length >= 8) {\r
+      *(Pointer64++) = Value64;\r
+      Length -= 8;\r
+    }\r
+\r
+    // Finish with bytes if needed\r
+    Pointer8 = (UINT8*)Pointer64;\r
+  } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {\r
+    // Generate the 32bit value\r
+    Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r
+\r
+    Pointer32 = (UINT32*)Buffer;\r
+    while (Length >= 4) {\r
+      *(Pointer32++) = Value32;\r
+      Length -= 4;\r
+    }\r
+\r
+    // Finish with bytes if needed\r
+    Pointer8 = (UINT8*)Pointer32;\r
+  } else {\r
+    Pointer8 = (UINT8*)Buffer;\r
+  }\r
+  while (Length-- > 0) {\r
+    *(Pointer8++) = Value;\r
   }\r
   return Buffer;\r
 }\r