// so actually
// void atomicload64(uint64 *res, uint64 volatile *addr);
TEXT runtime·atomicload64(SB), 7, $0-8
- MOVL 4(SP), BX
+ MOVL 4(SP), BX
MOVL 8(SP), AX
// MOVQ (%EAX), %MM0
BYTE $0x0f; BYTE $0x6f; BYTE $0x00
MOVL DI, ret+16(FP)
RET
+TEXT strings·IndexByte(SB),7,$0
+ MOVL s+0(FP), SI
+ MOVL s_len+4(FP), CX
+ MOVB c+8(FP), AL
+ MOVL SI, DI
+ CLD; REPN; SCASB
+ JZ 3(PC)
+ MOVL $-1, ret+12(FP)
+ RET
+ SUBL SI, DI
+ SUBL $1, DI
+ MOVL DI, ret+12(FP)
+ RET
+
// input:
// SI = a
// DI = b
MOVQ s+0(FP), SI
MOVQ s_len+8(FP), BX
MOVB c+24(FP), AL
+ CALL runtime·indexbytebody(SB)
+ MOVQ AX, ret+32(FP)
+ RET
+
+TEXT strings·IndexByte(SB),7,$0
+ MOVQ s+0(FP), SI
+ MOVQ s_len+8(FP), BX
+ MOVB c+16(FP), AL
+ CALL runtime·indexbytebody(SB)
+ MOVQ AX, ret+24(FP)
+ RET
+
+// input:
+// SI: data
+// BX: data len
+// AL: byte sought
+// output:
+// AX
+TEXT runtime·indexbytebody(SB),7,$0
MOVQ SI, DI
CMPQ BX, $16
JZ success
failure:
- MOVQ $-1, ret+32(FP)
+ MOVQ $-1, AX
RET
// handle for lengths < 16
MOVQ BX, CX
REPN; SCASB
JZ success
- MOVQ $-1, ret+32(FP)
+ MOVQ $-1, AX
RET
// we've found the chunk containing the byte
BSFW DX, DX
SUBQ SI, DI
ADDQ DI, DX
- MOVQ DX, ret+32(FP)
+ MOVQ DX, AX
RET
success:
SUBQ SI, DI
SUBL $1, DI
- MOVQ DI, ret+32(FP)
+ MOVQ DI, AX
RET
TEXT bytes·Equal(SB),7,$0-49
MOVW $-1, R0
MOVW R0, ret+16(FP)
RET
+
+TEXT strings·IndexByte(SB),7,$0
+ MOVW s+0(FP), R0
+ MOVW s_len+4(FP), R1
+ MOVBU c+8(FP), R2 // byte to find
+ MOVW R0, R4 // store base for later
+ ADD R0, R1 // end
+
+_sib_loop:
+ CMP R0, R1
+ B.EQ _sib_notfound
+ MOVBU.P 1(R0), R3
+ CMP R2, R3
+ B.NE _sib_loop
+
+ SUB $1, R0 // R0 will be one beyond the position we want
+ SUB R4, R0 // remove base
+ MOVW R0, ret+12(FP)
+ RET
+
+_sib_notfound:
+ MOVW $-1, R0
+ MOVW R0, ret+12(FP)
+ RET
return -1
}
-// IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
-func IndexByte(s string, c byte) int {
- for i := 0; i < len(s); i++ {
- if s[i] == c {
- return i
- }
- }
- return -1
-}
-
// LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
func LastIndex(s, sep string) int {
n := len(sep)
--- /dev/null
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file is here just to make the go tool happy.
--- /dev/null
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package strings
+
+// IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
+func IndexByte(s string, c byte) int // ../runtime/asm_$GOARCH.s