]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/net/lwip/lwip-sys/arch/memcpy.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / net / lwip / lwip-sys / arch / memcpy.c
1 /* Copyright (C) 2013 - Adam Green (https://github.com/adamgreen)
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 */
15 #if defined(TOOLCHAIN_GCC) && defined(__thumb2__)
16
17 #include <stdio.h>
18
19
20 /* This is a hand written Thumb-2 assembly language version of the
21 standard C memcpy() function that can be used by the lwIP networking
22 stack to improve its performance. It copies 4 bytes at a time and
23 unrolls the loop to perform 4 of these copies per loop iteration.
24 */
25 __attribute__((naked)) void thumb2_memcpy(void* pDest, const void* pSource, size_t length)
26 {
27 __asm (
28 ".syntax unified\n"
29 ".thumb\n"
30
31 // Copy 16 bytes at a time first.
32 " lsrs r3, r2, #4\n"
33 " beq.n 2$\n"
34 "1$: ldr r12, [r1], #4\n"
35 " str r12, [r0], #4\n"
36 " ldr r12, [r1], #4\n"
37 " str r12, [r0], #4\n"
38 " ldr r12, [r1], #4\n"
39 " str r12, [r0], #4\n"
40 " ldr r12, [r1], #4\n"
41 " str r12, [r0], #4\n"
42 " subs r3, #1\n"
43 " bne 1$\n"
44
45 // Copy byte by byte for what is left.
46 "2$:\n"
47 " ands r3, r2, #0xf\n"
48 " beq.n 4$\n"
49 "3$: ldrb r12, [r1], #1\n"
50 " strb r12, [r0], #1\n"
51 " subs r3, #1\n"
52 " bne 3$\n"
53
54 // Return to caller.
55 "4$: bx lr\n"
56 );
57 }
58
59 #endif
Imprint / Impressum