Skip to content

Commit 1052d09

Browse files
abner-chencsophie-zhao
authored andcommitted
internal/bytealg: add regABI support in bytealg functions on loong64
Update #40724 Co-authored-by: Xiaolin Zhao <[email protected]> Change-Id: I4a7392afd7238d44e7d09aaca7e0d733649926ac Reviewed-on: https://go-review.googlesource.com/c/go/+/521785 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: David Chase <[email protected]> Reviewed-by: Meidan Li <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: David Chase <[email protected]>
1 parent 4e6bbbe commit 1052d09

File tree

3 files changed

+101
-47
lines changed

3 files changed

+101
-47
lines changed

src/internal/bytealg/compare_loong64.s

+57-38
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,102 @@
55
#include "go_asm.h"
66
#include "textflag.h"
77

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
8+
TEXT ·Compare<ABIInternal>(SB),NOSPLIT,$0-56
9+
#ifndef GOEXPERIMENT_regabiargs
10+
MOVV a_base+0(FP), R4
11+
MOVV a_len+8(FP), R5
12+
MOVV b_base+24(FP), R6
13+
MOVV b_len+32(FP), R7
1314
MOVV $ret+48(FP), R13
15+
#else
16+
// R4 = a_base
17+
// R5 = a_len
18+
// R6 = a_cap (unused)
19+
// R7 = b_base (want in R6)
20+
// R8 = b_len (want in R7)
21+
// R9 = b_cap (unused)
22+
MOVV R7, R6
23+
MOVV R8, R7
24+
#endif
1425
JMP cmpbody<>(SB)
1526

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
27+
TEXT runtime·cmpstring<ABIInternal>(SB),NOSPLIT,$0-40
28+
#ifndef GOEXPERIMENT_regabiargs
29+
MOVV a_base+0(FP), R4
30+
MOVV b_base+16(FP), R6
31+
MOVV a_len+8(FP), R5
32+
MOVV b_len+24(FP), R7
2133
MOVV $ret+32(FP), R13
34+
#endif
35+
// R4 = a_base
36+
// R5 = a_len
37+
// R6 = b_base
38+
// R7 = b_len
2239
JMP cmpbody<>(SB)
2340

2441
// 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
42+
// R5 length of a
43+
// R7 length of b
44+
// R4 points to the start of a
45+
// R6 points to the start of b
2946
// R13 points to the return value (-1/0/1)
3047
TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0
31-
BEQ R6, R7, samebytes // same start of a and b
48+
BEQ R4, R6, samebytes // same start of a and b
3249

33-
SGTU R4, R5, R9
50+
SGTU R5, R7, R9
3451
BNE R0, R9, r2_lt_r1
35-
MOVV R4, R14
52+
MOVV R5, R14
3653
JMP entry
3754
r2_lt_r1:
38-
MOVV R5, R14 // R14 is min(R4, R5)
55+
MOVV R7, R14 // R14 is min(R4, R5)
3956
entry:
40-
ADDV R6, R14, R12 // R6 start of a, R14 end of a
41-
BEQ R6, R12, samebytes // length is 0
57+
ADDV R4, R14, R12 // R6 start of a, R14 end of a
58+
BEQ R4, R12, samebytes // length is 0
4259

4360
SRLV $4, R14 // R14 is number of chunks
4461
BEQ R0, R14, byte_loop
4562

4663
// make sure both a and b are aligned.
47-
OR R6, R7, R15
64+
OR R4, R6, R15
4865
AND $7, R15
4966
BNE R0, R15, byte_loop
5067

5168
PCALIGN $16
5269
chunk16_loop:
5370
BEQ R0, R14, byte_loop
54-
MOVV (R6), R8
55-
MOVV (R7), R9
71+
MOVV (R4), R8
72+
MOVV (R6), R9
5673
BNE R8, R9, byte_loop
57-
MOVV 8(R6), R16
58-
MOVV 8(R7), R17
74+
MOVV 8(R4), R16
75+
MOVV 8(R6), R17
76+
ADDV $16, R4
5977
ADDV $16, R6
60-
ADDV $16, R7
6178
SUBVU $1, R14
6279
BEQ R16, R17, chunk16_loop
80+
SUBV $8, R4
6381
SUBV $8, R6
64-
SUBV $8, R7
6582

6683
byte_loop:
67-
BEQ R6, R12, samebytes
68-
MOVBU (R6), R8
84+
BEQ R4, R12, samebytes
85+
MOVBU (R4), R8
86+
ADDVU $1, R4
87+
MOVBU (R6), R9
6988
ADDVU $1, R6
70-
MOVBU (R7), R9
71-
ADDVU $1, R7
7289
BEQ R8, R9, byte_loop
7390

7491
byte_cmp:
75-
SGTU R8, R9, R12 // R12 = 1 if (R8 > R9)
76-
BNE R0, R12, ret
77-
MOVV $-1, R12
92+
SGTU R8, R9, R4 // R12 = 1 if (R8 > R9)
93+
BNE R0, R4, ret
94+
MOVV $-1, R4
7895
JMP ret
7996

8097
samebytes:
81-
SGTU R4, R5, R8
82-
SGTU R5, R4, R9
83-
SUBV R9, R8, R12
98+
SGTU R5, R7, R8
99+
SGTU R7, R5, R9
100+
SUBV R9, R8, R4
84101

