-
Notifications
You must be signed in to change notification settings - Fork 1
/
match_amd64.s
45 lines (35 loc) · 1.1 KB
/
match_amd64.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Code generated by command: go run asm.go -out ../match_amd64.s -stubs ../match_stub.go -pkg swisstable. DO NOT EDIT.
#include "textflag.h"
// func MatchByte(c uint8, buffer []byte) (mask uint32, ok bool)
// Requires: SSE2, SSSE3
TEXT ·MatchByte(SB), NOSPLIT, $0-37
// Get our input parameters
MOVBLZX c+0(FP), AX
MOVQ buffer_base+8(FP), CX
MOVQ buffer_len+16(FP), DX
// Check len of our input slice, which must be at least 16
CMPQ DX, $0x10
JGE valid
// Input slice too short. Return 0, false
XORL AX, AX
MOVL AX, mask+32(FP)
MOVB $0x00, ok+36(FP)
RET
valid:
// Input slice is a valid length
// Move c into an xmm register
MOVD AX, X0
// Shuffle the value of c into every byte of another xmm register
PXOR X1, X1
PSHUFB X1, X0
// Do an unaligned move of 16 bytes of input slice data to xmm register
// MOVOU is how MOVDQU is spelled in Go asm
MOVOU (CX), X1
// Find matching bytes with result in xmm register
PCMPEQB X1, X0
// Collapse matching bytes result down to an integer bitmask
PMOVMSKB X0, AX
// Return bitmask, true
MOVL AX, mask+32(FP)
MOVB $0x01, ok+36(FP)
RET