e1f414b6 |
1 | /** @file\r |
d531bfee |
2 | Implementation of the InternalMemCopyMem routine. This function is broken\r |
3 | out into its own source file so that it can be excluded from a build for a\r |
4 | particular platform easily if an optimized version is desired.\r |
e1f414b6 |
5 | \r |
d531bfee |
6 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
e1f414b6 |
7 | All rights reserved. This program and the accompanying materials\r |
8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r |
10 | http://opensource.org/licenses/bsd-license.php\r |
11 | \r |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
14 | \r |
e1f414b6 |
15 | **/\r |
16 | \r |
1efcc4ae |
17 | \r |
f734a10a |
18 | \r |
e1f414b6 |
19 | \r |
20 | #include "MemLibInternals.h"\r |
21 | \r |
22 | /**\r |
23 | Copy Length bytes from Source to Destination.\r |
24 | \r |
25 | @param Destination Target of copy\r |
d531bfee |
26 | @param Source Place to copy from\r |
27 | @param Length Number of bytes to copy\r |
e1f414b6 |
28 | \r |
29 | @return Destination\r |
30 | \r |
31 | **/\r |
32 | VOID *\r |
33 | EFIAPI\r |
34 | InternalMemCopyMem (\r |
35 | OUT VOID *Destination,\r |
36 | IN CONST VOID *Source,\r |
37 | IN UINTN Length\r |
38 | )\r |
39 | {\r |
40 | //\r |
41 | // Declare the local variables that actually move the data elements as\r |
42 | // volatile to prevent the optimizer from replacing this function with\r |
43 | // the intrinsic memcpy()\r |
44 | //\r |
45 | volatile UINT8 *Destination8;\r |
46 | CONST UINT8 *Source8;\r |
47 | \r |
48 | if (Source > Destination) {\r |
49 | Destination8 = (UINT8*)Destination;\r |
50 | Source8 = (CONST UINT8*)Source;\r |
51 | while (Length-- != 0) {\r |
52 | *(Destination8++) = *(Source8++);\r |
53 | }\r |
54 | } else if (Source < Destination) {\r |
55 | Destination8 = (UINT8*)Destination + Length;\r |
56 | Source8 = (CONST UINT8*)Source + Length;\r |
57 | while (Length-- != 0) {\r |
58 | *(--Destination8) = *(--Source8);\r |
59 | }\r |
60 | }\r |
61 | return Destination;\r |
62 | }\r |