]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/strcpy.S
Update.
[thirdparty/glibc.git] / sysdeps / powerpc / strcpy.S
CommitLineData
650425ce 1/* Optimized strcpy implementation for PowerPC.
4e141d64 2 Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
650425ce
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <sysdep.h>
21
22/* See strlen.s for comments on how the end-of-string testing works. */
23
650425ce
UD
24/* char * [r3] strcpy (char *dest [r3], const char *src [r4]) */
25
1d280d9f 26EALIGN(strcpy, 4, 0)
650425ce 27
1d280d9f
GM
28#define rTMP r0
29#define rRTN r3 /* incoming DEST arg preserved as result */
30#define rSRC r4 /* pointer to previous word in src */
31#define rDEST r5 /* pointer to previous word in dest */
32#define rWORD r6 /* current word from src */
33#define rFEFE r7 /* constant 0xfefefeff (-0x01010101) */
34#define r7F7F r8 /* constant 0x7f7f7f7f */
35#define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f) */
36#define rALT r10 /* alternate word from src */
650425ce 37
1d280d9f
GM
38 or rTMP, rSRC, rRTN
39 clrlwi. rTMP, rTMP, 30
40 addi rDEST, rRTN, -4
41 bne L(unaligned)
650425ce 42
1d280d9f
GM
43 lis rFEFE, -0x101
44 lis r7F7F, 0x7f7f
45 lwz rWORD, 0(rSRC)
46 addi rFEFE, rFEFE, -0x101
47 addi r7F7F, r7F7F, 0x7f7f
48 b L(g2)
650425ce 49
1d280d9f
GM
50L(g0): lwzu rALT, 4(rSRC)
51 stwu rWORD, 4(rDEST)
52 add rTMP, rFEFE, rALT
53 nor rNEG, r7F7F, rALT
54 and. rTMP, rTMP, rNEG
55 bne- L(g1)
56 lwzu rWORD, 4(rSRC)
57 stwu rALT, 4(rDEST)
58L(g2): add rTMP, rFEFE, rWORD
59 nor rNEG, r7F7F, rWORD
60 and. rTMP, rTMP, rNEG
61 beq+ L(g0)
62
63 mr rALT, rWORD
650425ce 64/* We've hit the end of the string. Do the rest byte-by-byte. */
1d280d9f
GM
65L(g1): rlwinm. rTMP, rALT, 8, 24, 31
66 stb rTMP, 4(rDEST)
650425ce 67 beqlr-
1d280d9f
GM
68 rlwinm. rTMP, rALT, 16, 24, 31
69 stb rTMP, 5(rDEST)
650425ce 70 beqlr-
1d280d9f
GM
71 rlwinm. rTMP, rALT, 24, 24, 31
72 stb rTMP, 6(rDEST)
650425ce 73 beqlr-
1d280d9f 74 stb rALT, 7(rDEST)
650425ce
UD
75 blr
76
77/* Oh well. In this case, we just do a byte-by-byte copy. */
78 .align 4
79 nop
80L(unaligned):
1d280d9f
GM
81 lbz rWORD, 0(rSRC)
82 addi rDEST, rRTN, -1
83 cmpwi rWORD, 0
84 beq- L(u2)
650425ce 85
1d280d9f
GM
86L(u0): lbzu rALT, 1(rSRC)
87 stbu rWORD, 1(rDEST)
88 cmpwi rALT, 0
89 beq- L(u1)
650425ce 90 nop /* Let 601 load start of loop. */
1d280d9f
GM
91 lbzu rWORD, 1(rSRC)
92 stbu rALT, 1(rDEST)
93 cmpwi rWORD, 0
94 bne+ L(u0)
95L(u2): stb rWORD, 1(rDEST)
650425ce 96 blr
1d280d9f 97L(u1): stb rALT, 1(rDEST)
650425ce
UD
98 blr
99
100END(strcpy)