Add Changelog ...
[glibc.git] / sysdeps / powerpc / powerpc32 / 405 / strlen.S
blob210a3afd9246037866cbb9de8e0af439b9c24fe1
1 /* Optimized strlen 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 /* strlen
25        Register Use
26        r3:source address and return length of string
27        r4:byte counter
29        Implementation description
30        Load 2 words at a time and count bytes, if we find null we subtract one from
31        the count and return the count value. We need to subtract one because
32        we don't count the null character as a byte. */
34 EALIGN (BP_SYM (strlen),5,0)
35        neg     r7,r3
36        clrlwi. r8,r7,29
37        addi    r4,0,0
38        beq     L(byte_count_loop)
39        mtctr   r8
41 L(loop):
42        lbz     r5,0(r3)
43        cmpi    cr5,r5,0x0
44        addi    r3,r3,0x1
45        addi    r4,r4,0x1
46        beq     cr5,L(end_strlen)
47        bdnz    L(loop)
49 L(byte_count_loop):
50        lwz     r5,0(r3)
51        lwz     r6,4(r3)
52        dlmzb.  r12,r5,r6
53        add     r4,r4,r12
54        bne     L(end_strlen)
55        lwz     r5,8(r3)
56        lwz     r6,12(r3)
57        dlmzb.  r12,r5,r6
58        add     r4,r4,r12
59        bne     L(end_strlen)
60        lwz     r5,16(r3)
61        lwz     r6,20(r3)
62        dlmzb.  r12,r5,r6
63        add     r4,r4,r12
64        bne     L(end_strlen)
65        lwz     r5,24(r3)
66        lwz     r6,28(r3)
67        addi    r3,r3,0x20
68        dlmzb.  r12,r5,r6
69        add     r4,r4,r12
70        bne     L(end_strlen)
71        b       L(byte_count_loop)
73 L(end_strlen):
74        addi    r3,r4,-1
75        blr
76 END (BP_SYM (strlen))
77 libc_hidden_builtin_def (strlen)