github.com/coocood/rtutil@v0.0.0-20190304133409-c84515f646f2/rtutil.go (about)

     1  package rtutil
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  // NanoTime returns the current time in nanoseconds from a monotonic clock.
     8  //go:linkname NanoTime runtime.nanotime
     9  func NanoTime() int64
    10  
    11  // CPUTicks is a faster alternative to NanoTime to measure time duration.
    12  //go:linkname CPUTicks runtime.cputicks
    13  func CPUTicks() int64
    14  
    15  type stringStruct struct {
    16  	str unsafe.Pointer
    17  	len int
    18  }
    19  
    20  //go:noescape
    21  //go:linkname aeshash runtime.aeshash
    22  func aeshash(p unsafe.Pointer, h, s uintptr) uintptr
    23  
    24  // AESHash is the hash function used by map, it utilize available hardware instructions.
    25  func AESHash(data []byte) uint64 {
    26  	ss := (*stringStruct)(unsafe.Pointer(&data))
    27  	return uint64(aeshash(ss.str, 0, uintptr(ss.len)))
    28  }
    29  
    30  // FastRand is a fast thread local random function.
    31  //go:linkname FastRand runtime.fastrand
    32  func FastRand() uint32
    33