1/* Optimized strlen implementation for PowerPC476. 2 Copyright (C) 2010-2021 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, see 17 <https://www.gnu.org/licenses/>. */ 18 19#include <sysdep.h> 20 21/* strlen 22 23 Register Use 24 r3:source address and return length of string 25 r4:byte counter 26 27 Implementation description 28 Load 2 words at a time and count bytes, if we find null we subtract one from 29 the count and return the count value. We need to subtract one because 30 we don't count the null character as a byte. */ 31 32EALIGN (strlen,5,0) 33 neg r7,r3 34 clrlwi. r8,r7,29 35 addi r4,0,0 36 beq L(byte_count_loop) 37 mtctr r8 38 39L(loop): 40 lbz r5,0(r3) 41 cmpi cr5,r5,0x0 42 addi r3,r3,0x1 43 addi r4,r4,0x1 44 beq cr5,L(end_strlen) 45 bdnz L(loop) 46 47L(byte_count_loop): 48 lwz r5,0(r3) 49 lwz r6,4(r3) 50 dlmzb. r12,r5,r6 51 add r4,r4,r12 52 bne L(end_strlen) 53 lwz r5,8(r3) 54 lwz r6,12(r3) 55 dlmzb. r12,r5,r6 56 add r4,r4,r12 57 bne L(end_strlen) 58 lwz r5,16(r3) 59 lwz r6,20(r3) 60 dlmzb. r12,r5,r6 61 add r4,r4,r12 62 bne L(end_strlen) 63 lwz r5,24(r3) 64 lwz r6,28(r3) 65 addi r3,r3,0x20 66 dlmzb. r12,r5,r6 67 add r4,r4,r12 68 bne L(end_strlen) 69 b L(byte_count_loop) 70 71L(end_strlen): 72 addi r3,r4,-1 73 blr 74END (strlen) 75libc_hidden_builtin_def (strlen) 76