Blame sysdeps/arm/strlen.S

Packit 6c4009
/* Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Code contributed by Matthew Wilcox <willy@odie.barnet.ac.uk>
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Thumb requires excessive IT insns here.  */
Packit 6c4009
#define NO_THUMB
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
/* size_t strlen(const char *S)
Packit 6c4009
 * entry: r0 -> string
Packit 6c4009
 * exit: r0 = len
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
	.syntax unified
Packit 6c4009
	.text
Packit 6c4009
Packit 6c4009
ENTRY(strlen)
Packit 6c4009
	bic     r1, r0, $3              @ addr of word containing first byte
Packit 6c4009
	ldr     r2, [r1], $4            @ get the first word
Packit 6c4009
	ands    r3, r0, $3              @ how many bytes are duff?
Packit 6c4009
	rsb     r0, r3, $0              @ get - that number into counter.
Packit 6c4009
	beq     Laligned                @ skip into main check routine if no
Packit 6c4009
					@ more
Packit 6c4009
#ifdef __ARMEB__
Packit 6c4009
	orr     r2, r2, $0xff000000     @ set this byte to non-zero
Packit 6c4009
	subs    r3, r3, $1              @ any more to do?
Packit 6c4009
	orrgt   r2, r2, $0x00ff0000     @ if so, set this byte
Packit 6c4009
	subs    r3, r3, $1              @ more?
Packit 6c4009
	orrgt   r2, r2, $0x0000ff00     @ then set.
Packit 6c4009
#else
Packit 6c4009
	orr     r2, r2, $0x000000ff     @ set this byte to non-zero
Packit 6c4009
	subs    r3, r3, $1              @ any more to do?
Packit 6c4009
	orrgt   r2, r2, $0x0000ff00     @ if so, set this byte
Packit 6c4009
	subs    r3, r3, $1              @ more?
Packit 6c4009
	orrgt   r2, r2, $0x00ff0000     @ then set.
Packit 6c4009
#endif
Packit 6c4009
Laligned:				@ here, we have a word in r2.  Does it
Packit 6c4009
	tst     r2, $0x000000ff         @ contain any zeroes?
Packit 6c4009
	tstne   r2, $0x0000ff00         @
Packit 6c4009
	tstne   r2, $0x00ff0000         @
Packit 6c4009
	tstne   r2, $0xff000000         @
Packit 6c4009
	addne   r0, r0, $4              @ if not, the string is 4 bytes longer
Packit 6c4009
	ldrne   r2, [r1], $4            @ and we continue to the next word
Packit 6c4009
	bne     Laligned                @
Packit 6c4009
Llastword:				@ drop through to here once we find a
Packit 6c4009
#ifdef __ARMEB__
Packit 6c4009
	tst     r2, $0xff000000         @ word that has a zero byte in it
Packit 6c4009
	addne   r0, r0, $1              @
Packit 6c4009
	tstne   r2, $0x00ff0000         @ and add up to 3 bytes on to it
Packit 6c4009
	addne   r0, r0, $1              @
Packit 6c4009
	tstne   r2, $0x0000ff00         @ (if first three all non-zero, 4th
Packit 6c4009
	addne   r0, r0, $1              @  must be zero)
Packit 6c4009
#else
Packit 6c4009
	tst     r2, $0x000000ff         @ word that has a zero byte in it
Packit 6c4009
	addne   r0, r0, $1              @
Packit 6c4009
	tstne   r2, $0x0000ff00         @ and add up to 3 bytes on to it
Packit 6c4009
	addne   r0, r0, $1              @
Packit 6c4009
	tstne   r2, $0x00ff0000         @ (if first three all non-zero, 4th
Packit 6c4009
	addne   r0, r0, $1              @  must be zero)
Packit 6c4009
#endif
Packit 6c4009
	DO_RET(lr)
Packit 6c4009
END(strlen)
Packit 6c4009
libc_hidden_builtin_def (strlen)