Add Changelog ...
[glibc.git] / sysdeps / powerpc / powerpc32 / 405 / strcpy.S
blob8e6c396e5d3b0e7c728ec55d6ffa8e885770f7ec
1 /* Optimized strcpy implementation for PowerPC476.
2    Copyright (C) 2010 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/>.  */
19 #include <sysdep.h>
20 #include <bp-sym.h>
21 #include <bp-asm.h>
23 /* strcpy
25        Register Use
26        r3:destination and return address
27        r4:source address
28        r10:temp destination address
30        Implementation description
31        Loop by checking 2 words at a time, with dlmzb. Check if there is a null
32        in the 2 words. If there is a null jump to end checking to determine
33        where in the last 8 bytes it is. Copy the appropriate bytes of the last
34        8 according to the null position. */
36 EALIGN (BP_SYM (strcpy), 5, 0)
37        neg     r7,r4
38        subi    r4,r4,1
39        clrlwi. r8,r7,29
40        subi    r10,r3,1
41        beq     L(pre_word8_loop)
42        mtctr   r8
44 L(loop):
45        lbzu    r5,0x01(r4)
46        cmpi    cr5,r5,0x0
47        stbu    r5,0x01(r10)
48        beq     cr5,L(end_strcpy)
49        bdnz    L(loop)
51 L(pre_word8_loop):
52        subi    r4,r4,3
53        subi    r10,r10,3
55 L(word8_loop):
56        lwzu    r5,0x04(r4)
57        lwzu    r6,0x04(r4)
58        dlmzb.  r11,r5,r6
59        bne     L(byte_copy)
60        stwu    r5,0x04(r10)
61        stwu    r6,0x04(r10)
62        lwzu    r5,0x04(r4)
63        lwzu    r6,0x04(r4)
64        dlmzb.  r11,r5,r6
65        bne     L(byte_copy)
66        stwu    r5,0x04(r10)
67        stwu    r6,0x04(r10)
68        lwzu    r5,0x04(r4)
69        lwzu    r6,0x04(r4)
70        dlmzb.  r11,r5,r6
71        bne     L(byte_copy)
72        stwu    r5,0x04(r10)
73        stwu    r6,0x04(r10)
74        lwzu    r5,0x04(r4)
75        lwzu    r6,0x04(r4)
76        dlmzb.  r11,r5,r6
77        bne     L(byte_copy)
78        stwu    r5,0x04(r10)
79        stwu    r6,0x04(r10)
80        b       L(word8_loop)
82 L(last_bytes_copy):
83        stwu    r5,0x04(r10)
84        subi    r11,r11,4
85        mtctr   r11
86        addi    r10,r10,3
87        subi    r4,r4,1
89 L(last_bytes_copy_loop):
90        lbzu    r5,0x01(r4)
91        stbu    r5,0x01(r10)
92        bdnz    L(last_bytes_copy_loop)
93        blr
95 L(byte_copy):
96        blt     L(last_bytes_copy)
97        mtctr   r11
98        addi    r10,r10,3
99        subi    r4,r4,5
101 L(last_bytes_copy_loop2):
102        lbzu    r5,0x01(r4)
103        stbu    r5,0x01(r10)
104        bdnz    L(last_bytes_copy_loop2)
106 L(end_strcpy):
107        blr
108 END (BP_SYM (strcpy))
109 libc_hidden_builtin_def (strcpy)