]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/BaseMemoryLibVstm/CopyMem.c
Add some ldm/vldm optimized CopyMem routines. Add performance macros to BDS
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibVstm / CopyMem.c
diff --git a/ArmPkg/Library/BaseMemoryLibVstm/CopyMem.c b/ArmPkg/Library/BaseMemoryLibVstm/CopyMem.c
new file mode 100755 (executable)
index 0000000..aa2ffea
--- /dev/null
@@ -0,0 +1,62 @@
+/** @file\r
+  Implementation of the InternalMemCopyMem routine. This function is broken\r
+  out into its own source file so that it can be excluded from a build for a\r
+  particular platform easily if an optimized version is desired.\r
+\r
+  Copyright (c) 2006 - 2008, 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
+\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
+\r
+**/\r
+\r
+\r
+\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Copy Length bytes from Source to Destination.\r
+\r
+  @param  DestinationBuffer Target of copy\r
+  @param  SourceBuffer      Place to copy from\r
+  @param  Length            Number of bytes to copy\r
+\r
+  @return Destination\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+InternalMemCopyMem (\r
+  OUT     VOID                      *DestinationBuffer,\r
+  IN      CONST VOID                *SourceBuffer,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  //\r
+  // Declare the local variables that actually move the data elements as\r
+  // volatile to prevent the optimizer from replacing this function with\r
+  // the intrinsic memcpy()\r
+  //\r
+  volatile UINT8                    *Destination8;\r
+  CONST UINT8                       *Source8;\r
+\r
+  if (SourceBuffer > DestinationBuffer) {\r
+    Destination8 = (UINT8*)DestinationBuffer;\r
+    Source8 = (CONST UINT8*)SourceBuffer;\r
+    while (Length-- != 0) {\r
+      *(Destination8++) = *(Source8++);\r
+    }\r
+  } else if (SourceBuffer < DestinationBuffer) {\r
+    Destination8 = (UINT8*)DestinationBuffer + Length;\r
+    Source8 = (CONST UINT8*)SourceBuffer + Length;\r
+    while (Length-- != 0) {\r
+      *(--Destination8) = *(--Source8);\r
+    }\r
+  }\r
+  return DestinationBuffer;\r
+}\r