github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/abi/abi.go (about)

     1  // Copyright 2020 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 abi
     6  
     7  import (
     8  	"github.com/shogo82148/std/unsafe"
     9  )
    10  
    11  // RegArgs is a struct that has space for each argument
    12  // and return value register on the current architecture.
    13  //
    14  // Assembly code knows the layout of the first two fields
    15  // of RegArgs.
    16  //
    17  // RegArgs also contains additional space to hold pointers
    18  // when it may not be safe to keep them only in the integer
    19  // register space otherwise.
    20  type RegArgs struct {
    21  	// Values in these slots should be precisely the bit-by-bit
    22  	// representation of how they would appear in a register.
    23  	//
    24  	// This means that on big endian arches, integer values should
    25  	// be in the top bits of the slot. Floats are usually just
    26  	// directly represented, but some architectures treat narrow
    27  	// width floating point values specially (e.g. they're promoted
    28  	// first, or they need to be NaN-boxed).
    29  	Ints   [IntArgRegs]uintptr
    30  	Floats [FloatArgRegs]uint64
    31  
    32  	// Ptrs is a space that duplicates Ints but with pointer type,
    33  	// used to make pointers passed or returned  in registers
    34  	// visible to the GC by making the type unsafe.Pointer.
    35  	Ptrs [IntArgRegs]unsafe.Pointer
    36  
    37  	// ReturnIsPtr is a bitmap that indicates which registers
    38  	// contain or will contain pointers on the return path from
    39  	// a reflectcall. The i'th bit indicates whether the i'th
    40  	// register contains or will contain a valid Go pointer.
    41  	ReturnIsPtr IntArgRegBitmap
    42  }
    43  
    44  func (r *RegArgs) Dump()
    45  
    46  // IntRegArgAddr returns a pointer inside of r.Ints[reg] that is appropriately
    47  // offset for an argument of size argSize.
    48  //
    49  // argSize must be non-zero, fit in a register, and a power-of-two.
    50  //
    51  // This method is a helper for dealing with the endianness of different CPU
    52  // architectures, since sub-word-sized arguments in big endian architectures
    53  // need to be "aligned" to the upper edge of the register to be interpreted
    54  // by the CPU correctly.
    55  func (r *RegArgs) IntRegArgAddr(reg int, argSize uintptr) unsafe.Pointer
    56  
    57  // IntArgRegBitmap is a bitmap large enough to hold one bit per
    58  // integer argument/return register.
    59  type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8
    60  
    61  // Set sets the i'th bit of the bitmap to 1.
    62  func (b *IntArgRegBitmap) Set(i int)
    63  
    64  // Get returns whether the i'th bit of the bitmap is set.
    65  //
    66  // nosplit because it's called in extremely sensitive contexts, like
    67  // on the reflectcall return path.
    68  //
    69  //go:nosplit
    70  func (b *IntArgRegBitmap) Get(i int) bool