Skip to content

Commit e22d241

Browse files
committed
Revert "bytes: add optimized Compare for arm64"
This reverts commit bfa8b6f. Reason for revert: This depends on another CL which is not yet submitted. Change-Id: I50e7594f1473c911a2079fe910849a6694ac6c07 Reviewed-on: https://go-review.googlesource.com/101496 Reviewed-by: Cherry Zhang <[email protected]>
1 parent bfa8b6f commit e22d241

File tree

1 file changed

+19
-87
lines changed

1 file changed

+19
-87
lines changed

src/internal/bytealg/compare_arm64.s

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-56
1010
MOVD a_len+8(FP), R0
1111
MOVD b_base+24(FP), R3
1212
MOVD b_len+32(FP), R1
13-
MOVD $ret+48(FP), R7
13+
ADD $56, RSP, R7
1414
B cmpbody<>(SB)
1515

1616
TEXT bytes·Compare(SB),NOSPLIT|NOFRAME,$0-56
1717
MOVD a_base+0(FP), R2
1818
MOVD a_len+8(FP), R0
1919
MOVD b_base+24(FP), R3
2020
MOVD b_len+32(FP), R1
21-
MOVD $ret+48(FP), R7
21+
ADD $56, RSP, R7
2222
B cmpbody<>(SB)
2323

2424
TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40
2525
MOVD a_base+0(FP), R2
2626
MOVD a_len+8(FP), R0
2727
MOVD b_base+16(FP), R3
2828
MOVD b_len+24(FP), R1
29-
MOVD $ret+32(FP), R7
29+
ADD $40, RSP, R7
3030
B cmpbody<>(SB)
3131

3232
// On entry:
@@ -37,98 +37,30 @@ TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40
3737
// R7 points to return value (-1/0/1 will be written here)
3838
//
3939
// On exit:
40-
// R4, R5, R6, R8, R9 and R10 are clobbered
40+
// R4, R5, and R6 are clobbered
4141
TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0
4242
CMP R2, R3
43-
BEQ samebytes // same starting pointers; compare lengths
43+
BEQ samebytes // same starting pointers; compare lengths
4444
CMP R0, R1
45-
CSEL LT, R1, R0, R6 // R6 is min(R0, R1)
45+
CSEL LT, R1, R0, R6 // R6 is min(R0, R1)
4646

47-
CMP $0, R6
48-
BEQ samebytes
49-
BIC $0xf, R6, R10
50-
CBZ R10, small // length < 16
51-
ADD R2, R10 // end of chunk16
52-
// length >= 16
53-
chunk16_loop:
54-
LDP.P 16(R2), (R4, R8)
55-
LDP.P 16(R3), (R5, R9)
47+
ADD R2, R6 // R2 is current byte in a, R6 is last byte in a to compare
48+
loop:
49+
CMP R2, R6
50+
BEQ samebytes // all compared bytes were the same; compare lengths
51+
MOVBU.P 1(R2), R4
52+
MOVBU.P 1(R3), R5
5653
CMP R4, R5
57-
BNE cmp
58-
CMP R8, R9
59-
BNE cmpnext
60-
CMP R10, R2
61-
BNE chunk16_loop
62-
AND $0xf, R6, R6
63-
CBZ R6, samebytes
64-
SUBS $8, R6
65-
BLT tail
66-
// the length of tail > 8 bytes
67-
MOVD.P 8(R2), R4
68-
MOVD.P 8(R3), R5
69-
CMP R4, R5
70-
BNE cmp
71-
SUB $8, R6
72-
// compare last 8 bytes
73-
tail:
74-
MOVD (R2)(R6), R4
75-
MOVD (R3)(R6), R5
76-
CMP R4, R5
77-
BEQ samebytes
78-
cmp:
79-
REV R4, R4
80-
REV R5, R5
81-
CMP R4, R5
82-
ret:
54+
BEQ loop
55+
// bytes differed
8356
MOVD $1, R4
84-
CNEG HI, R4, R4
57+
CSNEG LT, R4, R4, R4
8558
MOVD R4, (R7)
8659
RET
87-
small:
88-
TBZ $3, R6, lt_8
89-
MOVD (R2), R4
90-
MOVD (R3), R5
91-
CMP R4, R5
92-
BNE cmp
93-
SUBS $8, R6
94-
BEQ samebytes
95-
ADD $8, R2
96-
ADD $8, R3
97-
SUB $8, R6
98-
B tail
99-
lt_8:
100-
TBZ $2, R6, lt_4
101-
MOVWU (R2), R4
102-
MOVWU (R3), R5
103-
CMPW R4, R5
104-
BNE cmp
105-
SUBS $4, R6
106-
BEQ samebytes
107-
ADD $4, R2
108-
ADD $4, R3
109-
lt_4:
110-
TBZ $1, R6, lt_2
111-
MOVHU (R2), R4
112-
MOVHU (R3), R5
113-
CMPW R4, R5
114-
BNE cmp
115-
ADD $2, R2
116-
ADD $2, R3
117-
lt_2:
118-
TBZ $0, R6, samebytes
119-
one:
120-
MOVBU (R2), R4
121-
MOVBU (R3), R5
122-
CMPW R4, R5
123-
BNE ret
12460
samebytes:
125-
CMP R1, R0
126-
CSET NE, R4
127-
CNEG LO, R4, R4
61+
MOVD $1, R4
62+
CMP R0, R1
63+
CSNEG LT, R4, R4, R4
64+
CSEL EQ, ZR, R4, R4
12865
MOVD R4, (R7)
12966
RET
130-
cmpnext:
131-
REV R8, R4
132-
REV R9, R5
133-
CMP R4, R5
134-
B ret

0 commit comments

Comments
 (0)