Documentation ¶
Index ¶
- func CallFunc()
- func GrowStack()
- func Prepare()
- func PushFunc()
- func Restore()
- type ArchFunc
- type Args
- type Error
- type FloatingPointRegister
- func (r *FloatingPointRegister) Bool() bool
- func (r *FloatingPointRegister) Float32() float32
- func (r *FloatingPointRegister) Float64() float64
- func (r *FloatingPointRegister) Int() int
- func (r *FloatingPointRegister) Int32() int32
- func (r *FloatingPointRegister) Int64() int64
- func (r *FloatingPointRegister) Int8() int8
- func (r *FloatingPointRegister) SetBool(b bool)
- func (r *FloatingPointRegister) SetFloat32(f float32)
- func (r *FloatingPointRegister) SetFloat64(f float64)
- func (r *FloatingPointRegister) SetInt(i int)
- func (r *FloatingPointRegister) SetInt32(i int32)
- func (r *FloatingPointRegister) SetInt64(i int64)
- func (r *FloatingPointRegister) SetInt8(i int8)
- func (r *FloatingPointRegister) SetUint(i uint)
- func (r *FloatingPointRegister) SetUint16(i uint16)
- func (r *FloatingPointRegister) SetUint32(i uint32)
- func (r *FloatingPointRegister) SetUint64(i uint64)
- func (r *FloatingPointRegister) SetUint8(i uint8)
- func (r *FloatingPointRegister) SetUintptr(i uintptr)
- func (r *FloatingPointRegister) SetUnsafePointer(i unsafe.Pointer)
- func (r *FloatingPointRegister) Uint() uint
- func (r *FloatingPointRegister) Uint16() uint16
- func (r *FloatingPointRegister) Uint32() uint32
- func (r *FloatingPointRegister) Uint64() uint64
- func (r *FloatingPointRegister) Uint8() uint8
- func (r *FloatingPointRegister) Uintptr() uintptr
- func (r *FloatingPointRegister) UnsafePointer() unsafe.Pointer
- type FuncName
- type Instruction
- type Location
- type MathFunc
- type Mode
- type Pointer
- type Program
- type Register
- func (r *Register) Bool() bool
- func (r *Register) Float32() float32
- func (r *Register) Float64() float64
- func (r *Register) Int() int
- func (r *Register) Int16() int16
- func (r *Register) Int32() int32
- func (r *Register) Int64() int64
- func (r *Register) Int8() int8
- func (r *Register) SetBool(b bool)
- func (r *Register) SetFloat32(i float32)
- func (r *Register) SetFloat64(f float64)
- func (r *Register) SetInt(i int)
- func (r *Register) SetInt16(i int16)
- func (r *Register) SetInt32(i int32)
- func (r *Register) SetInt64(i int64)
- func (r *Register) SetInt8(i int8)
- func (r *Register) SetUint(i uint)
- func (r *Register) SetUint16(i uint16)
- func (r *Register) SetUint32(i uint32)
- func (r *Register) SetUint64(i uint64)
- func (r *Register) SetUint8(i uint8)
- func (r *Register) SetUintptr(i uintptr)
- func (r *Register) SetUnsafePointer(i unsafe.Pointer)
- func (r *Register) Uint() uint
- func (r *Register) Uint16() uint16
- func (r *Register) Uint32() uint32
- func (r *Register) Uint64() uint64
- func (r *Register) Uint8() uint8
- func (r *Register) Uintptr() uintptr
- func (r *Register) UnsafePointer() unsafe.Pointer
- type Registers
- type RegistersArch
- type RegistersFast
- type RegistersFull
- func (r *RegistersFull) R10() *Register
- func (r *RegistersFull) R11() *Register
- func (r *RegistersFull) R12() *Register
- func (r *RegistersFull) R13() *Register
- func (r *RegistersFull) R14() *Register
- func (r *RegistersFull) R15() *Register
- func (r *RegistersFull) R8() *Register
- func (r *RegistersFull) R9() *Register
- func (r *RegistersFull) X10() *FloatingPointRegister
- func (r *RegistersFull) X11() *FloatingPointRegister
- func (r *RegistersFull) X12() *FloatingPointRegister
- func (r *RegistersFull) X13() *FloatingPointRegister
- func (r *RegistersFull) X14() *FloatingPointRegister
- func (r *RegistersFull) X15() *FloatingPointRegister
- func (r *RegistersFull) X4() *FloatingPointRegister
- func (r *RegistersFull) X5() *FloatingPointRegister
- func (r *RegistersFull) X6() *FloatingPointRegister
- func (r *RegistersFull) X7() *FloatingPointRegister
- func (r *RegistersFull) X8() *FloatingPointRegister
- func (r *RegistersFull) X9() *FloatingPointRegister
- type RegistersLong
- type RegistersMany
- type RegistersSome
- type RegistersZero
- func (r *RegistersZero) R0() *Register
- func (r *RegistersZero) R1() *Register
- func (r *RegistersZero) R10() *Register
- func (r *RegistersZero) R11() *Register
- func (r *RegistersZero) R12() *Register
- func (r *RegistersZero) R13() *Register
- func (r *RegistersZero) R14() *Register
- func (r *RegistersZero) R15() *Register
- func (r *RegistersZero) R2() *Register
- func (r *RegistersZero) R3() *Register
- func (r *RegistersZero) R4() *Register
- func (r *RegistersZero) R5() *Register
- func (r *RegistersZero) R6() *Register
- func (r *RegistersZero) R7() *Register
- func (r *RegistersZero) R8() *Register
- func (r *RegistersZero) R9() *Register
- func (r *RegistersZero) X0() *FloatingPointRegister
- func (r *RegistersZero) X1() *FloatingPointRegister
- func (r *RegistersZero) X10() *FloatingPointRegister
- func (r *RegistersZero) X11() *FloatingPointRegister
- func (r *RegistersZero) X12() *FloatingPointRegister
- func (r *RegistersZero) X13() *FloatingPointRegister
- func (r *RegistersZero) X14() *FloatingPointRegister
- func (r *RegistersZero) X15() *FloatingPointRegister
- func (r *RegistersZero) X2() *FloatingPointRegister
- func (r *RegistersZero) X3() *FloatingPointRegister
- func (r *RegistersZero) X4() *FloatingPointRegister
- func (r *RegistersZero) X5() *FloatingPointRegister
- func (r *RegistersZero) X6() *FloatingPointRegister
- func (r *RegistersZero) X7() *FloatingPointRegister
- func (r *RegistersZero) X8() *FloatingPointRegister
- func (r *RegistersZero) X9() *FloatingPointRegister
- type SlowFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FloatingPointRegister ¶
type FloatingPointRegister floatingPointRegister
FloatingPointRegister represents a handle to a floating-point optimised data register.
func (*FloatingPointRegister) Bool ¶
func (r *FloatingPointRegister) Bool() bool
Bool returns true if the register is not equal to 0.
func (*FloatingPointRegister) Float32 ¶
func (r *FloatingPointRegister) Float32() float32
Float32 returns the register as a float32.
func (*FloatingPointRegister) Float64 ¶
func (r *FloatingPointRegister) Float64() float64
Float64 returns the register as a float64.
func (*FloatingPointRegister) Int ¶
func (r *FloatingPointRegister) Int() int
Int returns the register as an int.
func (*FloatingPointRegister) Int32 ¶
func (r *FloatingPointRegister) Int32() int32
Int32 returns the register as an int32.
func (*FloatingPointRegister) Int64 ¶
func (r *FloatingPointRegister) Int64() int64
Int64 returns the register as an int64.
func (*FloatingPointRegister) Int8 ¶
func (r *FloatingPointRegister) Int8() int8
Int8 returns the register as an int8.
func (*FloatingPointRegister) SetBool ¶
func (r *FloatingPointRegister) SetBool(b bool)
SetBool sets the register to 1 if b is true, otherwise 0.
func (*FloatingPointRegister) SetFloat32 ¶
func (r *FloatingPointRegister) SetFloat32(f float32)
SetFloat32 sets the register to f.
func (*FloatingPointRegister) SetFloat64 ¶
func (r *FloatingPointRegister) SetFloat64(f float64)
SetFloat64 sets the register to f.
func (*FloatingPointRegister) SetInt ¶
func (r *FloatingPointRegister) SetInt(i int)
SetInt sets the register to i.
func (*FloatingPointRegister) SetInt32 ¶
func (r *FloatingPointRegister) SetInt32(i int32)
SetInt32 sets the register to i.
func (*FloatingPointRegister) SetInt64 ¶
func (r *FloatingPointRegister) SetInt64(i int64)
SetInt64 sets the register to i.
func (*FloatingPointRegister) SetInt8 ¶
func (r *FloatingPointRegister) SetInt8(i int8)
SetInt8 sets the register to i.
func (*FloatingPointRegister) SetUint ¶
func (r *FloatingPointRegister) SetUint(i uint)
SetUint sets the register to i.
func (*FloatingPointRegister) SetUint16 ¶
func (r *FloatingPointRegister) SetUint16(i uint16)
SetUint16 sets the register to i.
func (*FloatingPointRegister) SetUint32 ¶
func (r *FloatingPointRegister) SetUint32(i uint32)
SetUint32 sets the register to i.
func (*FloatingPointRegister) SetUint64 ¶
func (r *FloatingPointRegister) SetUint64(i uint64)
SetUint64 sets the register to i.
func (*FloatingPointRegister) SetUint8 ¶
func (r *FloatingPointRegister) SetUint8(i uint8)
SetUint8 sets the register to i.
func (*FloatingPointRegister) SetUintptr ¶
func (r *FloatingPointRegister) SetUintptr(i uintptr)
SetUintptr sets the register to i.
func (*FloatingPointRegister) SetUnsafePointer ¶
func (r *FloatingPointRegister) SetUnsafePointer(i unsafe.Pointer)
SetUnsafePointer sets the register to i.
func (*FloatingPointRegister) Uint ¶
func (r *FloatingPointRegister) Uint() uint
Uint returns the register as an uint.
func (*FloatingPointRegister) Uint16 ¶
func (r *FloatingPointRegister) Uint16() uint16
Uint16 returns the register as an uint16.
func (*FloatingPointRegister) Uint32 ¶
func (r *FloatingPointRegister) Uint32() uint32
Uint32 returns the register as an uint32.
func (*FloatingPointRegister) Uint64 ¶
func (r *FloatingPointRegister) Uint64() uint64
Uint64 returns the register as an uint64.
func (*FloatingPointRegister) Uint8 ¶
func (r *FloatingPointRegister) Uint8() uint8
Uint8 returns the register as an uint8.
func (*FloatingPointRegister) Uintptr ¶
func (r *FloatingPointRegister) Uintptr() uintptr
Uintptr returns the register as an uintptr
func (*FloatingPointRegister) UnsafePointer ¶
func (r *FloatingPointRegister) UnsafePointer() unsafe.Pointer
UnsafePointer returns the register as an unsafe.Pointer only valid when the pointer in this register is runtime pinned, static, or when it hasn't been allocated by Go.
type FuncName ¶
type FuncName uint8
const ( Noop FuncName = iota Jump // to instruction $normal if $assert is not zero. Call // call the function loaded into the context. Wrap // replace $normal with p.Func[$length]($normal) Data // replace $normal with p.Data[$normal] Bool // convert $normal to a boolean in $normal. SwapLength SwapAssert SwapResult HeapMake HeapPush8 HeapPush16 HeapPush32 HeapPush64 HeapCopy HeapLoad StackCaller // switch to caller stack pointer StackCallee // switch to callee stack pointer Stack // reset stack pointer Stack8 Stack16 Stack32 Stack64 PointerMake // make $normal pointer a [Pointer]. PointerFree PointerKeep PointerLoad ErrorMake // make $result into an error in $normal and $assert. StringSize // null-terminated string size of $normal StringCopy // copy $normal as a null-terminated string and store in $normal. StringMake // copy $normal + $length as a null-terminated string if needed. AssertArgs )
Func names.
type Instruction ¶
type Instruction uint8
Instruction is a single instruction that can be executed by the cpu inside of a [MakeFunc] function.
func NewArch ¶
func NewArch(args ArchFunc) Instruction
func NewBits ¶
func NewBits(args uint8) Instruction
func NewFunc ¶
func NewFunc(args FuncName) Instruction
func NewLoad ¶
func NewLoad(args Location) Instruction
func NewMath ¶
func NewMath(args MathFunc) Instruction
func NewMove ¶
func NewMove(args Location) Instruction
func NewSlow ¶
func NewSlow(args SlowFunc) Instruction
func (Instruction) Decode ¶
func (op Instruction) Decode() (Mode, Args)
Decode returns the mode and arguments of the instruction.
func (Instruction) String ¶
func (op Instruction) String() (s string)
String implements fmt.Stringer and returns a readable representation of the instruction.
type MathFunc ¶
type MathFunc uint8
const ( Flip MathFunc = iota // invert $result as a boolean // assertions Less // write 1 to $result if $normal !< $assert More // write 1 to $result if $normal !> $assert Same // write 1 to $result if $normal != $assert Diff // write 1 to $result if $normal = $assert Add // add $normal and $assert Sub // subtract $assert from $normal Mul // multiply $normal and $assert Div // divide $normal by $assert Mod // modulo $normal by $assert Addi // signed add $normal and $assert Subi // signed subtract $assert from $normal Muli // signed multiply $normal and $assert Divi // signed divide $normal by $assert Modi // signed modulo $normal by $assert And // bitwise and $normal and $assert Or // bitwise or $normal and $assert Xor // bitwise xor $normal and $assert Shl // shift $normal left by $assert Shr // shift $normal right by $assert Addf // add $normal and $assert as floating point Subf // subtract $assert from $normal as floating point Mulf // multiply $normal and $assert as floating point Divf // divide $normal by $assert as floating point Conv // cast integer $normal to $result as a float Convf // cast float $normal to $result as an integer )
Math operations, operate on $normal and $assert, result is stored in $result.
type Mode ¶
type Mode uint8
Mode is the highest 3-bits of an instruction that defined how to interpret the remaining lower 5 bits of the instruction.
const ( Func Mode = iota Arch // architecture-specific registers and instructions. Load // register N into the $normal register. Slow // ABI compatible functions. Move // the $normal register into write-only output register N. Math // math operations. Bits // load lowest five bits of $normal into register N. )
Modes supported.
type Program ¶
type Program struct { Call unsafe.Pointer // unsafe pointer to the function that will be called by the [Call] instruction. Size int // stack/frame size, zero if unknown. Text []Instruction Pins []Location Data []uint Func []func(Register) Register Dump func() // debug dumper // contains filtered or unexported fields }
Program can be converted into any Go function at runtime. The virtual machine Instruction is geared for writing calling convention converters, although it is turing complete and can be used for general purpose computation (with limited access to the system).
func (*Program) Add ¶
func (program *Program) Add(ins ...Instruction)
Add the given instructions to the program.
func (*Program) MakeFunc ¶
MakeFunc is the safest way to convert a Program into a Go function (still very unsafe!) as it garuntees that the Program will have access to the full set of registers. The resulting call-overhead is the highest. This can be optimized by calling the variants of MakeFunc that leverage a more restricted set of registers.
type Register ¶
type Register register
Register represents a handle to a general purpose data register.
func (*Register) SetFloat32 ¶
SetFloat32 sets the register to i.
func (*Register) SetFloat64 ¶
SetFloat64 sets the register to f.
func (*Register) SetUintptr ¶
SetUintptr sets the register to i.
func (*Register) SetUnsafePointer ¶
SetUnsafePointer sets the register to i.
func (*Register) UnsafePointer ¶
UnsafePointer returns the register as an unsafe.Pointer only valid when the pointer in this register is runtime pinned, static, or when it hasn't been allocated by Go.
type Registers ¶
type Registers interface { R0() *Register R1() *Register R2() *Register R3() *Register R4() *Register R5() *Register R6() *Register R7() *Register R8() *Register R9() *Register R10() *Register R11() *Register R12() *Register R13() *Register R14() *Register R15() *Register X0() *FloatingPointRegister X1() *FloatingPointRegister X2() *FloatingPointRegister X3() *FloatingPointRegister X4() *FloatingPointRegister X5() *FloatingPointRegister X6() *FloatingPointRegister X7() *FloatingPointRegister X8() *FloatingPointRegister X9() *FloatingPointRegister X10() *FloatingPointRegister X11() *FloatingPointRegister X12() *FloatingPointRegister X13() *FloatingPointRegister X14() *FloatingPointRegister X15() *FloatingPointRegister }
type RegistersArch ¶
type RegistersArch = registers
Registers represent the full set of calling registers available on the current architecture for handling the slowest but most general calls.
type RegistersFast ¶
type RegistersFast struct { RegistersZero // contains filtered or unexported fields }
RegistersFast represent the smallest set of useful calling registers available on the current architecture for the fastest calls (R0, R1, and X0).
func (*RegistersFast) R0 ¶
func (r *RegistersFast) R0() *Register
func (*RegistersFast) R1 ¶
func (r *RegistersFast) R1() *Register
func (*RegistersFast) X0 ¶
func (r *RegistersFast) X0() *FloatingPointRegister
type RegistersFull ¶
type RegistersFull struct { RegistersMany // contains filtered or unexported fields }
RegistersFull represent the full set of calling registers, even if they are not available on the current architecture (undefined behaviour).
func (*RegistersFull) R10 ¶
func (r *RegistersFull) R10() *Register
func (*RegistersFull) R11 ¶
func (r *RegistersFull) R11() *Register
func (*RegistersFull) R12 ¶
func (r *RegistersFull) R12() *Register
func (*RegistersFull) R13 ¶
func (r *RegistersFull) R13() *Register
func (*RegistersFull) R14 ¶
func (r *RegistersFull) R14() *Register
func (*RegistersFull) R15 ¶
func (r *RegistersFull) R15() *Register
func (*RegistersFull) R8 ¶
func (r *RegistersFull) R8() *Register
func (*RegistersFull) R9 ¶
func (r *RegistersFull) R9() *Register
func (*RegistersFull) X10 ¶
func (r *RegistersFull) X10() *FloatingPointRegister
func (*RegistersFull) X11 ¶
func (r *RegistersFull) X11() *FloatingPointRegister
func (*RegistersFull) X12 ¶
func (r *RegistersFull) X12() *FloatingPointRegister
func (*RegistersFull) X13 ¶
func (r *RegistersFull) X13() *FloatingPointRegister
func (*RegistersFull) X14 ¶
func (r *RegistersFull) X14() *FloatingPointRegister
func (*RegistersFull) X15 ¶
func (r *RegistersFull) X15() *FloatingPointRegister
func (*RegistersFull) X4 ¶
func (r *RegistersFull) X4() *FloatingPointRegister
func (*RegistersFull) X5 ¶
func (r *RegistersFull) X5() *FloatingPointRegister
func (*RegistersFull) X6 ¶
func (r *RegistersFull) X6() *FloatingPointRegister
func (*RegistersFull) X7 ¶
func (r *RegistersFull) X7() *FloatingPointRegister
func (*RegistersFull) X8 ¶
func (r *RegistersFull) X8() *FloatingPointRegister
func (*RegistersFull) X9 ¶
func (r *RegistersFull) X9() *FloatingPointRegister
type RegistersLong ¶
type RegistersLong struct { RegistersSome // contains filtered or unexported fields }
RegistersLong represent a suitable set of calling registers available on the current architecture for most calls (R0, R1, R2, R3, R4, R5, X0, X1 and X2).
func (*RegistersLong) R4 ¶
func (r *RegistersLong) R4() *Register
func (*RegistersLong) R5 ¶
func (r *RegistersLong) R5() *Register
func (*RegistersLong) X2 ¶
func (r *RegistersLong) X2() *FloatingPointRegister
type RegistersMany ¶
type RegistersMany struct { RegistersLong // contains filtered or unexported fields }
RegistersMany represent even more registers that are available on the current architecture for calls that should still be slightly faster than the full register set (R0, R1, R2, R3, R4, R5, R6, R7, X0, X1, X2 and X3).
func (*RegistersMany) R6 ¶
func (r *RegistersMany) R6() *Register
func (*RegistersMany) R7 ¶
func (r *RegistersMany) R7() *Register
func (*RegistersMany) X3 ¶
func (r *RegistersMany) X3() *FloatingPointRegister
type RegistersSome ¶
type RegistersSome struct { RegistersFast // contains filtered or unexported fields }
RegistersSome represent a useful set of calling registers available on the current architecture for faster calls (R0, R1, R2, R3, X0 and X1).
func (*RegistersSome) R2 ¶
func (r *RegistersSome) R2() *Register
func (*RegistersSome) R3 ¶
func (r *RegistersSome) R3() *Register
func (*RegistersSome) X1 ¶
func (r *RegistersSome) X1() *FloatingPointRegister
type RegistersZero ¶
type RegistersZero struct{}
RegistersZero represents access to no calling registers. Accessing any register will result in a panic.
func (*RegistersZero) R0 ¶
func (r *RegistersZero) R0() *Register
func (*RegistersZero) R1 ¶
func (r *RegistersZero) R1() *Register
func (*RegistersZero) R10 ¶
func (r *RegistersZero) R10() *Register
func (*RegistersZero) R11 ¶
func (r *RegistersZero) R11() *Register
func (*RegistersZero) R12 ¶
func (r *RegistersZero) R12() *Register
func (*RegistersZero) R13 ¶
func (r *RegistersZero) R13() *Register
func (*RegistersZero) R14 ¶
func (r *RegistersZero) R14() *Register
func (*RegistersZero) R15 ¶
func (r *RegistersZero) R15() *Register
func (*RegistersZero) R2 ¶
func (r *RegistersZero) R2() *Register
func (*RegistersZero) R3 ¶
func (r *RegistersZero) R3() *Register
func (*RegistersZero) R4 ¶
func (r *RegistersZero) R4() *Register
func (*RegistersZero) R5 ¶
func (r *RegistersZero) R5() *Register
func (*RegistersZero) R6 ¶
func (r *RegistersZero) R6() *Register
func (*RegistersZero) R7 ¶
func (r *RegistersZero) R7() *Register
func (*RegistersZero) R8 ¶
func (r *RegistersZero) R8() *Register
func (*RegistersZero) R9 ¶
func (r *RegistersZero) R9() *Register
func (*RegistersZero) X0 ¶
func (r *RegistersZero) X0() *FloatingPointRegister
func (*RegistersZero) X1 ¶
func (r *RegistersZero) X1() *FloatingPointRegister
func (*RegistersZero) X10 ¶
func (r *RegistersZero) X10() *FloatingPointRegister
func (*RegistersZero) X11 ¶
func (r *RegistersZero) X11() *FloatingPointRegister
func (*RegistersZero) X12 ¶
func (r *RegistersZero) X12() *FloatingPointRegister
func (*RegistersZero) X13 ¶
func (r *RegistersZero) X13() *FloatingPointRegister
func (*RegistersZero) X14 ¶
func (r *RegistersZero) X14() *FloatingPointRegister
func (*RegistersZero) X15 ¶
func (r *RegistersZero) X15() *FloatingPointRegister
func (*RegistersZero) X2 ¶
func (r *RegistersZero) X2() *FloatingPointRegister
func (*RegistersZero) X3 ¶
func (r *RegistersZero) X3() *FloatingPointRegister
func (*RegistersZero) X4 ¶
func (r *RegistersZero) X4() *FloatingPointRegister
func (*RegistersZero) X5 ¶
func (r *RegistersZero) X5() *FloatingPointRegister
func (*RegistersZero) X6 ¶
func (r *RegistersZero) X6() *FloatingPointRegister
func (*RegistersZero) X7 ¶
func (r *RegistersZero) X7() *FloatingPointRegister
func (*RegistersZero) X8 ¶
func (r *RegistersZero) X8() *FloatingPointRegister
func (*RegistersZero) X9 ¶
func (r *RegistersZero) X9() *FloatingPointRegister