...
1// Copied from S2 implementation.
2
3//go:build !appengine && !noasm && gc && !noasm
4
5#include "textflag.h"
6
7// func matchLen(a []byte, b []byte) int
8// Requires: BMI
9TEXT ·matchLen(SB), NOSPLIT, $0-56
10 MOVQ a_base+0(FP), AX
11 MOVQ b_base+24(FP), CX
12 MOVQ a_len+8(FP), DX
13
14 // matchLen
15 XORL SI, SI
16 CMPL DX, $0x08
17 JB matchlen_match4_standalone
18
19matchlen_loopback_standalone:
20 MOVQ (AX)(SI*1), BX
21 XORQ (CX)(SI*1), BX
22 TESTQ BX, BX
23 JZ matchlen_loop_standalone
24
25#ifdef GOAMD64_v3
26 TZCNTQ BX, BX
27#else
28 BSFQ BX, BX
29#endif
30 SARQ $0x03, BX
31 LEAL (SI)(BX*1), SI
32 JMP gen_match_len_end
33
34matchlen_loop_standalone:
35 LEAL -8(DX), DX
36 LEAL 8(SI), SI
37 CMPL DX, $0x08
38 JAE matchlen_loopback_standalone
39
40matchlen_match4_standalone:
41 CMPL DX, $0x04
42 JB matchlen_match2_standalone
43 MOVL (AX)(SI*1), BX
44 CMPL (CX)(SI*1), BX
45 JNE matchlen_match2_standalone
46 LEAL -4(DX), DX
47 LEAL 4(SI), SI
48
49matchlen_match2_standalone:
50 CMPL DX, $0x02
51 JB matchlen_match1_standalone
52 MOVW (AX)(SI*1), BX
53 CMPW (CX)(SI*1), BX
54 JNE matchlen_match1_standalone
55 LEAL -2(DX), DX
56 LEAL 2(SI), SI
57
58matchlen_match1_standalone:
59 CMPL DX, $0x01
60 JB gen_match_len_end
61 MOVB (AX)(SI*1), BL
62 CMPB (CX)(SI*1), BL
63 JNE gen_match_len_end
64 INCL SI
65
66gen_match_len_end:
67 MOVQ SI, ret+48(FP)
68 RET
View as plain text