github.com/zhangyunhao116/wyhash@v0.4.1-0.20220217162229-7d42996fa899/internal/unalign/readunaligned_big.go (about)

     1  // +build 386 amd64 arm arm64 ppc64le mips64le mipsle riscv64 wasm
     2  //
     3  // from golang-go/src/os/endian_big.go
     4  
     5  package unalign
     6  
     7  import (
     8  	"unsafe"
     9  )
    10  
    11  func Read8(p unsafe.Pointer) uint64 {
    12  	// Equal to runtime.readUnaligned64, but this function can be inlined
    13  	// compared to  use runtime.readUnaligned64 via go:linkname.
    14  	q := (*[8]byte)(p)
    15  	return uint64(q[0]) | uint64(q[1])<<8 | uint64(q[2])<<16 | uint64(q[3])<<24 | uint64(q[4])<<32 | uint64(q[5])<<40 | uint64(q[6])<<48 | uint64(q[7])<<56
    16  }
    17  
    18  func Read4(p unsafe.Pointer) uint64 {
    19  	q := (*[4]byte)(p)
    20  	return uint64(uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24)
    21  }