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<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
14 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
25 JMP cmpbody<>(SB)
26
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
33 MOVV $ret+32(FP), R13
34 #endif
35 // R4 = a_base
36 // R5 = a_len
37 // R6 = b_base
38 // R7 = b_len
39 JMP cmpbody<>(SB)
40
41 // On entry:
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
46 // R13 points to the return value (-1/0/1)
47 TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0
48 BEQ R4, R6, samebytes // same start of a and b
49
50 SGTU R5, R7, R9
51 BNE R0, R9, r2_lt_r1
52 MOVV R5, R14
53 JMP entry
54 r2_lt_r1:
55 MOVV R7, R14 // R14 is min(R4, R5)
56 entry:
57 ADDV R4, R14, R12 // R6 start of a, R14 end of a
58 BEQ R4, R12, samebytes // length is 0
59
60 SRLV $4, R14 // R14 is number of chunks
61 BEQ R0, R14, byte_loop
62
63 // make sure both a and b are aligned.
64 OR R4, R6, R15
65 AND $7, R15
66 BNE R0, R15, byte_loop
67
68 PCALIGN $16
69 chunk16_loop:
70 BEQ R0, R14, byte_loop
71 MOVV (R4), R8
72 MOVV (R6), R9
73 BNE R8, R9, byte_loop
74 MOVV 8(R4), R16
75 MOVV 8(R6), R17
76 ADDV $16, R4
77 ADDV $16, R6
78 SUBVU $1, R14
79 BEQ R16, R17, chunk16_loop
80 SUBV $8, R4
81 SUBV $8, R6
82
83 byte_loop:
84 BEQ R4, R12, samebytes
85 MOVBU (R4), R8
86 ADDVU $1, R4
87 MOVBU (R6), R9
88 ADDVU $1, R6
89 BEQ R8, R9, byte_loop
90
91 byte_cmp:
92 SGTU R8, R9, R4 // R12 = 1 if (R8 > R9)
93 BNE R0, R4, ret
94 MOVV $-1, R4
95 JMP ret
96
97 samebytes:
98 SGTU R5, R7, R8
99 SGTU R7, R5, R9
100 SUBV R9, R8, R4
101
102 ret:
103 #ifndef GOEXPERIMENT_regabiargs
104 MOVV R4, (R13)
105 #endif
106 RET
107
View as plain text