1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Hashing algorithm inspired by
6 // wyhash: https://github.com/wangyi-fudan/wyhash/blob/ceb019b530e2c1c14d70b79bfa2bc49de7d95bc1/Modern%20Non-Cryptographic%20Hash%20Function%20and%20Pseudorandom%20Number%20Generator.pdf
8 //go:build 386 || arm || mips || mipsle || amd64p32 || armbe || m68k || mips64p32 || mips64p32le || nios2 || ppc || riscv || s390 || sh || shbe || sparc
9 // +build 386 arm mips mipsle amd64p32 armbe m68k mips64p32 mips64p32le nios2 ppc riscv s390 sh shbe sparc
15 // For gccgo, use go:linkname to export compiler-called functions.
19 func memhash32(p unsafe
.Pointer
, seed
uintptr) uintptr {
20 a
, b
:= mix32(uint32(seed
), uint32(4^hashkey
[0]))
21 t
:= readUnaligned32(p
)
29 func memhash64(p unsafe
.Pointer
, seed
uintptr) uintptr {
30 a
, b
:= mix32(uint32(seed
), uint32(8^hashkey
[0]))
31 a
^= readUnaligned32(p
)
32 b
^= readUnaligned32(add(p
, 4))
38 func memhash(p unsafe
.Pointer
, seed
, s
uintptr) uintptr {
39 if GOARCH
== "386" && GOOS
!= "nacl" && useAeshash
{
40 return aeshash(p
, seed
, s
)
42 a
, b
:= mix32(uint32(seed
), uint32(s
^hashkey
[0]))
47 a
^= readUnaligned32(p
)
48 b
^= readUnaligned32(add(p
, 4))
53 a
^= readUnaligned32(p
)
54 b
^= readUnaligned32(add(p
, s
-4))
56 t
:= uint32(*(*byte)(p
))
57 t |
= uint32(*(*byte)(add(p
, s
>>1))) << 8
58 t |
= uint32(*(*byte)(add(p
, s
-1))) << 16
66 func mix32(a
, b
uint32) (uint32, uint32) {
67 c
:= uint64(a
^uint32(hashkey
[1])) * uint64(b
^uint32(hashkey
[2]))
68 return uint32(c
), uint32(c
>> 32)