85102
ret:
86-
MOVV R12, (R13)
103+
#ifndef GOEXPERIMENT_regabiargs
104+
MOVV R4, (R13)
105+
#endif
87106
RET

src/internal/bytealg/equal_loong64.s

+18-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
#define REGCTXT R29
99

1010
// memequal(a, b unsafe.Pointer, size uintptr) bool
11-
TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25
11+
TEXT runtime·memequal<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-25
12+
#ifndef GOEXPERIMENT_regabiargs
1213
MOVV a+0(FP), R4
1314
MOVV b+8(FP), R5
14-
BEQ R4, R5, eq
1515
MOVV size+16(FP), R6
16+
#endif
17+
BEQ R4, R5, eq
1618
ADDV R4, R6, R7
1719
PCALIGN $16
1820
loop:
1921
BNE R4, R7, test
2022
MOVV $1, R4
23+
#ifndef GOEXPERIMENT_regabiargs
2124
MOVB R4, ret+24(FP)
25+
#endif
2226
RET
2327
test:
2428
MOVBU (R4), R9
@@ -27,27 +31,38 @@ test:
2731
ADDV $1, R5
2832
BEQ R9, R10, loop
2933

34+
MOVB R0, R4
35+
#ifndef GOEXPERIMENT_regabiargs
3036
MOVB R0, ret+24(FP)
37+
#endif
3138
RET
3239
eq:
3340
MOVV $1, R4
41+
#ifndef GOEXPERIMENT_regabiargs
3442
MOVB R4, ret+24(FP)
43+
#endif
3544
RET
3645

3746
// memequal_varlen(a, b unsafe.Pointer) bool
38-
TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17
47+
TEXT runtime·memequal_varlen<ABIInternal>(SB),NOSPLIT,$40-17
48+
#ifndef GOEXPERIMENT_regabiargs
3949
MOVV a+0(FP), R4
4050
MOVV b+8(FP), R5
51+
#endif
4152
BEQ R4, R5, eq
4253
MOVV 8(REGCTXT), R6 // compiler stores size at offset 8 in the closure
4354
MOVV R4, 8(R3)
4455
MOVV R5, 16(R3)
4556
MOVV R6, 24(R3)
4657
JAL runtime·memequal(SB)
4758
MOVBU 32(R3), R4
59+
#ifndef GOEXPERIMENT_regabiargs
4860
MOVB R4, ret+16(FP)
61+
#endif
4962
RET
5063
eq:
5164
MOVV $1, R4
65+
#ifndef GOEXPERIMENT_regabiargs
5266
MOVB R4, ret+16(FP)
67+
#endif
5368
RET

src/internal/bytealg/indexbyte_loong64.s

+26-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
#include "go_asm.h"
66
#include "textflag.h"
77

8-
TEXT ·IndexByte(SB),NOSPLIT,$0-40
8+
TEXT ·IndexByte<ABIInternal>(SB),NOSPLIT,$0-40
9+
#ifndef GOEXPERIMENT_regabiargs
910
MOVV b_base+0(FP), R4
1011
MOVV b_len+8(FP), R5
11-
MOVBU c+24(FP), R6 // byte to find
12-
MOVV R4, R7 // store base for later
12+
MOVBU c+24(FP), R7 // byte to find
13+
#endif
14+
// R4 = b_base
15+
// R5 = b_len
16+
// R6 = b_cap (unused)
17+
// R7 = byte to find
18+
AND $0xff, R7
19+
MOVV R4, R6 // store base for later
1320
ADDV R4, R5 // end
1421
ADDV $-1, R4
1522

@@ -18,21 +25,30 @@ loop:
1825
ADDV $1, R4
1926
BEQ R4, R5, notfound
2027
MOVBU (R4), R8
21-
BNE R6, R8, loop
28+
BNE R7, R8, loop
2229

23-
SUBV R7, R4 // remove base
30+
SUBV R6, R4 // remove base
31+
#ifndef GOEXPERIMENT_regabiargs
2432
MOVV R4, ret+32(FP)
33+
#endif
2534
RET
2635

2736
notfound:
2837
MOVV $-1, R4
38+
#ifndef GOEXPERIMENT_regabiargs
2939
MOVV R4, ret+32(FP)
40+
#endif
3041
RET
3142

32-
TEXT ·IndexByteString(SB),NOSPLIT,$0-32
43+
TEXT ·IndexByteString<ABIInternal>(SB),NOSPLIT,$0-32
44+
#ifndef GOEXPERIMENT_regabiargs
3345
MOVV s_base+0(FP), R4
3446
MOVV s_len+8(FP), R5
3547
MOVBU c+16(FP), R6 // byte to find
48+
#endif
49+
// R4 = s_base
50+
// R5 = s_len
51+
// R6 = byte to find
3652
MOVV R4, R7 // store base for later
3753
ADDV R4, R5 // end
3854
ADDV $-1, R4
@@ -45,10 +61,14 @@ loop:
4561
BNE R6, R8, loop
4662

4763
SUBV R7, R4 // remove base
64+
#ifndef GOEXPERIMENT_regabiargs
4865
MOVV R4, ret+24(FP)
66+
#endif
4967
RET
5068

5169
notfound:
5270
MOVV $-1, R4
71+
#ifndef GOEXPERIMENT_regabiargs
5372
MOVV R4, ret+24(FP)
73+
#endif
5474
RET

0 commit comments

Comments
 (0)