diff options
-rw-r--r-- | pkg/atomicbitops/aligned_32bit_unsafe.go | 6 |
1 files changed, 6 insertions, 0 deletions
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)) } |