1 /* Optimized strcpy implementation for PowerPC.
2 Copyright (C) 1997-2015 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]) */
28 #define rRTN r3 /* incoming DEST arg preserved as result */
29 #define rSRC r4 /* pointer to previous word in src */
30 #define rDEST r5 /* pointer to previous word in dest */
31 #define rWORD r6 /* current word from src */
32 #define rFEFE r7 /* constant 0xfefefeff (-0x01010101) */
33 #define r7F7F r8 /* constant 0x7f7f7f7f */
34 #define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f) */
35 #define rALT r10 /* alternate word from src */
39 clrlwi. rTMP, rTMP, 30
46 addi rFEFE, rFEFE, -0x101
47 addi r7F7F, r7F7F, 0x7f7f
50 L(g0): lwzu rALT, 4(rSRC)
58 L(g2): add rTMP, rFEFE, rWORD
59 nor rNEG, r7F7F, rWORD
64 /* We've hit the end of the string. Do the rest byte-by-byte. */
66 #ifdef __LITTLE_ENDIAN__
67 rlwinm. rTMP, rALT, 0, 24, 31
70 rlwinm. rTMP, rALT, 24, 24, 31
73 rlwinm. rTMP, rALT, 16, 24, 31
76 rlwinm rTMP, rALT, 8, 24, 31
80 rlwinm. rTMP, rALT, 8, 24, 31
83 rlwinm. rTMP, rALT, 16, 24, 31
86 rlwinm. rTMP, rALT, 24, 24, 31
93 /* Oh well. In this case, we just do a byte-by-byte copy. */
102 L(u0): lbzu rALT, 1(rSRC)
106 nop /* Let 601 load start of loop. */
111 L(u2): stb rWORD, 1(rDEST)
113 L(u1): stb rALT, 1(rDEST)
117 libc_hidden_builtin_def (strcpy)