// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !purego

package maphash

import (
	
	
	
	
)

const purego = false

//go:linkname runtime_rand runtime.rand
func runtime_rand() uint64

//go:linkname runtime_memhash runtime.memhash
//go:noescape
func runtime_memhash( unsafe.Pointer, ,  uintptr) uintptr

func rthash( []byte,  uint64) uint64 {
	if len() == 0 {
		return 
	}
	 := len()
	// The runtime hasher only works on uintptr. For 64-bit
	// architectures, we use the hasher directly. Otherwise,
	// we use two parallel hashers on the lower and upper 32 bits.
	if goarch.PtrSize == 8 {
		return uint64(runtime_memhash(unsafe.Pointer(&[0]), uintptr(), uintptr()))
	}
	 := runtime_memhash(unsafe.Pointer(&[0]), uintptr(), uintptr())
	 := runtime_memhash(unsafe.Pointer(&[0]), uintptr(>>32), uintptr())
	return uint64()<<32 | uint64()
}

func rthashString( string,  uint64) uint64 {
	 := unsafe.Slice(unsafe.StringData(), len())
	return rthash(, )
}

func randUint64() uint64 {
	return runtime_rand()
}

func comparableHash[ comparable]( ,  Seed) uint64 {
	 := .s
	var  map[]struct{}
	 := abi.TypeOf()
	var  func(unsafe.Pointer, uintptr) uintptr
	if goexperiment.SwissMap {
		 = (*abi.SwissMapType)(unsafe.Pointer()).Hasher
	} else {
		 = (*abi.OldMapType)(unsafe.Pointer()).Hasher
	}
	if goarch.PtrSize == 8 {
		return uint64((abi.NoEscape(unsafe.Pointer(&)), uintptr()))
	}
	 := (abi.NoEscape(unsafe.Pointer(&)), uintptr())
	 := (abi.NoEscape(unsafe.Pointer(&)), uintptr(>>32))
	return uint64()<<32 | uint64()
}

func writeComparable[ comparable]( *Hash,  ) {
	.state.s = comparableHash(, .state)
}