2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc64 / strcpy.S
blobe9e9fc78cd977b6113c4c70c8e994daa05c4a8e3
1 /* Optimized strcpy implementation for PowerPC64.
2    Copyright (C) 1997, 1999, 2000, 2002, 2003 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <bp-sym.h>
22 #include <bp-asm.h>
24 /* See strlen.s for comments on how the end-of-string testing works.  */
26 /* char * [r3] strcpy (char *dest [r3], const char *src [r4])  */
28 EALIGN (BP_SYM (strcpy), 4, 0)
29         CALL_MCOUNT 2
31 #define rTMP    r0
32 #define rRTN    r3      /* incoming DEST arg preserved as result */
33 /* Note.  The Bounded pointer support in this code is broken.  This code
34    was inherited from PPC32 and and that support was never completed.  
35    Current PPC gcc does not support -fbounds-check or -fbounded-pointers.
36    These artifacts are left in the code as a reminder in case we need
37    bounded pointer support in the future.  */
38 #if __BOUNDED_POINTERS__
39 # define rDEST  r4      /* pointer to previous word in dest */
40 # define rSRC   r5      /* pointer to previous word in src */
41 # define rLOW   r11
42 # define rHIGH  r12
43 #else
44 # define rSRC   r4      /* pointer to previous word in src */
45 # define rDEST  r5      /* pointer to previous word in dest */
46 #endif
47 #define rWORD   r6      /* current word from src */
48 #define rFEFE   r7      /* constant 0xfefefefefefefeff (-0x0101010101010101) */
49 #define r7F7F   r8      /* constant 0x7f7f7f7f7f7f7f7f */
50 #define rNEG    r9      /* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
51 #define rALT    r10     /* alternate word from src */
53         CHECK_BOUNDS_LOW (rSRC, rLOW, rHIGH)
54         CHECK_BOUNDS_LOW (rDEST, rLOW, rHIGH)
55         STORE_RETURN_BOUNDS (rLOW, rHIGH)
57         dcbt    0,rSRC
58         or      rTMP, rSRC, rRTN
59         clrldi. rTMP, rTMP, 61
60 #if __BOUNDED_POINTERS__
61         addi    rDEST, rDEST, -8
62 #else
63         addi    rDEST, rRTN, -8
64 #endif
65         dcbtst  0,rRTN
66         bne     L(unaligned)
68         lis     rFEFE, -0x101
69         lis     r7F7F, 0x7f7f
70         ld      rWORD, 0(rSRC)
71         addi    rFEFE, rFEFE, -0x101
72         addi    r7F7F, r7F7F, 0x7f7f
73         sldi    rTMP, rFEFE, 32
74         insrdi  r7F7F, r7F7F, 32, 0
75         add     rFEFE, rFEFE, rTMP
76         b       L(g2)
78 L(g0):  ldu     rALT, 8(rSRC)
79         stdu    rWORD, 8(rDEST)
80         add     rTMP, rFEFE, rALT
81         nor     rNEG, r7F7F, rALT
82         and.    rTMP, rTMP, rNEG
83         bne-    L(g1)
84         ldu     rWORD, 8(rSRC)
85         stdu    rALT, 8(rDEST)
86 L(g2):  add     rTMP, rFEFE, rWORD
87         nor     rNEG, r7F7F, rWORD
88         and.    rTMP, rTMP, rNEG
89         beq+    L(g0)
91         mr      rALT, rWORD
92 /* We've hit the end of the string.  Do the rest byte-by-byte.  */
93 L(g1):
94         extrdi. rTMP, rALT, 8, 0
95         stb     rTMP, 8(rDEST)
96         beqlr-
97         extrdi. rTMP, rALT, 8, 8
98         stb     rTMP, 9(rDEST)
99         beqlr-
100         extrdi. rTMP, rALT, 8, 16
101         stb     rTMP, 10(rDEST)
102         beqlr-
103         extrdi. rTMP, rALT, 8, 24
104         stb     rTMP, 11(rDEST)
105         beqlr-
106         extrdi. rTMP, rALT, 8, 32
107         stb     rTMP, 12(rDEST)
108         beqlr-
109         extrdi. rTMP, rALT, 8, 40
110         stb     rTMP, 13(rDEST)
111         beqlr-
112         extrdi. rTMP, rALT, 8, 48
113         stb     rTMP, 14(rDEST)
114         beqlr-
115         stb     rALT, 15(rDEST)
116         /* GKM FIXME: check high bound.  */
117         blr
119 /* Oh well.  In this case, we just do a byte-by-byte copy.  */
120         .align 4
121         nop
122 L(unaligned):
123         lbz     rWORD, 0(rSRC)
124         addi    rDEST, rRTN, -1
125         cmpwi   rWORD, 0
126         beq-    L(u2)
128 L(u0):  lbzu    rALT, 1(rSRC)
129         stbu    rWORD, 1(rDEST)
130         cmpwi   rALT, 0
131         beq-    L(u1)
132         nop             /* Let 601 load start of loop.  */
133         lbzu    rWORD, 1(rSRC)
134         stbu    rALT, 1(rDEST)
135         cmpwi   rWORD, 0
136         bne+    L(u0)
137 L(u2):  stb     rWORD, 1(rDEST)
138         /* GKM FIXME: check high bound.  */
139         blr
140 L(u1):  stb     rALT, 1(rDEST)
141         /* GKM FIXME: check high bound.  */
142         blr
144 END (BP_SYM (strcpy))
145 libc_hidden_builtin_def (strcpy)