jit

package
v0.0.0-...-337ae54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2025 License: 0BSD Imports: 8 Imported by: 0

Documentation

Overview

Package jit provides a safe alternative to reflect.MakeFunc with support for transparent optimisation.

This package is still in an experimental proof-of-concept phase and is not quite ready for general use. The aim is to provide a safe way to create small optimised functions at runtime. This package is included in runtime.link to serve as an optimisation pathway for [api.Linker] implementations.

Index

Constants

This section is empty.

Variables

View Source
var HardwareLocations = xyz.AccessorFor(HardwareLocation.Values)
View Source
var Locations = xyz.AccessorFor(Location.Values)

Functions

func Make

func Make[T any](impl Implementation) (T, error)

Make a new function of type 'T' using the given JIT implementation function. The implementation function must have the JIT equivalent for each argument and return value. The Implementation function may be called each time the JIT function is called, in order to compile it, or it may only be called once. Therefore the behaviour of the implementation should not depend on any side effects or mutability.

func MakeFunc

func MakeFunc(fnType reflect.Type, impl Implementation) (reflect.Value, error)

MakeFunc is like Make, but it can be used to create a function value from a reflect.Type instead of one known at compile time.

Types

type ABI

type ABI interface {
	// Call the given pointer with the given arguments and return the results.
	// This will be used when making a 'safe' function using [reflect.MakeFunc] or
	// when the platform does not have JIT optimisations enabled. If an error is
	// returned, it will be returned by [MakeFunc]. The second return value should
	// contains functions that should release any resources allocated by the
	// corresponding argument.
	Call(unsafe.Pointer, []reflect.Value, ...reflect.Type) ([]reflect.Value, []func(), error)

	// CallingConvention returns the calling convention for the given function type
	// so that the location of each argument and return value is clearly specified,
	// if an error is returned, [Call] is used as a fallback.
	CallingConvention(reflect.Type) (args, rets []Location, err error)
}

ABI describes how to call an unsafe.Pointer as the specified function type.

type Assembly

type Assembly struct {
	// contains filtered or unexported fields
}

Assembly used to assemble a function.

func (Assembly) Add

func (asm Assembly) Add(a, b Value) Value

Add returns (a + b).

func (Assembly) Convert

func (asm Assembly) Convert(a Value, rtype reflect.Type) Value

func (Assembly) Go

func (asm Assembly) Go(val Value, fn func(pointer unsafe.Pointer) reflect.Value) Value

func (Assembly) IsZero

func (asm Assembly) IsZero(a Value) Value

func (Assembly) NewError

func (asm Assembly) NewError() Value

func (Assembly) Not

func (asm Assembly) Not(a Value) Value

func (Assembly) NullTerminated

func (asm Assembly) NullTerminated(s Value) Value

func (Assembly) Pinner

func (asm Assembly) Pinner() Pinner

func (Assembly) SliceLen

func (asm Assembly) SliceLen(s Value) Value

func (Assembly) StringLen

func (asm Assembly) StringLen(s Value) Value

func (Assembly) UnsafeCall

func (asm Assembly) UnsafeCall(abi ABI, ptr unsafe.Pointer, args []Value, rets ...reflect.Type) ([]Value, []Lifetime, error)

UnsafeCall uses the given ABI to call the given function pointer with the given arguments and return the results.

type HardwareLocation

type HardwareLocation xyz.Tagged[uint64, struct {
	Register xyz.Case[HardwareLocation, cpu.GPR] // standard register.
	Floating xyz.Case[HardwareLocation, cpu.FPR] // standard floating-point register.
	Stack    xyz.Case[HardwareLocation, uintptr] // offset to the parameter on the stack.
}]

HardwareLocation describes the physical and direct location of a value.

type Implementation

type Implementation func(Assembly, []Value) ([]Value, error)

Implementation for a function.

type Lifetime

type Lifetime struct {
	// contains filtered or unexported fields
}

Lifetime for a value.

type Location

type Location xyz.Tagged[any, struct {
	Physical xyz.Case[Location, HardwareLocation] // value is passed directly.
	Indirect xyz.Case[Location, HardwareLocation] // value is passed indirectly.
	Multiple xyz.Case[Location, []Location]       // multiple values (ie. struct).
}]

Location of a function's argument or return value.

func (Location) Equals

func (loc Location) Equals(rhs Location) bool

type Pinner

type Pinner struct {
	// contains filtered or unexported fields
}

func (Pinner) Pin

func (p Pinner) Pin(value Value)

func (Pinner) Unpin

func (p Pinner) Unpin()

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represents an underlying Go value.

func (Value) UnsafePointer

func (val Value) UnsafePointer() Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL