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