1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 #include "go_asm.h"
6 #include "textflag.h"
7
8 TEXT ·IndexByte(SB),NOSPLIT,$0-20
9 MOVW b_base+0(FP), R0
10 MOVW b_len+4(FP), R1
11 MOVBU c+12(FP), R2 // byte to find
12 MOVW $ret+16(FP), R5
13 B indexbytebody<>(SB)
14
15 TEXT ·IndexByteString(SB),NOSPLIT,$0-16
16 MOVW s_base+0(FP), R0
17 MOVW s_len+4(FP), R1
18 MOVBU c+8(FP), R2 // byte to find
19 MOVW $ret+12(FP), R5
20 B indexbytebody<>(SB)
21
22 // input:
23 // R0: data
24 // R1: data length
25 // R2: byte to find
26 // R5: address to put result
27 TEXT indexbytebody<>(SB),NOSPLIT,$0-0
28 MOVW R0, R4 // store base for later
29 ADD R0, R1 // end
30
31 loop:
32 CMP R0, R1
33 B.EQ notfound
34 MOVBU.P 1(R0), R3
35 CMP R2, R3
36 B.NE loop
37
38 SUB $1, R0 // R0 will be one beyond the position we want
39 SUB R4, R0 // remove base
40 MOVW R0, (R5)
41 RET
42
43 notfound:
44 MOVW $-1, R0
45 MOVW R0, (R5)
46 RET
47
View as plain text