Skip to content

Commit

Permalink
Generate a specific simd.MatchEmpty()
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
  • Loading branch information
colega committed Jul 4, 2024
1 parent 8098dea commit efda023
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bits_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func metaMatchH2(m *metadata, h h2) bitset {
}

func metaMatchEmpty(m *metadata) bitset {
b := simd.MatchMetadata((*[groupSize]uint8)(m), empty)
b := simd.MatchEmpty((*[groupSize]uint8)(m))
return bitset(b)
}

Expand Down
11 changes: 11 additions & 0 deletions simd/match.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ TEXT ·MatchMetadata(SB), NOSPLIT, $0-18
PMOVMSKB X0, AX
MOVW AX, ret+16(FP)
RET

// func MatchEmpty(metadata *[16]uint8) uint16
// Requires: SSE2
TEXT ·MatchEmpty(SB), NOSPLIT, $0-10
MOVQ metadata+0(FP), AX
PXOR X0, X0
MOVOU (AX), X1
PCMPEQB X1, X0
PMOVMSKB X0, AX
MOVW AX, ret+8(FP)
RET
4 changes: 4 additions & 0 deletions simd/match_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 36 additions & 17 deletions simd/src/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,41 @@ import (
func main() {
ConstraintExpr("amd64")

TEXT("MatchMetadata", NOSPLIT, "func(metadata *[16]uint8, hash uint8) uint16")
Doc("MatchMetadata performs a 16-way probe of |metadata| using SSE instructions",
"nb: |metadata| must be an aligned pointer")
m := Mem{Base: Load(Param("metadata"), GP64())}
h := Load(Param("hash"), GP32())
mask := GP32()

x0, x1, x2 := XMM(), XMM(), XMM()
MOVD(h, x0)
PXOR(x1, x1)
PSHUFB(x1, x0)
MOVOU(m, x2)
PCMPEQB(x2, x0)
PMOVMSKB(x0, mask)

Store(mask.As16(), ReturnIndex(0))
RET()
{
TEXT("MatchMetadata", NOSPLIT, "func(metadata *[16]uint8, hash uint8) uint16")
Doc("MatchMetadata performs a 16-way probe of |metadata| using SSE instructions",
"nb: |metadata| must be an aligned pointer")
m := Mem{Base: Load(Param("metadata"), GP64())}
h := Load(Param("hash"), GP32())
mask := GP32()

x0, x1, x2 := XMM(), XMM(), XMM()
MOVD(h, x0)
PXOR(x1, x1)
PSHUFB(x1, x0)
MOVOU(m, x2)
PCMPEQB(x2, x0)
PMOVMSKB(x0, mask)

Store(mask.As16(), ReturnIndex(0))
RET()
}

{
TEXT("MatchEmpty", NOSPLIT, "func(metadata *[16]uint8) uint16")
Doc("MatchMetadata performs a 16-way probe of zero byte using SSE instructions",
"nb: |metadata| must be an aligned pointer")
m := Mem{Base: Load(Param("metadata"), GP64())}
mask := GP32()

x0, x1 := XMM(), XMM()
PXOR(x0, x0)
MOVOU(m, x1)
PCMPEQB(x1, x0)
PMOVMSKB(x0, mask)

Store(mask.As16(), ReturnIndex(0))
RET()
}
Generate()
}

0 comments on commit efda023

Please sign in to comment.