github.com/saintwish/kv@v1.0.4/swiss/bits_amd64.go (about)

     1  // From https://github.com/dolthub/swiss
     2  // Copyright 2023 Dolthub, Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  //go:build amd64 && !nosimd
    17  
    18  package swiss
    19  
    20  import (
    21  	"math/bits"
    22  	_ "unsafe"
    23  
    24  	"github.com/saintwish/kv/swiss/simd"
    25  )
    26  
    27  const (
    28  	groupSize       = 16
    29  	maxAvgGroupLoad = 14
    30  )
    31  
    32  type bitset uint16
    33  
    34  func metaMatchH2(m *metadata, h h2) bitset {
    35  	b := simd.MatchMetadata((*[16]int8)(m), int8(h))
    36  	return bitset(b)
    37  }
    38  
    39  func metaMatchEmpty(m *metadata) bitset {
    40  	b := simd.MatchMetadata((*[16]int8)(m), empty)
    41  	return bitset(b)
    42  }
    43  
    44  func nextMatch(b *bitset) (s uint32) {
    45  	s = uint32(bits.TrailingZeros16(uint16(*b)))
    46  	*b &= ^(1 << s) // clear bit |s|
    47  	return
    48  }
    49  
    50  //go:linkname fastrand runtime.fastrand
    51  func fastrand() uint32