github.com/songzhibin97/gkit@v1.2.13/internal/runtimex/readunaligned_bigendian.go (about)

     1  //go:build ppc64 || s390x || mips || mips64
     2  // +build ppc64 s390x mips mips64
     3  
     4  //
     5  // from golang-go/src/os/endian_little.go
     6  
     7  package runtimex
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  func ReadUnaligned64(p unsafe.Pointer) uint64 {
    14  	// Equal to runtime.readUnaligned64, but this function can be inlined
    15  	// compared to  use runtime.readUnaligned64 via go:linkname.
    16  	q := (*[8]byte)(p)
    17  	return uint64(q[7]) | uint64(q[6])<<8 | uint64(q[5])<<16 | uint64(q[4])<<24 |
    18  		uint64(q[3])<<32 | uint64(q[2])<<40 | uint64(q[1])<<48 | uint64(q[0])<<56
    19  }
    20  
    21  func ReadUnaligned32(p unsafe.Pointer) uint64 {
    22  	q := (*[4]byte)(p)
    23  	return uint64(uint32(q[3]) | uint32(q[2])<<8 | uint32(q[1])<<16 | uint32(q[0])<<24)
    24  }
    25  
    26  func ReadUnaligned16(p unsafe.Pointer) uint64 {
    27  	q := (*[2]byte)(p)
    28  	return uint64(uint32(q[1]) | uint32(q[0])<<8)
    29  }