]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BaseMemoryLibStm/Arm/CopyMem.asm
BeagleBoardPkg: remove dependency on ArmPkg/BaseMemoryLibStm
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibStm / Arm / CopyMem.asm
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
7; any trailing bytes. It was updated to do 32-byte copies using stm/ldm.\r
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
1e57a462 40\r
efda1775 41 INCLUDE AsmMacroExport.inc\r
d39eb83c 42\r
efda1775 43 RVCT_ASM_EXPORT InternalMemCopyMem\r
1e57a462 44 stmfd sp!, {r4-r11, lr}\r
45 // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)\r
46 mov r11, r0\r
47 mov r10, r0\r
48 mov r12, r2\r
49 mov r14, r1\r
3402aac7 50\r
643ec0e7 51memcopy_check_overlapped\r
52 cmp r11, r1\r
53 // If (dest < source)\r
54 bcc memcopy_check_optim_default\r
55 // If (dest <= source). But with the previous condition -> If (dest == source)\r
56 bls memcopy_end\r
57\r
58 // If (source + length < dest)\r
59 rsb r3, r1, r11\r
60 cmp r12, r3\r
61 bcc memcopy_check_optim_default\r
62\r
3402aac7 63 // If (length == 0)\r
643ec0e7 64 cmp r12, #0\r
65 beq memcopy_end\r
3402aac7 66\r
643ec0e7 67 b memcopy_check_optim_overlap\r
68\r
69memcopy_check_optim_default\r
70 // 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
71 tst r0, #0xF\r
1e57a462 72 movne r0, #0\r
73 bne memcopy_default\r
74 tst r1, #0xF\r
75 movne r3, #0\r
76 moveq r3, #1\r
77 cmp r2, #31\r
78 movls r0, #0\r
79 andhi r0, r3, #1\r
80 b memcopy_default\r
3402aac7 81\r
1e57a462 82memcopy_check_optim_overlap\r
83 // r10 = dest_end, r14 = source_end\r
84 add r10, r11, r12\r
85 add r14, r12, r1\r
86\r
87 // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)\r
88 cmp r2, #31\r
89 movls r0, #0\r
90 movhi r0, #1\r
91 tst r10, #0xF\r
92 movne r0, #0\r
93 tst r14, #0xF\r
94 movne r0, #0\r
643ec0e7 95 b memcopy_overlapped\r
3402aac7 96\r
643ec0e7 97memcopy_overlapped_non_optim\r
98 // We read 1 byte from the end of the source buffer\r
1e57a462 99 sub r3, r14, #1\r
100 sub r12, r12, #1\r
3402aac7 101 ldrb r3, [r3, #0]\r
1e57a462 102 sub r2, r10, #1\r
103 cmp r12, #0\r
643ec0e7 104 // We write 1 byte at the end of the dest buffer\r
1e57a462 105 sub r10, r10, #1\r
106 sub r14, r14, #1\r
107 strb r3, [r2, #0]\r
643ec0e7 108 bne memcopy_overlapped_non_optim\r
109 b memcopy_end\r
110\r
111// r10 = dest_end, r14 = source_end\r
112memcopy_overlapped\r
113 // Are we in the optimized case ?\r
114 cmp r0, #0\r
115 beq memcopy_overlapped_non_optim\r
3402aac7 116\r
643ec0e7 117 // Optimized Overlapped - Read 32 bytes\r
118 sub r14, r14, #32\r
119 sub r12, r12, #32\r
120 cmp r12, #31\r
121 ldmia r14, {r2-r9}\r
3402aac7 122\r
643ec0e7 123 // If length is less than 32 then disable optim\r
124 movls r0, #0\r
3402aac7 125\r
643ec0e7 126 cmp r12, #0\r
3402aac7
RC
127\r
128 // Optimized Overlapped - Write 32 bytes\r
643ec0e7 129 sub r10, r10, #32\r
130 stmia r10, {r2-r9}\r
3402aac7 131\r
643ec0e7 132 // while (length != 0)\r
133 bne memcopy_overlapped\r
134 b memcopy_end\r
3402aac7 135\r
643ec0e7 136memcopy_default_non_optim\r
137 // Byte copy\r
3402aac7 138 ldrb r3, [r14], #1\r
1e57a462 139 sub r12, r12, #1\r
140 strb r3, [r10], #1\r
3402aac7 141\r
643ec0e7 142memcopy_default\r
1e57a462 143 cmp r12, #0\r
144 beq memcopy_end\r
3402aac7 145\r
643ec0e7 146// r10 = dest, r14 = source\r
147memcopy_default_loop\r
1e57a462 148 cmp r0, #0\r
643ec0e7 149 beq memcopy_default_non_optim\r
3402aac7 150\r
643ec0e7 151 // Optimized memcopy - Read 32 Bytes\r
1e57a462 152 sub r12, r12, #32\r
153 cmp r12, #31\r
154 ldmia r14!, {r2-r9}\r
3402aac7 155\r
643ec0e7 156 // If length is less than 32 then disable optim\r
1e57a462 157 movls r0, #0\r
3402aac7 158\r
1e57a462 159 cmp r12, #0\r
3402aac7 160\r
643ec0e7 161 // Optimized memcopy - Write 32 Bytes\r
1e57a462 162 stmia r10!, {r2-r9}\r
163\r
643ec0e7 164 // while (length != 0)\r
165 bne memcopy_default_loop\r
3402aac7 166\r
643ec0e7 167memcopy_end\r
1e57a462 168 mov r0, r11\r
2ac288f9 169 ldmfd sp!, {r4-r11, pc}\r
3402aac7 170\r
d39eb83c 171 END\r
3402aac7 172\r