1 #------------------------------------------------------------------------------
3 # CopyMem() worker for ARM
5 # This file started out as C code that did 64 bit moves if the buffer was
6 # 32-bit aligned, else it does a byte copy. It also does a byte copy for
7 # any trailing bytes. It was updated to do 32-byte copies using stm/ldm.
9 # Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
10 # This program and the accompanying materials
11 # are licensed and made available under the terms and conditions of the BSD License
12 # which accompanies this distribution. The full text of the license may be found at
13 # http://opensource.org/licenses/bsd-license.php
15 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #------------------------------------------------------------------------------
20 #include <AsmMacroIoLib.h>
23 Copy Length bytes from Source to Destination. Overlap is OK.
27 @param Destination Target of copy
28 @param Source Place to copy from
29 @param Length Number of bytes to copy
37 OUT VOID *DestinationBuffer,
38 IN CONST VOID *SourceBuffer,
42 ASM_FUNC(InternalMemCopyMem)
43 stmfd sp!, {r4-r11, lr}
44 // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)
50 memcopy_check_overlapped:
53 bcc memcopy_check_optim_default
54 // If (dest <= source). But with the previous condition -> If (dest == source)
57 // If (source + length < dest)
60 bcc memcopy_check_optim_default
66 b memcopy_check_optim_overlap
68 memcopy_check_optim_default:
69 // Check if we can use an optimized path ((length >= 32) && destination word-aligned && source word-aligned) for the memcopy (optimized path if r0 == 1)
81 memcopy_check_optim_overlap:
82 // r10 = dest_end, r14 = source_end
86 // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)
96 memcopy_overlapped_non_optim:
97 // We read 1 byte from the end of the source buffer
103 // We write 1 byte at the end of the dest buffer
107 bne memcopy_overlapped_non_optim
110 // r10 = dest_end, r14 = source_end
112 // Are we in the optimized case ?
114 beq memcopy_overlapped_non_optim
116 // Optimized Overlapped - Read 32 bytes
122 // If length is less than 32 then disable optim
127 // Optimized Overlapped - Write 32 bytes
131 // while (length != 0)
132 bne memcopy_overlapped
135 memcopy_default_non_optim:
145 // r10 = dest, r14 = source
146 memcopy_default_loop:
148 beq memcopy_default_non_optim
150 // Optimized memcopy - Read 32 Bytes
155 // If length is less than 32 then disable optim
160 // Optimized memcopy - Write 32 Bytes
163 // while (length != 0)
164 bne memcopy_default_loop
168 ldmfd sp!, {r4-r11, pc}