Skip to content

Commit d062a5a

Browse files
committed
Fix issue yuin#214: replace golang native map with swiss map for table hash parts
1 parent ccacf66 commit d062a5a

File tree

7 files changed

+575
-70
lines changed

7 files changed

+575
-70
lines changed

bits.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This is a port of the bits.go file from the dolthub/swiss repository.
2+
// The original source code is licensed under the Apache License, Version 2.0.
3+
// The original source code can be found at:
4+
// https://github.com/dolthub/swiss
5+
6+
//go:build !amd64 || nosimd
7+
8+
package lua
9+
10+
import (
11+
"math/bits"
12+
"unsafe"
13+
)
14+
15+
const (
16+
groupSize = 8
17+
maxAvgGroupLoad = 7
18+
19+
loBits uint64 = 0x0101010101010101
20+
hiBits uint64 = 0x8080808080808080
21+
)
22+
23+
type bitset uint64
24+
25+
func metaMatchH2(m *metadata, h h2) bitset {
26+
// https://graphics.stanford.edu/~seander/bithacks.html##ValueInWord
27+
return hasZeroByte(castUint64(m) ^ (loBits * uint64(h)))
28+
}
29+
30+
func metaMatchEmpty(m *metadata) bitset {
31+
return hasZeroByte(castUint64(m) ^ hiBits)
32+
}
33+
34+
func nextMatch(b *bitset) uint32 {
35+
s := uint32(bits.TrailingZeros64(uint64(*b)))
36+
*b &= ^(1 << s) // clear bit |s|
37+
return s >> 3 // div by 8
38+
}
39+
40+
func hasZeroByte(x uint64) bitset {
41+
return bitset(((x - loBits) & ^(x)) & hiBits)
42+
}
43+
44+
func castUint64(m *metadata) uint64 {
45+
return *(*uint64)((unsafe.Pointer)(m))
46+
}

bits_amd64.go

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bits_amd64.s

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Code generated by command: go run asm.go -out match.s -stubs match_amd64.go. DO NOT EDIT.
2+
3+
//go:build amd64
4+
5+
#include "textflag.h"
6+
7+
// func matchMetadata(metadata *[16]int8, hash int8) uint16
8+
// Requires: SSE2, SSSE3
9+
TEXT ·matchMetadata(SB), NOSPLIT, $0-18
10+
MOVQ metadata+0(FP), AX
11+
MOVBLSX hash+8(FP), CX
12+
MOVD CX, X0
13+
PXOR X1, X1
14+
PSHUFB X1, X0
15+
MOVOU (AX), X1
16+
PCMPEQB X1, X0
17+
PMOVMSKB X0, AX
18+
MOVW AX, ret+16(FP)
19+
RET

0 commit comments

Comments
 (0)