2
* Copyright (c) 2008 ARM Ltd
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. The name of the company may not be used to endorse or promote
14
* products derived from this software without specific prior written
17
* THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
#define magic1(REG) "#0x01010101"
35
#define magic2(REG) "#0x80808080"
37
#define magic1(REG) #REG
38
#define magic2(REG) #REG ", lsl #7"
41
char* __attribute__((naked))
42
strcpy (char* dst, const char* src)
45
#if !(defined(__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED) || \
46
(defined (__thumb__) && !defined (__thumb2__)))
56
"str r5, [sp, #-4]!\n\t"
58
"orr r5, r5, r5, lsl #8\n\t"
59
"orr r5, r5, r5, lsl #16\n\t"
62
"str r4, [sp, #-4]!\n\t"
64
"ldr r3, [r1], #4\n\t"
66
"sub r2, r3, "magic1(r5)"\n\t"
68
"tst r2, "magic2(r5)"\n\t"
70
"streq r3, [ip], #4\n\t"
71
"ldreq r3, [r1], #4\n"
73
/* Inner loop. We now know that r1 is 64-bit aligned, so we
74
can safely fetch up to two words. This allows us to avoid
79
"ldr r4, [r1], #4\n\t"
80
"sub r2, r3, "magic1(r5)"\n\t"
82
"tst r2, "magic2(r5)"\n\t"
83
"sub r2, r4, "magic1(r5)"\n\t"
85
"str r3, [ip], #4\n\t"
87
"tst r2, "magic2(r5)"\n\t"
89
"ldreq r3, [r1], #4\n\t"
90
"streq r4, [ip], #4\n\t"
95
"rors r3, r3, #24\n\t"
97
"strb r3, [ip], #1\n\t"
103
"ldr r4, [sp], #4\n\t"
105
"ldr r5, [sp], #4\n\t"
109
/* Strings have the same offset from word alignment, but it's
114
"ldrb r2, [r1], #1\n\t"
115
"strb r2, [ip], #1\n\t"
122
"ldrh r2, [r1], #2\n\t"
124
"tst r2, #0xff00\n\t"
126
"strneh r2, [ip], #2\n\t"
127
"lsreq r2, r2, #8\n\t"
128
"streqb r2, [ip]\n\t"
129
"tstne r2, #0xff\n\t"
133
"strneh r2, [ip], #2\n\t"
134
"streqb r2, [ip]\n\t"
135
"tstne r2, #0xff00\n\t"
140
/* src and dst do not have a common word-alignement. Fall back to
143
"ldrb r2, [r1], #1\n\t"
144
"strb r2, [ip], #1\n\t"
149
#elif !defined (__thumb__) || defined (__thumb2__)
152
"ldrb r2, [r1], #1\n\t"
153
"strb r2, [r3], #1\n\t"