OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [arm/] [strcpy.c] - Blame information for rev 345

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 * Copyright (c) 2008 ARM Ltd
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
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
15
 *    permission.
16
 *
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.
27
 */
28
 
29
#include "arm_asm.h"
30
#include <_ansi.h>
31
#include <string.h>
32
 
33
#ifdef __thumb2__
34
#define magic1(REG) "#0x01010101"
35
#define magic2(REG) "#0x80808080"
36
#else
37
#define magic1(REG) #REG
38
#define magic2(REG) #REG ", lsl #7"
39
#endif
40
 
41
char* __attribute__((naked))
42
strcpy (char* dst, const char* src)
43
{
44
  asm (
45
#if !(defined(__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED) || \
46
      (defined (__thumb__) && !defined (__thumb2__)))
47
       "optpld  r1\n\t"
48
       "eor     r2, r0, r1\n\t"
49
       "mov     ip, r0\n\t"
50
       "tst     r2, #3\n\t"
51
       "bne     4f\n\t"
52
       "tst     r1, #3\n\t"
53
       "bne     3f\n"
54
  "5:\n\t"
55
#ifndef __thumb2__
56
       "str     r5, [sp, #-4]!\n\t"
57
       "mov     r5, #0x01\n\t"
58
       "orr     r5, r5, r5, lsl #8\n\t"
59
       "orr     r5, r5, r5, lsl #16\n\t"
60
#endif
61
 
62
       "str     r4, [sp, #-4]!\n\t"
63
       "tst     r1, #4\n\t"
64
       "ldr     r3, [r1], #4\n\t"
65
       "beq     2f\n\t"
66
       "sub     r2, r3, "magic1(r5)"\n\t"
67
       "bics    r2, r2, r3\n\t"
68
       "tst     r2, "magic2(r5)"\n\t"
69
       "itt     eq\n\t"
70
       "streq   r3, [ip], #4\n\t"
71
       "ldreq   r3, [r1], #4\n"
72
       "bne     1f\n\t"
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
75
          load stalls.  */
76
       ".p2align 2\n"
77
  "2:\n\t"
78
       "optpld  r1, #8\n\t"
79
       "ldr     r4, [r1], #4\n\t"
80
       "sub     r2, r3, "magic1(r5)"\n\t"
81
       "bics    r2, r2, r3\n\t"
82
       "tst     r2, "magic2(r5)"\n\t"
83
       "sub     r2, r4, "magic1(r5)"\n\t"
84
       "bne     1f\n\t"
85
       "str     r3, [ip], #4\n\t"
86
       "bics    r2, r2, r4\n\t"
87
       "tst     r2, "magic2(r5)"\n\t"
88
       "itt     eq\n\t"
89
       "ldreq   r3, [r1], #4\n\t"
90
       "streq   r4, [ip], #4\n\t"
91
       "beq     2b\n\t"
92
       "mov     r3, r4\n"
93
  "1:\n\t"
94
#ifdef __ARMEB__
95
       "rors    r3, r3, #24\n\t"
96
#endif
97
       "strb    r3, [ip], #1\n\t"
98
       "tst     r3, #0xff\n\t"
99
#ifdef __ARMEL__
100
       "ror     r3, r3, #8\n\t"
101
#endif
102
       "bne     1b\n\t"
103
       "ldr     r4, [sp], #4\n\t"
104
#ifndef __thumb2__
105
       "ldr     r5, [sp], #4\n\t"
106
#endif
107
       "RETURN\n"
108
 
109
       /* Strings have the same offset from word alignment, but it's
110
          not zero.  */
111
  "3:\n\t"
112
       "tst     r1, #1\n\t"
113
       "beq     1f\n\t"
114
       "ldrb    r2, [r1], #1\n\t"
115
       "strb    r2, [ip], #1\n\t"
116
       "cmp     r2, #0\n\t"
117
       "it      eq\n"
118
       "RETURN  eq\n"
119
  "1:\n\t"
120
       "tst     r1, #2\n\t"
121
       "beq     5b\n\t"
122
       "ldrh    r2, [r1], #2\n\t"
123
#ifdef __ARMEB__
124
       "tst     r2, #0xff00\n\t"
125
       "iteet   ne\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"
130
#else
131
       "tst     r2, #0xff\n\t"
132
       "itet    ne\n\t"
133
       "strneh  r2, [ip], #2\n\t"
134
       "streqb  r2, [ip]\n\t"
135
       "tstne   r2, #0xff00\n\t"
136
#endif
137
       "bne     5b\n\t"
138
       "RETURN\n"
139
 
140
       /* src and dst do not have a common word-alignement.  Fall back to
141
          byte copying.  */
142
  "4:\n\t"
143
       "ldrb    r2, [r1], #1\n\t"
144
       "strb    r2, [ip], #1\n\t"
145
       "cmp     r2, #0\n\t"
146
       "bne     4b\n\t"
147
       "RETURN"
148
 
149
#elif !defined (__thumb__) || defined (__thumb2__)
150
       "mov     r3, r0\n\t"
151
  "1:\n\t"
152
       "ldrb    r2, [r1], #1\n\t"
153
       "strb    r2, [r3], #1\n\t"
154
       "cmp     r2, #0\n\t"
155
       "bne     1b\n\t"
156
       "RETURN"
157
#else
158
       "mov     r3, r0\n\t"
159
  "1:\n\t"
160
       "ldrb    r2, [r1]\n\t"
161
       "add     r1, r1, #1\n\t"
162
       "strb    r2, [r3]\n\t"
163
       "add     r3, r3, #1\n\t"
164
       "cmp     r2, #0\n\t"
165
       "bne     1b\n\t"
166
       "RETURN"
167
#endif
168
       );
169
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.