]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibOptDxe/Arm/CopyMem.S
MdePkg/BaseMemoryLibOptDxe: replace deprecated uses of IT blocks
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / Arm / CopyMem.S
CommitLineData
a37f6605
AB
1#------------------------------------------------------------------------------\r
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
9# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
10# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
11# This program and the accompanying materials\r
12# are licensed and made available under the terms and conditions of the BSD License\r
13# which accompanies this distribution. The full text of the license may be found at\r
14# http://opensource.org/licenses/bsd-license.php\r
15#\r
16# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18#\r
19#------------------------------------------------------------------------------\r
20\r
21 .text\r
22 .thumb\r
23 .syntax unified\r
24\r
25/**\r
26 Copy Length bytes from Source to Destination. Overlap is OK.\r
27\r
28 This implementation\r
29\r
30 @param Destination Target of copy\r
31 @param Source Place to copy from\r
32 @param Length Number of bytes to copy\r
33\r
34 @return Destination\r
35\r
36\r
37VOID *\r
38EFIAPI\r
39InternalMemCopyMem (\r
40 OUT VOID *DestinationBuffer,\r
41 IN CONST VOID *SourceBuffer,\r
42 IN UINTN Length\r
43 )\r
44**/\r
45ASM_GLOBAL ASM_PFX(InternalMemCopyMem)\r
46ASM_PFX(InternalMemCopyMem):\r
47 push {r4-r11, lr}\r
48 // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)\r
49 mov r11, r0\r
50 mov r10, r0\r
51 mov r12, r2\r
52 mov r14, r1\r
53\r
54 cmp r11, r1\r
55 // If (dest < source)\r
56 bcc memcopy_check_optim_default\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 b memcopy_check_optim_overlap\r
63\r
64memcopy_check_optim_default:\r
65 // 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
66 tst r0, #0xF\r
67 it ne\r
eab26788 68 movne.n r0, #0\r
a37f6605
AB
69 bne memcopy_default\r
70 tst r1, #0xF\r
eab26788
AB
71 it ne\r
72 movne.n r3, #0\r
73 it eq\r
74 moveq.n r3, #1\r
a37f6605 75 cmp r2, #31\r
eab26788
AB
76 it ls\r
77 movls.n r0, #0\r
78 bls memcopy_default\r
79 and r0, r3, #1\r
a37f6605
AB
80 b memcopy_default\r
81\r
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
eab26788
AB
89 it ls\r
90 movls.n r0, #0\r
91 it hi\r
92 movhi.n r0, #1\r
a37f6605
AB
93 tst r10, #0xF\r
94 it ne\r
eab26788 95 movne.n r0, #0\r
a37f6605
AB
96 tst r14, #0xF\r
97 it ne\r
eab26788 98 movne.n r0, #0\r
a37f6605
AB
99 b memcopy_overlapped\r
100\r
101memcopy_overlapped_non_optim:\r
102 // We read 1 byte from the end of the source buffer\r
103 sub r3, r14, #1\r
104 sub r12, r12, #1\r
105 ldrb r3, [r3, #0]\r
106 sub r2, r10, #1\r
107 cmp r12, #0\r
108 // We write 1 byte at the end of the dest buffer\r
109 sub r10, r10, #1\r
110 sub r14, r14, #1\r
111 strb r3, [r2, #0]\r
112 bne memcopy_overlapped_non_optim\r
113 b memcopy_end\r
114\r
115// r10 = dest_end, r14 = source_end\r
116memcopy_overlapped:\r
117 // Are we in the optimized case ?\r
118 cmp r0, #0\r
119 beq memcopy_overlapped_non_optim\r
120\r
121 // Optimized Overlapped - Read 32 bytes\r
122 sub r14, r14, #32\r
123 sub r12, r12, #32\r
124 cmp r12, #31\r
125 ldmia r14, {r2-r9}\r
126\r
127 // If length is less than 32 then disable optim\r
128 it ls\r
eab26788 129 movls.n r0, #0\r
a37f6605
AB
130\r
131 cmp r12, #0\r
132\r
133 // Optimized Overlapped - Write 32 bytes\r
134 sub r10, r10, #32\r
135 stmia r10, {r2-r9}\r
136\r
137 // while (length != 0)\r
138 bne memcopy_overlapped\r
139 b memcopy_end\r
140\r
141memcopy_default_non_optim:\r
142 // Byte copy\r
143 ldrb r3, [r14], #1\r
144 sub r12, r12, #1\r
145 strb r3, [r10], #1\r
146\r
147memcopy_default:\r
148 cmp r12, #0\r
149 beq memcopy_end\r
150\r
151// r10 = dest, r14 = source\r
152memcopy_default_loop:\r
153 cmp r0, #0\r
154 beq memcopy_default_non_optim\r
155\r
156 // Optimized memcopy - Read 32 Bytes\r
157 sub r12, r12, #32\r
158 cmp r12, #31\r
159 ldmia r14!, {r2-r9}\r
160\r
161 // If length is less than 32 then disable optim\r
162 it ls\r
eab26788 163 movls.n r0, #0\r
a37f6605
AB
164\r
165 cmp r12, #0\r
166\r
167 // Optimized memcopy - Write 32 Bytes\r
168 stmia r10!, {r2-r9}\r
169\r
170 // while (length != 0)\r
171 bne memcopy_default_loop\r
172\r
173memcopy_end:\r
174 mov r0, r11\r
175 pop {r4-r11, pc}\r