github.com/primecitizens/pcz/std@v0.2.1/core/mem/read.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package mem 5 6 import ( 7 "unsafe" 8 9 "github.com/primecitizens/pcz/std/core/arch" 10 ) 11 12 // Note: These routines perform the read with a native endianness. 13 14 func ReadUnaligned32(p unsafe.Pointer) uint32 { 15 q := (*[4]byte)(p) 16 if arch.BigEndian { 17 return uint32(q[3]) | uint32(q[2])<<8 | uint32(q[1])<<16 | uint32(q[0])<<24 18 } 19 return uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24 20 } 21 22 func ReadUnaligned64(p unsafe.Pointer) uint64 { 23 q := (*[8]byte)(p) 24 if arch.BigEndian { 25 return uint64(q[7]) | uint64(q[6])<<8 | uint64(q[5])<<16 | uint64(q[4])<<24 | 26 uint64(q[3])<<32 | uint64(q[2])<<40 | uint64(q[1])<<48 | uint64(q[0])<<56 27 } 28 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 29 }