~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to src/linaro-a9/strchr.s

  • Committer: Dr. David Alan Gilbert
  • Date: 2011-02-10 18:39:03 UTC
  • Revision ID: david.gilbert@linaro.org-20110210183903-35d3te7ercbhv1d4
Import of fast memchr, strlen and simple strchr from Dave Gilbert's repo

Show diffs side-by-side

added added

removed removed

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