Skip to content

Commit d28bf6c

Browse files
XiaodongLoongIan Lance Taylor
authored andcommitted
internal/bytealg: support basic byte operation on loong64
Contributors to the loong64 port are: Weining Lu <[email protected]> Lei Wang <[email protected]> Lingqin Gong <[email protected]> Xiaolin Zhao <[email protected]> Meidan Li <[email protected]> Xiaojuan Zhai <[email protected]> Qiyuan Pu <[email protected]> Guoqi Chen <[email protected]> This port has been updated to Go 1.15.6: https://github.com/loongson/go Updates #46229 Change-Id: I4ac6d38dc632abfa0b698325ca0ae349c0d7ecd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/342316 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]> Run-TryBot: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a6f3f8d commit d28bf6c

File tree

7 files changed

+194
-4
lines changed

7 files changed

+194
-4
lines changed

src/internal/bytealg/compare_generic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le && !riscv64
5+
//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !loong64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le && !riscv64
66

77
package bytealg
88

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2022 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 ·Compare(SB),NOSPLIT,$0-56
9+
MOVV a_base+0(FP), R6
10+
MOVV b_base+24(FP), R7
11+
MOVV a_len+8(FP), R4
12+
MOVV b_len+32(FP), R5
13+
MOVV $ret+48(FP), R13
14+
JMP cmpbody<>(SB)
15+
16+
TEXT runtime·cmpstring(SB),NOSPLIT,$0-40
17+
MOVV a_base+0(FP), R6
18+
MOVV b_base+16(FP), R7
19+
MOVV a_len+8(FP), R4
20+
MOVV b_len+24(FP), R5
21+
MOVV $ret+32(FP), R13
22+
JMP cmpbody<>(SB)
23+
24+
// On entry:
25+
// R4 length of a
26+
// R5 length of b
27+
// R6 points to the start of a
28+
// R7 points to the start of b
29+
// R13 points to the return value (-1/0/1)
30+
TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0
31+
BEQ R6, R7, samebytes // same start of a and b
32+
33+
SGTU R4, R5, R9
34+
BNE R0, R9, r2_lt_r1
35+
MOVV R4, R14
36+
JMP entry
37+
r2_lt_r1:
38+
MOVV R5, R14 // R14 is min(R4, R5)
39+
entry:
40+
ADDV R6, R14, R12 // R6 start of a, R14 end of a
41+
BEQ R6, R12, samebytes // length is 0
42+
43+
SRLV $4, R14 // R14 is number of chunks
44+
BEQ R0, R14, byte_loop
45+
46+
// make sure both a and b are aligned.
47+
OR R6, R7, R15
48+
AND $7, R15
49+
BNE R0, R15, byte_loop
50+
51+
chunk16_loop:
52+
BEQ R0, R14, byte_loop
53+
MOVV (R6), R8
54+
MOVV (R7), R9
55+
BNE R8, R9, byte_loop
56+
MOVV 8(R6), R16
57+
MOVV 8(R7), R17
58+
ADDV $16, R6
59+
ADDV $16, R7
60+
SUBVU $1, R14
61+
BEQ R16, R17, chunk16_loop
62+
SUBV $8, R6
63+
SUBV $8, R7
64+
65+
byte_loop:
66+
BEQ R6, R12, samebytes
67+
MOVBU (R6), R8
68+
ADDVU $1, R6
69+
MOVBU (R7), R9
70+
ADDVU $1, R7
71+
BEQ R8, R9, byte_loop
72+
73+
byte_cmp:
74+
SGTU R8, R9, R12 // R12 = 1 if (R8 > R9)
75+
BNE R0, R12, ret
76+
MOVV $-1, R12
77+
JMP ret
78+
79+
samebytes:
80+
SGTU R4, R5, R8
81+
SGTU R5, R4, R9
82+
SUBV R9, R8, R12
83+
84+
ret:
85+
MOVV R12, (R13)
86+
RET

