Skip to content

Commit

Permalink
feat: add readunalighed 16bit support (bytedance#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Ye Li <[email protected]>
Co-authored-by: ZhangYunHao <[email protected]>
  • Loading branch information
3 people authored Jun 4, 2021
1 parent 6d4403f commit 1031037
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/runtimex/readunaligned.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ func ReadUnaligned32(p unsafe.Pointer) uint64 {
q := (*[4]byte)(p)
return uint64(uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24)
}

func ReadUnaligned16(p unsafe.Pointer) uint64 {
q := (*[2]byte)(p)
return uint64(uint32(q[0]) | uint32(q[1])<<8)
}
5 changes: 5 additions & 0 deletions internal/runtimex/readunaligned_bigendian.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ func ReadUnaligned32(p unsafe.Pointer) uint64 {
q := (*[4]byte)(p)
return uint64(uint32(q[3]) | uint32(q[2])<<8 | uint32(q[1])<<16 | uint32(q[0])<<24)
}

func ReadUnaligned16(p unsafe.Pointer) uint64 {
q := (*[2]byte)(p)
return uint64(uint32(q[1]) | uint32(q[0])<<8)
}

0 comments on commit 1031037

Please sign in to comment.