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