xref: /freebsd/contrib/cortex-strings/src/arm/strchr.S (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1/* Copyright (c) 2010-2011, Linaro Limited
2   All rights reserved.
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7
8      * Redistributions of source code must retain the above copyright
9      notice, this list of conditions and the following disclaimer.
10
11      * Redistributions in binary form must reproduce the above copyright
12      notice, this list of conditions and the following disclaimer in the
13      documentation and/or other materials provided with the distribution.
14
15      * Neither the name of Linaro Limited nor the names of its
16      contributors may be used to endorse or promote products derived
17      from this software without specific prior written permission.
18
19   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33   Written by Dave Gilbert <david.gilbert@linaro.org>
34
35   A very simple strchr routine, from benchmarks on A9 it's a bit faster than
36   the current version in eglibc (2.12.1-0ubuntu14 package)
37   I don't think doing a word at a time version is worth it since a lot
38   of strchr cases are very short anyway.
39
40 */
41
42@ 2011-02-07 david.gilbert@linaro.org
43@    Extracted from local git a5b438d861
44
45	.syntax unified
46	.arch armv7-a
47
48	.text
49	.thumb
50
51@ ---------------------------------------------------------------------------
52
53	.thumb_func
54	.align 2
55	.p2align 4,,15
56	.global strchr
57	.type strchr,%function
58strchr:
59	@ r0 = start of string
60	@ r1 = character to match
61	@ returns NULL for no match, or a pointer to the match
62	and	r1,r1, #255
63
641:
65	ldrb	r2,[r0],#1
66	cmp	r2,r1
67	cbz	r2,10f
68	bne	1b
69
70	@ We're here if it matched
715:
72	subs	r0,r0,#1
73	bx	lr
74
7510:
76	@ We're here if we ran off the end
77	cmp	r1, #0	@ Corner case - you're allowed to search for the nil and get a pointer to it
78	beq	5b	@ A bit messy, if it's common we should branch at the start to a special loop
79	mov	r0,#0
80	bx	lr
81