]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc32/405/strlen.S
Enable optimized string routines for several PowerPC 4XX family processors.
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / 405 / strlen.S
CommitLineData
a72cc2b2
LM
1/* Optimized strlen implementation for PowerPC476.
2 Copyright (C) 2010 Free Software Foundation, Inc.
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 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.
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 Lesser General Public License for more details.
14
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., 51 Franklin Street, Fifth Floor, Boston MA
18 02110-1301 USA. */
19
20#include <sysdep.h>
21#include <bp-sym.h>
22#include <bp-asm.h>
23
24/* strlen
25
26 Register Use
27 r3:source address and return length of string
28 r4:byte counter
29
30 Implementation description
31 Load 2 words at a time and count bytes, if we find null we subtract one from
32 the count and return the count value. We need to subtract one because
33 we don't count the null character as a byte. */
34
35EALIGN (BP_SYM (strlen),5,0)
36 neg r7,r3
37 clrlwi. r8,r7,29
38 addi r4,0,0
39 beq L(byte_count_loop)
40 mtctr r8
41
42L(loop):
43 lbz r5,0(r3)
44 cmpi cr5,r5,0x0
45 addi r3,r3,0x1
46 addi r4,r4,0x1
47 beq cr5,L(end_strlen)
48 bdnz L(loop)
49
50L(byte_count_loop):
51 lwz r5,0(r3)
52 lwz r6,4(r3)
53 dlmzb. r12,r5,r6
54 add r4,r4,r12
55 bne L(end_strlen)
56 lwz r5,8(r3)
57 lwz r6,12(r3)
58 dlmzb. r12,r5,r6
59 add r4,r4,r12
60 bne L(end_strlen)
61 lwz r5,16(r3)
62 lwz r6,20(r3)
63 dlmzb. r12,r5,r6
64 add r4,r4,r12
65 bne L(end_strlen)
66 lwz r5,24(r3)
67 lwz r6,28(r3)
68 addi r3,r3,0x20
69 dlmzb. r12,r5,r6
70 add r4,r4,r12
71 bne L(end_strlen)
72 b L(byte_count_loop)
73
74L(end_strlen):
75 addi r3,r4,-1
76 blr
77END (BP_SYM (strlen))
78libc_hidden_builtin_def (strlen)