From a6c623ed9f971d6fbebddaf9ad03d357994647cc Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Tue, 30 Mar 2021 15:03:08 -0700 Subject: Added more comments --- pkg/atomicbitops/aligned_32bit_unsafe.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pkg/atomicbitops') diff --git a/pkg/atomicbitops/aligned_32bit_unsafe.go b/pkg/atomicbitops/aligned_32bit_unsafe.go index a5c762f67..200fc0092 100644 --- a/pkg/atomicbitops/aligned_32bit_unsafe.go +++ b/pkg/atomicbitops/aligned_32bit_unsafe.go @@ -35,6 +35,9 @@ type AlignedAtomicInt64 struct { } func (aa *AlignedAtomicInt64) ptr() *int64 { + // In the 15-byte aa.value, there are guaranteed to be 8 contiguous + // bytes with 64-bit alignment. We find an address in this range by + // adding 7, then clear the 3 least significant bits to get its start. return (*int64)(unsafe.Pointer((uintptr(unsafe.Pointer(&aa.value)) + 7) &^ 7)) } @@ -67,6 +70,9 @@ type AlignedAtomicUint64 struct { } func (aa *AlignedAtomicUint64) ptr() *uint64 { + // In the 15-byte aa.value, there are guaranteed to be 8 contiguous + // bytes with 64-bit alignment. We find an address in this range by + // adding 7, then clear the 3 least significant bits to get its start. return (*uint64)(unsafe.Pointer((uintptr(unsafe.Pointer(&aa.value)) + 7) &^ 7)) } -- cgit v1.2.3