]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/arm/strchr.s
libc: add _uv2d()/uv2f() and _vas*d() functions to vlrt.c
[plan9front.git] / sys / src / libc / arm / strchr.s
1 TEXT strchr(SB), $0
2         MOVBU   c+4(FP), R1
3         CMP     $0, R1
4         BEQ     _null
5
6 _strchr:                                /* not looking for a null, byte at a time */
7         MOVBU.P 1(R0), R2
8         CMP     R1, R2
9         BEQ     _sub1
10
11         CMP     $0, R2
12         BNE     _strchr
13
14 _return0:                               /* character not found in string, return 0 */
15         MOVW    $0, R0
16         RET
17
18 _null:                                  /* looking for null, align */
19         AND.S   $3, R0, R2
20         BEQ     _aligned
21
22         MOVBU.P 1(R0), R4
23         CMP     $0, R4
24         BEQ     _sub1
25         B       _null
26
27 _aligned:
28         MOVW    $0xFF, R3               /* mask */
29
30 _loop:
31         MOVW.P  4(R0), R4               /* 4 at a time */
32         TST     R4, R3                  /* AND.S R2, R3, Rx */
33         TST.NE  R4>>8, R3
34         TST.NE  R4>>16, R3
35         TST.NE  R4>>24, R3
36         BNE     _loop
37
38         TST     R4, R3                  /* its somewhere, find it and correct */
39         BEQ     _sub4
40         TST     R4>>8, R3
41         BEQ     _sub3
42         TST     R4>>16, R3
43         BEQ     _sub2
44
45 _sub1:                                  /* compensate for pointer increment */
46         SUB     $1, R0
47         RET
48 _sub2:
49         SUB     $2, R0
50         RET
51 _sub3:
52         SUB     $3, R0
53         RET
54 _sub4:
55         SUB     $4, R0
56         RET