src/internal/bytealg/compare_native.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64
5+
//go:build 386 || amd64 || s390x || arm || arm64 || loong64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64
66

77
package bytealg
88

src/internal/bytealg/equal_loong64.s

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2022 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+
#define REGCTXT R29
9+
10+
// memequal(a, b unsafe.Pointer, size uintptr) bool
11+
TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25
12+
MOVV a+0(FP), R4
13+
MOVV b+8(FP), R5
14+
BEQ R4, R5, eq
15+
MOVV size+16(FP), R6
16+
ADDV R4, R6, R7
17+
loop:
18+
BNE R4, R7, test
19+
MOVV $1, R4
20+
MOVB R4, ret+24(FP)
21+
RET
22+
test:
23+
MOVBU (R4), R9
24+
ADDV $1, R4
25+
MOVBU (R5), R10
26+
ADDV $1, R5
27+
BEQ R9, R10, loop
28+
29+
MOVB R0, ret+24(FP)
30+
RET
31+
eq:
32+
MOVV $1, R4
33+
MOVB R4, ret+24(FP)
34+
RET
35+
36+
// memequal_varlen(a, b unsafe.Pointer) bool
37+
TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
38+
MOVV a+0(FP), R4
39+
MOVV b+8(FP), R5
40+
BEQ R4, R5, eq
41+
MOVV 8(REGCTXT), R6 // compiler stores size at offset 8 in the closure
42+
MOVV R4, 8(R3)
43+
MOVV R5, 16(R3)
44+
MOVV R6, 24(R3)
45+
JAL runtime·memequal(SB)
46+
MOVBU 32(R3), R4
47+
MOVB R4, ret+16(FP)
48+
RET
49+
eq:
50+
MOVV $1, R4
51+
MOVB R4, ret+16(FP)
52+
RET

src/internal/bytealg/indexbyte_generic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm
5+
//go:build !386 && !amd64 && !s390x && !arm && !arm64 && !loong64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm
66

77
package bytealg
88

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2022 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-40
9+
MOVV b_base+0(FP), R4
10+
MOVV b_len+8(FP), R5
11+
MOVBU c+24(FP), R6 // byte to find
12+
MOVV R4, R7 // store base for later
13+
ADDV R4, R5 // end
14+
ADDV $-1, R4
15+
16+
loop:
17+
ADDV $1, R4
18+
BEQ R4, R5, notfound
19+
MOVBU (R4), R8
20+
BNE R6, R8, loop
21+
22+
SUBV R7, R4 // remove base
23+
MOVV R4, ret+32(FP)
24+
RET
25+
26+
notfound:
27+
MOVV $-1, R4
28+
MOVV R4, ret+32(FP)
29+
RET
30+
31+
TEXT ·IndexByteString(SB),NOSPLIT,$0-32
32+
MOVV s_base+0(FP), R4
33+
MOVV s_len+8(FP), R5
34+
MOVBU c+16(FP), R6 // byte to find
35+
MOVV R4, R7 // store base for later
36+
ADDV R4, R5 // end
37+
ADDV $-1, R4
38+
39+
loop:
40+
ADDV $1, R4
41+
BEQ R4, R5, notfound
42+
MOVBU (R4), R8
43+
BNE R6, R8, loop
44+
45+
SUBV R7, R4 // remove base
46+
MOVV R4, ret+24(FP)
47+
RET
48+
49+
notfound:
50+
MOVV $-1, R4
51+
MOVV R4, ret+24(FP)
52+
RET

src/internal/bytealg/indexbyte_native.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || mips64 || mips64le || riscv64 || wasm
5+
//go:build 386 || amd64 || s390x || arm || arm64 || loong64 || ppc64 || ppc64le || mips || mipsle || mips64 || mips64le || riscv64 || wasm
66

77
package bytealg
88

0 commit comments

Comments
 (0)