1 /* Copyright (c) 2009 Xilinx, Inc. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are
7 1. Redistributions source code must retain the above copyright notice,
8 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.
14 3. Neither the name of Xilinx nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
19 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 <<strcpy>>---copy string
39 char *strcpy(char *<[dst]>, const char *<[src]>);
43 char *strcpy(<[dst]>, <[src]>)
48 <<strcpy>> copies the string pointed to by <[src]>
49 (including the terminating null character) to the array
50 pointed to by <[dst]>.
53 This function returns the initial value of <[dst]>.
58 <<strcpy>> requires no supporting OS subroutines.
70 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
71 #define UNALIGNED(X, Y) \
72 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
74 #if LONG_MAX == 2147483647L
75 #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
77 #if LONG_MAX == 9223372036854775807L
78 /* Nonzero if X (a long int) contains a NULL byte. */
79 #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
81 #error long int is not a 32bit or 64bit type.
86 #error long int is not a 32bit or 64bit byte
90 _DEFUN (strcpy, (dst0, src0),
97 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
100 while (*dst0++ = *src0++)
106 _CONST char *src = src0;
108 _CONST long *aligned_src;
110 /* If SRC or DEST is unaligned, then copy bytes. */
111 if (!UNALIGNED (src, dst))
113 aligned_dst = (long*)dst;
114 aligned_src = (long*)src;
116 /* SRC and DEST are both "long int" aligned, try to do "long int"
118 while (!DETECTNULL(*aligned_src))
120 *aligned_dst++ = *aligned_src++;
123 dst = (char*)aligned_dst;
124 src = (char*)aligned_src;
127 while (*dst++ = *src++)
130 #endif /* not PREFER_SIZE_OVER_SPEED */
135 or r9, r0, r0 /* Index register */ \n\
139 brci ne, r3, try_align_args \n\
140 brci ne, r4, regular_strcpy /* At this point we dont have a choice */ \n\
143 pcmpbf r4, r0, r3 \n\
144 brci ne, r4, cpy_bytes /* If r4 != 0, then null present within string */\n\
152 brcid ne, r4, cpy_bytes \n\
153 addik r9, r9, 1 /* delay slot */\n\
156 or r3, r0, r5 /* Return strcpy result */\n\
159 brci ne, r7, regular_strcpy /* cannot align args */\n\
160 rsubik r10, r3, 4 /* Number of initial bytes to align */\n\
164 brcid eq, r3, end_cpy /* Break if we have seen null character */\n\
165 addik r10, r10, -1 \n\
166 brcid ne, r10, align_loop \n\
172 brcid ne, r3, regular_strcpy \n\
176 or r3, r0, r5 /* Return strcpy result */");
177 #endif /* ! HAVE_HW_PCMP */