1 /* Optimized strcpy implementation for PowerPC64.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
21 /* See strlen.s for comments on how the end-of-string testing works. */
23 /* char * [r3] strcpy (char *dest [r3], const char *src [r4]) */
26 # define FUNC_NAME __stpcpy
28 # define FUNC_NAME strcpy
31 EALIGN (FUNC_NAME, 4, 0)
36 #define rRTN r3 /* pointer to previous word/doubleword in dest */
38 #define rRTN r12 /* pointer to previous word/doubleword in dest */
40 #define rSRC r4 /* pointer to previous word/doubleword in src */
41 #define rWORD r6 /* current word from src */
42 #define rFEFE r7 /* constant 0xfefefeff | 0xfefefefefefefeff */
43 #define r7F7F r8 /* constant 0x7f7f7f7f | 0x7f7f7f7f7f7f7f7f */
44 #define rNEG r9 /* ~(word in s1 | r7F7F) */
45 #define rALT r10 /* alternate word from src */
48 /* Save the dst pointer to use as return value. */
52 clrldi. rTMP, rTMP, 61
53 bne L(check_word_alignment)
55 /* For doubleword aligned memory, operate using doubleword load and stores. */
61 addi rFEFE, rFEFE, -0x101
62 addi r7F7F, r7F7F, 0x7f7f
64 insrdi r7F7F, r7F7F, 32, 0
65 add rFEFE, rFEFE, rTMP
68 L(g0): ldu rALT, 8(rSRC)
76 L(g2): add rTMP, rFEFE, rWORD
77 nor rNEG, r7F7F, rWORD
82 /* We've hit the end of the string. Do the rest byte-by-byte. */
84 #ifdef __LITTLE_ENDIAN__
85 extrdi. rTMP, rALT, 8, 56
88 extrdi. rTMP, rALT, 8, 48
91 extrdi. rTMP, rALT, 8, 40
94 extrdi. rTMP, rALT, 8, 32
97 extrdi. rTMP, rALT, 8, 24
100 extrdi. rTMP, rALT, 8, 16
103 extrdi. rTMP, rALT, 8, 8
106 extrdi rTMP, rALT, 8, 0
109 extrdi. rTMP, rALT, 8, 0
112 extrdi. rTMP, rALT, 8, 8
115 extrdi. rTMP, rALT, 8, 16
118 extrdi. rTMP, rALT, 8, 24
121 extrdi. rTMP, rALT, 8, 32
124 extrdi. rTMP, rALT, 8, 40
127 extrdi. rTMP, rALT, 8, 48
134 L(check_word_alignment):
135 clrldi. rTMP, rTMP, 62
138 /* For word aligned memory, operate using word load and stores. */
144 addi rFEFE, rFEFE, -0x101
145 addi r7F7F, r7F7F, 0x7f7f
148 L(g3): lwzu rALT, 4(rSRC)
150 add rTMP, rFEFE, rALT
151 nor rNEG, r7F7F, rALT
152 and. rTMP, rTMP, rNEG
156 L(g5): add rTMP, rFEFE, rWORD
157 nor rNEG, r7F7F, rWORD
158 and. rTMP, rTMP, rNEG
162 /* We've hit the end of the string. Do the rest byte-by-byte. */
164 #ifdef __LITTLE_ENDIAN__
165 rlwinm. rTMP, rALT, 0, 24, 31
168 rlwinm. rTMP, rALT, 24, 24, 31
171 rlwinm. rTMP, rALT, 16, 24, 31
174 rlwinm rTMP, rALT, 8, 24, 31
177 rlwinm. rTMP, rALT, 8, 24, 31
180 rlwinm. rTMP, rALT, 16, 24, 31
183 rlwinm. rTMP, rALT, 24, 24, 31
190 /* Oh well. In this case, we just do a byte-by-byte copy. */
199 L(u0): lbzu rALT, 1(rSRC)
203 nop /* Let 601 load start of loop. */
208 L(u2): stbu rWORD, 1(rRTN)
210 L(u1): stbu rALT, 1(rRTN)
214 #ifndef USE_AS_STPCPY
215 libc_hidden_builtin_def (strcpy)