about summary refs log tree commit diff
path: root/sysdeps/powerpc/powerpc32/405/strlen.S
blob: 572a6318629c96bfc4dfa3a07dc6ae83d6aaa97b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Optimized strlen implementation for PowerPC476.
   Copyright (C) 2010-2021 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library.  If not, see
   <https://www.gnu.org/licenses/>.  */

#include <sysdep.h>

/* strlen

       Register Use
       r3:source address and return length of string
       r4:byte counter

       Implementation description
       Load 2 words at a time and count bytes, if we find null we subtract one from
       the count and return the count value. We need to subtract one because
       we don't count the null character as a byte. */

EALIGN (strlen,5,0)
       neg     r7,r3
       clrlwi. r8,r7,29
       addi    r4,0,0
       beq     L(byte_count_loop)
       mtctr   r8

L(loop):
       lbz     r5,0(r3)
       cmpi    cr5,r5,0x0
       addi    r3,r3,0x1
       addi    r4,r4,0x1
       beq     cr5,L(end_strlen)
       bdnz    L(loop)

L(byte_count_loop):
       lwz     r5,0(r3)
       lwz     r6,4(r3)
       dlmzb.  r12,r5,r6
       add     r4,r4,r12
       bne     L(end_strlen)
       lwz     r5,8(r3)
       lwz     r6,12(r3)
       dlmzb.  r12,r5,r6
       add     r4,r4,r12
       bne     L(end_strlen)
       lwz     r5,16(r3)
       lwz     r6,20(r3)
       dlmzb.  r12,r5,r6
       add     r4,r4,r12
       bne     L(end_strlen)
       lwz     r5,24(r3)
       lwz     r6,28(r3)
       addi    r3,r3,0x20
       dlmzb.  r12,r5,r6
       add     r4,r4,r12
       bne     L(end_strlen)
       b       L(byte_count_loop)

L(end_strlen):
       addi    r3,r4,-1
       blr
END (strlen)
libc_hidden_builtin_def (strlen)