github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/bloom/xxhash/xxhash_purego.go (about)

     1  //go:build purego || !amd64
     2  
     3  package xxhash
     4  
     5  // Sum64 computes the 64-bit xxHash digest of b.
     6  func Sum64(b []byte) uint64 {
     7  	var n = len(b)
     8  	var h uint64
     9  
    10  	if n >= 32 {
    11  		v1 := prime1plus2
    12  		v2 := prime2
    13  		v3 := uint64(0)
    14  		v4 := negprime1
    15  		for len(b) >= 32 {
    16  			v1 = round(v1, u64(b[0:8:len(b)]))
    17  			v2 = round(v2, u64(b[8:16:len(b)]))
    18  			v3 = round(v3, u64(b[16:24:len(b)]))
    19  			v4 = round(v4, u64(b[24:32:len(b)]))
    20  			b = b[32:len(b):len(b)]
    21  		}
    22  		h = rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
    23  		h = mergeRound(h, v1)
    24  		h = mergeRound(h, v2)
    25  		h = mergeRound(h, v3)
    26  		h = mergeRound(h, v4)
    27  	} else {
    28  		h = prime5
    29  	}
    30  
    31  	h += uint64(n)
    32  
    33  	i, end := 0, len(b)
    34  	for ; i+8 <= end; i += 8 {
    35  		k1 := round(0, u64(b[i:i+8:len(b)]))
    36  		h ^= k1
    37  		h = rol27(h)*prime1 + prime4
    38  	}
    39  	if i+4 <= end {
    40  		h ^= uint64(u32(b[i:i+4:len(b)])) * prime1
    41  		h = rol23(h)*prime2 + prime3
    42  		i += 4
    43  	}
    44  	for ; i < end; i++ {
    45  		h ^= uint64(b[i]) * prime5
    46  		h = rol11(h) * prime1
    47  	}
    48  
    49  	return avalanche(h)
    50  }