]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BaseMemoryLibStm/Arm/CopyMem.S
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibStm / Arm / CopyMem.S
CommitLineData
3402aac7 1#------------------------------------------------------------------------------\r
d39eb83c 2#\r
3# CopyMem() worker for ARM\r
4#\r
5# This file started out as C code that did 64 bit moves if the buffer was\r
6# 32-bit aligned, else it does a byte copy. It also does a byte copy for\r
3402aac7 7# any trailing bytes. It was updated to do 32-byte copies using stm/ldm.\r
d39eb83c 8#\r
d6ebcab7
HT
9# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
10# This program and the accompanying materials\r
d39eb83c 11# are licensed and made available under the terms and conditions of the BSD License\r
12# which accompanies this distribution. The full text of the license may be found at\r
13# http://opensource.org/licenses/bsd-license.php\r
14#\r
15# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17#\r
18#------------------------------------------------------------------------------\r
19\r
20/**\r
21 Copy Length bytes from Source to Destination. Overlap is OK.\r
22\r
3402aac7 23 This implementation\r
d39eb83c 24\r
25 @param Destination Target of copy\r
26 @param Source Place to copy from\r
27 @param Length Number of bytes to copy\r
28\r
29 @return Destination\r
30\r
31\r
32VOID *\r
33EFIAPI\r
34InternalMemCopyMem (\r
35 OUT VOID *DestinationBuffer,\r
36 IN CONST VOID *SourceBuffer,\r
37 IN UINTN Length\r
38 )\r
39**/\r
40.text\r
41.align 2\r
1bfda055 42GCC_ASM_EXPORT(InternalMemCopyMem)\r
d39eb83c 43\r
44ASM_PFX(InternalMemCopyMem):\r
2ac288f9 45 stmfd sp!, {r4-r11, lr}\r
643ec0e7 46 // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)\r
2ac288f9 47 mov r11, r0\r
48 mov r10, r0\r
643ec0e7 49 mov r12, r2\r
50 mov r14, r1\r
3402aac7 51\r
643ec0e7 52memcopy_check_overlapped:\r
53 cmp r11, r1\r
54 // If (dest < source)\r
55 bcc memcopy_check_optim_default\r
56 // If (dest <= source). But with the previous condition -> If (dest == source)\r
57 bls memcopy_end\r
58\r
59 // If (source + length < dest)\r
60 rsb r3, r1, r11\r
61 cmp r12, r3\r
62 bcc memcopy_check_optim_default\r
63\r
3402aac7 64 // If (length == 0)\r
643ec0e7 65 cmp r12, #0\r
66 beq memcopy_end\r
3402aac7 67\r
643ec0e7 68 b memcopy_check_optim_overlap\r
69\r
70memcopy_check_optim_default:\r
71 // Check if we can use an optimized path ((length >= 32) && destination word-aligned && source word-aligned) for the memcopy (optimized path if r0 == 1)\r
72 tst r0, #0xF\r
2ac288f9 73 movne r0, #0\r
643ec0e7 74 bne memcopy_default\r
75 tst r1, #0xF\r
2ac288f9 76 movne r3, #0\r
77 moveq r3, #1\r
78 cmp r2, #31\r
79 movls r0, #0\r
80 andhi r0, r3, #1\r
643ec0e7 81 b memcopy_default\r
3402aac7 82\r
643ec0e7 83memcopy_check_optim_overlap:\r
84 // r10 = dest_end, r14 = source_end\r
85 add r10, r11, r12\r
86 add r14, r12, r1\r
87\r
88 // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)\r
89 cmp r2, #31\r
2ac288f9 90 movls r0, #0\r
643ec0e7 91 movhi r0, #1\r
92 tst r10, #0xF\r
93 movne r0, #0\r
94 tst r14, #0xF\r
95 movne r0, #0\r
96 b memcopy_overlapped\r
3402aac7 97\r
643ec0e7 98memcopy_overlapped_non_optim:\r
99 // We read 1 byte from the end of the source buffer\r
100 sub r3, r14, #1\r
101 sub r12, r12, #1\r
3402aac7 102 ldrb r3, [r3, #0]\r
2ac288f9 103 sub r2, r10, #1\r
643ec0e7 104 cmp r12, #0\r
105 // We write 1 byte at the end of the dest buffer\r
2ac288f9 106 sub r10, r10, #1\r
643ec0e7 107 sub r14, r14, #1\r
2ac288f9 108 strb r3, [r2, #0]\r
643ec0e7 109 bne memcopy_overlapped_non_optim\r
110 b memcopy_end\r
111\r
112// r10 = dest_end, r14 = source_end\r
113memcopy_overlapped:\r
114 // Are we in the optimized case ?\r
115 cmp r0, #0\r
116 beq memcopy_overlapped_non_optim\r
3402aac7 117\r
643ec0e7 118 // Optimized Overlapped - Read 32 bytes\r
119 sub r14, r14, #32\r
120 sub r12, r12, #32\r
121 cmp r12, #31\r
122 ldmia r14, {r2-r9}\r
3402aac7 123\r
643ec0e7 124 // If length is less than 32 then disable optim\r
125 movls r0, #0\r
3402aac7 126\r
643ec0e7 127 cmp r12, #0\r
3402aac7
RC
128\r
129 // Optimized Overlapped - Write 32 bytes\r
643ec0e7 130 sub r10, r10, #32\r
131 stmia r10, {r2-r9}\r
3402aac7 132\r
643ec0e7 133 // while (length != 0)\r
134 bne memcopy_overlapped\r
135 b memcopy_end\r
3402aac7 136\r
643ec0e7 137memcopy_default_non_optim:\r
138 // Byte copy\r
3402aac7 139 ldrb r3, [r14], #1\r
643ec0e7 140 sub r12, r12, #1\r
2ac288f9 141 strb r3, [r10], #1\r
3402aac7 142\r
643ec0e7 143memcopy_default:\r
144 cmp r12, #0\r
145 beq memcopy_end\r
3402aac7 146\r
643ec0e7 147// r10 = dest, r14 = source\r
148memcopy_default_loop:\r
2ac288f9 149 cmp r0, #0\r
643ec0e7 150 beq memcopy_default_non_optim\r
3402aac7 151\r
643ec0e7 152 // Optimized memcopy - Read 32 Bytes\r
153 sub r12, r12, #32\r
154 cmp r12, #31\r
155 ldmia r14!, {r2-r9}\r
3402aac7 156\r
643ec0e7 157 // If length is less than 32 then disable optim\r
2ac288f9 158 movls r0, #0\r
3402aac7 159\r
643ec0e7 160 cmp r12, #0\r
3402aac7 161\r
643ec0e7 162 // Optimized memcopy - Write 32 Bytes\r
2ac288f9 163 stmia r10!, {r2-r9}\r
643ec0e7 164\r
165 // while (length != 0)\r
166 bne memcopy_default_loop\r
3402aac7 167\r
643ec0e7 168memcopy_end:\r
2ac288f9 169 mov r0, r11\r
170 ldmfd sp!, {r4-r11, pc}\r
3402aac7 171\r