github.com/primecitizens/pcz/std@v0.2.1/builtin/ptr/tptr_32bit.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2014 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build 386 || arm || mips || mipsle
     9  
    10  package stdptr
    11  
    12  import "unsafe"
    13  
    14  // The number of bits stored in the numeric tag of a TaggedPointer
    15  const TaggedPointerBits = 32
    16  
    17  // On 32-bit systems, TaggedPointer has a 32-bit pointer and 32-bit count.
    18  
    19  // TaggedPointerPack created a TaggedPointer from a pointer and a tag.
    20  // Tag bits that don't fit in the result are discarded.
    21  func TaggedPointerPack(ptr unsafe.Pointer, tag uintptr) TaggedPointer {
    22  	return TaggedPointer(uintptr(ptr))<<32 | TaggedPointer(tag)
    23  }
    24  
    25  // Pointer returns the pointer from a TaggedPointer.
    26  func (tp TaggedPointer) pointer() unsafe.Pointer {
    27  	return unsafe.Pointer(uintptr(tp >> 32))
    28  }
    29  
    30  // Tag returns the tag from a TaggedPointer.
    31  func (tp TaggedPointer) tag() uintptr {
    32  	return uintptr(tp)
    33  }