Home | History | Annotate | Download | only in runtime
      1 // Copyright 2014 The Go Authors.  All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package runtime
      6 
      7 import "unsafe"
      8 
      9 // On AMD64, virtual addresses are 48-bit numbers sign extended to 64.
     10 // We shift the address left 16 to eliminate the sign extended part and make
     11 // room in the bottom for the count.
     12 // In addition to the 16 bits taken from the top, we can take 3 from the
     13 // bottom, because node must be pointer-aligned, giving a total of 19 bits
     14 // of count.
     15 
     16 func lfstackPack(node *lfnode, cnt uintptr) uint64 {
     17 	return uint64(uintptr(unsafe.Pointer(node)))<<16 | uint64(cnt&(1<<19-1))
     18 }
     19 
     20 func lfstackUnpack(val uint64) (node *lfnode, cnt uintptr) {
     21 	node = (*lfnode)(unsafe.Pointer(uintptr(int64(val) >> 19 << 3)))
     22 	cnt = uintptr(val & (1<<19 - 1))
     23 	return
     24 }
     25