asm_arm64

package
v0.0.0-...-4e1a221 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COND_EQ asm.ConditionalRegisterState = asm.ConditionalRegisterStateUnset + 1 + iota
	COND_NE
	COND_HS
	COND_LO
	COND_MI
	COND_PL
	COND_VS
	COND_VC
	COND_HI
	COND_LS
	COND_GE
	COND_LT
	COND_GT
	COND_LE
	COND_AL
	COND_NV
)

Arm64-specific register states.

Note: Naming conventions intentionally match the Go assembler: https://go.dev/doc/asm See https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/condition-codes-1-condition-flags-and-codes

View Source
const (
	REG_R0 asm.Register = asm.NilRegister + 1 + iota
	REG_R1
	REG_R2
	REG_R3
	REG_R4
	REG_R5
	REG_R6
	REG_R7
	REG_R8
	REG_R9
	REG_R10
	REG_R11
	REG_R12
	REG_R13
	REG_R14
	REG_R15
	REG_R16
	REG_R17
	REG_R18
	REG_R19
	REG_R20
	REG_R21
	REG_R22
	REG_R23
	REG_R24
	REG_R25
	REG_R26
	REG_R27
	REG_R28
	REG_R29
	REG_R30
	REGZERO

	REG_F0
	REG_F1
	REG_F2
	REG_F3
	REG_F4
	REG_F5
	REG_F6
	REG_F7
	REG_F8
	REG_F9
	REG_F10
	REG_F11
	REG_F12
	REG_F13
	REG_F14
	REG_F15
	REG_F16
	REG_F17
	REG_F18
	REG_F19
	REG_F20
	REG_F21
	REG_F22
	REG_F23
	REG_F24
	REG_F25
	REG_F26
	REG_F27
	REG_F28
	REG_F29
	REG_F30
	REG_F31

	REG_FPSR

	REG_COND_EQ
	REG_COND_NE
	REG_COND_HS
	REG_COND_LO
	REG_COND_MI
	REG_COND_PL
	REG_COND_VS
	REG_COND_VC
	REG_COND_HI
	REG_COND_LS
	REG_COND_GE
	REG_COND_LT
	REG_COND_GT
	REG_COND_LE
	REG_COND_AL
	REG_COND_NV
)

Arm64-specific registers.

Note: Naming conventions intentionally match the Go assembler: https://go.dev/doc/asm See https://developer.arm.com/documentation/dui0801/a/Overview-of-AArch64-state/Predeclared-core-register-names-in-AArch64-state

View Source
const (
	NOP asm.Instruction = iota
	RET
	ADD
	ADDW
	ADR
	AND
	ANDW
	ASR
	ASRW
	B
	BEQ
	BGE
	BGT
	BHI
	BHS
	BLE
	BLO
	BLS
	BLT
	BMI
	BNE
	BVS
	CLZ
	CLZW
	CMP
	CMPW
	CSET
	EOR
	EORW
	FABSD
	FABSS
	FADDD
	FADDS
	FCMPD
	FCMPS
	FCVTDS
	FCVTSD
	FCVTZSD
	FCVTZSDW
	FCVTZSS
	FCVTZSSW
	FCVTZUD
	FCVTZUDW
	FCVTZUS
	FCVTZUSW
	FDIVD
	FDIVS
	FMAXD
	FMAXS
	FMIND
	FMINS
	FMOVD
	FMOVS
	FMULD
	FMULS
	FNEGD
	FNEGS
	FRINTMD
	FRINTMS
	FRINTND
	FRINTNS
	FRINTPD
	FRINTPS
	FRINTZD
	FRINTZS
	FSQRTD
	FSQRTS
	FSUBD
	FSUBS
	LSL
	LSLW
	LSR
	LSRW
	MOVB
	MOVBU
	MOVD
	MOVH
	MOVHU
	MOVW
	MOVWU
	MRS
	MSR
	MSUB
	MSUBW
	MUL
	MULW
	NEG
	NEGW
	ORR
	ORRW
	RBIT
	RBITW
	RNG
	ROR
	RORW
	SCVTFD
	SCVTFS
	SCVTFWD
	SCVTFWS
	SDIV
	SDIVW
	SUB
	SUBS
	SUBW
	SXTB
	SXTBW
	SXTH
	SXTHW
	SXTW
	UCVTFD
	UCVTFS
	UCVTFWD
	UCVTFWS
	UDIV
	UDIVW
	UXTW
	VBIT
	VCNT
	VUADDLV
)

Arm64-specific instructions.

Note: This only defines arm64 instructions used by wazero's JIT compiler. Note: Naming conventions intentionally match the Go assembler: https://go.dev/doc/asm

Variables

View Source
var (
	OperandTypesNoneToNone                     = OperandTypes{OperandTypeNone, OperandTypeNone}
	OperandTypesNoneToRegister                 = OperandTypes{OperandTypeNone, OperandTypeRegister}
	OperandTypesNoneToMemory                   = OperandTypes{OperandTypeNone, OperandTypeMemory}
	OperandTypesNoneToBranch                   = OperandTypes{OperandTypeNone, OperandTypeBranch}
	OperandTypesRegisterToRegister             = OperandTypes{OperandTypeRegister, OperandTypeRegister}
	OperandTypesLeftShiftedRegisterToRegister  = OperandTypes{OperandTypeLeftShiftedRegister, OperandTypeRegister}
	OperandTypesTwoRegistersToRegister         = OperandTypes{OperandTypeTwoRegisters, OperandTypeRegister}
	OperandTypesThreeRegistersToRegister       = OperandTypes{OperandTypeThreeRegisters, OperandTypeRegister}
	OperandTypesTwoRegistersToNone             = OperandTypes{OperandTypeTwoRegisters, OperandTypeNone}
	OperandTypesRegisterAndConstToNone         = OperandTypes{OperandTypeRegisterAndConst, OperandTypeNone}
	OperandTypesRegisterToMemory               = OperandTypes{OperandTypeRegister, OperandTypeMemory}
	OperandTypesMemoryToRegister               = OperandTypes{OperandTypeMemory, OperandTypeRegister}
	OperandTypesConstToRegister                = OperandTypes{OperandTypeConst, OperandTypeRegister}
	OperandTypesSIMDByteToSIMDByte             = OperandTypes{OperandTypeSIMDByte, OperandTypeSIMDByte}
	OperandTypesSIMDByteToRegister             = OperandTypes{OperandTypeSIMDByte, OperandTypeRegister}
	OperandTypesTwoSIMDBytesToSIMDByteRegister = OperandTypes{OperandTypeTwoSIMDBytes, OperandTypeSIMDByte}
)

Functions

func InstructionName

func InstructionName(i asm.Instruction) string

func RegisterName

func RegisterName(r asm.Register) string

Types

type Assembler

type Assembler interface {
	asm.AssemblerBase

	// CompileJumpToMemory adds jump-type instruction whose destination is stored in the memory address specified by
	// `baseReg`, and returns the corresponding Node in the assembled linked list.
	//
	// Note: this has exactly the same implementation as the same method in asm.AssemblerBase in the homemade assembler.
	// TODO: this will be removed after golang-asm removal.
	CompileJumpToMemory(jmpInstruction asm.Instruction, baseReg asm.Register)

	// CompileMemoryWithRegisterOffsetToRegister adds an instruction where source operand is the memory address
	// specified as `srcBaseReg + srcOffsetReg` and dst is the register `dstReg`.
	CompileMemoryWithRegisterOffsetToRegister(instruction asm.Instruction, srcBaseReg, srcOffsetReg, dstReg asm.Register)

	// CompileRegisterToMemoryWithRegisterOffset adds an instruction where source operand is the register `srcReg`,
	// and the destination is the memory address specified as `dstBaseReg + dstOffsetReg`
	CompileRegisterToMemoryWithRegisterOffset(instruction asm.Instruction, srcReg, dstBaseReg, dstOffsetReg asm.Register)

	// CompileTwoRegistersToRegister adds an instruction where source operands consists of two registers `src1` and `src2`,
	// and the destination is the register `dst`.
	CompileTwoRegistersToRegister(instruction asm.Instruction, src1, src2, dst asm.Register)

	// CompileThreeRegistersToRegister adds an instruction where source operands consist of three registers
	// `src1`, `src2` and `src3`, and destination operands consist of `dst` register.
	CompileThreeRegistersToRegister(instruction asm.Instruction, src1, src2, src3, dst asm.Register)

	// CompileTwoRegistersToNone adds an instruction where source operands consist of two registers `src1` and `src2`,
	// and destination operand is unspecified.
	CompileTwoRegistersToNone(instruction asm.Instruction, src1, src2 asm.Register)

	// CompileRegisterAndConstToNone adds an instruction where source operands consist of one register `src` and
	// constant `srcConst`, and destination operand is unspecified.
	CompileRegisterAndConstToNone(instruction asm.Instruction, src asm.Register, srcConst asm.ConstantValue)

	// CompileLeftShiftedRegisterToRegister adds an instruction where source operand is the "left shifted register"
	// represented as `srcReg << shiftNum` and the destination is the register `dstReg`.
	CompileLeftShiftedRegisterToRegister(
		instruction asm.Instruction,
		shiftedSourceReg asm.Register,
		shiftNum asm.ConstantValue,
		srcReg, dstReg asm.Register,
	)

	// CompileSIMDByteToSIMDByte adds an instruction where source and destination operand is the SIMD register
	// specified as `srcReg.B8` and `dstReg.B8` where `.B8` part of register is called "arrangement".
	// See https://stackoverflow.com/questions/57294672/what-is-arrangement-specifier-16b-8b-in-arm-assembly-language-instructions
	CompileSIMDByteToSIMDByte(instruction asm.Instruction, srcReg, dstReg asm.Register)

	// CompileTwoSIMDBytesToSIMDByteRegister adds an instruction where source operand is two SIMD registers specified as `srcReg1.B8`,
	// and `srcReg2.B8` and the destination is the one SIMD register `dstReg.B8`.
	CompileTwoSIMDBytesToSIMDByteRegister(instruction asm.Instruction, srcReg1, srcReg2, dstReg asm.Register)

	// CompileSIMDByteToRegister adds an instruction where source operand is the SIMD register specified as `srcReg.B8`,
	// and the destination is the register `dstReg`.
	CompileSIMDByteToRegister(instruction asm.Instruction, srcReg, dstReg asm.Register)

	// CompileConditionalRegisterSet adds an instruction to set 1 on dstReg if the condition satisfies,
	// otherwise set 0.
	CompileConditionalRegisterSet(cond asm.ConditionalRegisterState, dstReg asm.Register)
}

Assembler is the interface for arm64 specific assembler.

type AssemblerImpl

type AssemblerImpl struct {
	asm.BaseAssemblerImpl
	Root, Current *NodeImpl
	Buf           *bytes.Buffer
	// contains filtered or unexported fields
}

AssemblerImpl implements Assembler.

func NewAssemblerImpl

func NewAssemblerImpl(temporaryRegister asm.Register) *AssemblerImpl

func (*AssemblerImpl) Assemble

func (a *AssemblerImpl) Assemble() ([]byte, error)

Assemble implements asm.AssemblerBase

func (*AssemblerImpl) Bytes

func (a *AssemblerImpl) Bytes() []byte

Bytes returns the encoded binary.

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) CompileConditionalRegisterSet

func (a *AssemblerImpl) CompileConditionalRegisterSet(cond asm.ConditionalRegisterState, dstReg asm.Register)

CompileConditionalRegisterSet implements Assembler.CompileConditionalRegisterSet

func (*AssemblerImpl) CompileConstToRegister

func (a *AssemblerImpl) CompileConstToRegister(
	instruction asm.Instruction,
	value asm.ConstantValue,
	destinationReg asm.Register,
) (inst asm.Node)

CompileConstToRegister implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileJump

func (a *AssemblerImpl) CompileJump(jmpInstruction asm.Instruction) asm.Node

CompileJump implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileJumpToMemory

func (a *AssemblerImpl) CompileJumpToMemory(jmpInstruction asm.Instruction, baseReg asm.Register)

CompileJumpToMemory implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileJumpToRegister

func (a *AssemblerImpl) CompileJumpToRegister(jmpInstruction asm.Instruction, reg asm.Register)

CompileJumpToRegister implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileLeftShiftedRegisterToRegister

func (a *AssemblerImpl) CompileLeftShiftedRegisterToRegister(
	instruction asm.Instruction,
	shiftedSourceReg asm.Register,
	shiftNum asm.ConstantValue,
	srcReg, dstReg asm.Register,
)

CompileLeftShiftedRegisterToRegister implements Assembler.CompileLeftShiftedRegisterToRegister

func (*AssemblerImpl) CompileMemoryToRegister

func (a *AssemblerImpl) CompileMemoryToRegister(
	instruction asm.Instruction,
	sourceBaseReg asm.Register,
	sourceOffsetConst asm.ConstantValue,
	destinationReg asm.Register,
)

CompileMemoryToRegister implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileMemoryWithRegisterOffsetToRegister

func (a *AssemblerImpl) CompileMemoryWithRegisterOffsetToRegister(
	instruction asm.Instruction,
	srcBaseReg, srcOffsetReg, dstReg asm.Register,
)

CompileMemoryWithRegisterOffsetToRegister implements Assembler.CompileMemoryWithRegisterOffsetToRegister

func (*AssemblerImpl) CompileReadInstructionAddress

func (a *AssemblerImpl) CompileReadInstructionAddress(
	destinationRegister asm.Register,
	beforeAcquisitionTargetInstruction asm.Instruction,
)

CompileReadInstructionAddress implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileRegisterAndConstToNone

func (a *AssemblerImpl) CompileRegisterAndConstToNone(
	instruction asm.Instruction,
	src asm.Register,
	srcConst asm.ConstantValue,
)

CompileRegisterAndConstToNone implements Assembler.CompileRegisterAndConstToNone

func (*AssemblerImpl) CompileRegisterToMemory

func (a *AssemblerImpl) CompileRegisterToMemory(
	instruction asm.Instruction,
	sourceRegister, destinationBaseRegister asm.Register,
	destinationOffsetConst asm.ConstantValue,
)

CompileRegisterToMemory implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileRegisterToMemoryWithRegisterOffset

func (a *AssemblerImpl) CompileRegisterToMemoryWithRegisterOffset(
	instruction asm.Instruction,
	srcReg, dstBaseReg, dstOffsetReg asm.Register,
)

CompileRegisterToMemoryWithRegisterOffset implements Assembler.CompileRegisterToMemoryWithRegisterOffset

func (*AssemblerImpl) CompileRegisterToRegister

func (a *AssemblerImpl) CompileRegisterToRegister(instruction asm.Instruction, from, to asm.Register)

CompileRegisterToRegister implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileSIMDByteToRegister

func (a *AssemblerImpl) CompileSIMDByteToRegister(instruction asm.Instruction, srcReg, dstReg asm.Register)

CompileSIMDByteToRegister implements Assembler.CompileSIMDByteToRegister

func (*AssemblerImpl) CompileSIMDByteToSIMDByte

func (a *AssemblerImpl) CompileSIMDByteToSIMDByte(instruction asm.Instruction, srcReg, dstReg asm.Register)

CompileSIMDByteToSIMDByte implements Assembler.CompileSIMDByteToSIMDByte

func (*AssemblerImpl) CompileStandAlone

func (a *AssemblerImpl) CompileStandAlone(instruction asm.Instruction) asm.Node

CompileStandAlone implements the same method as documented on asm.AssemblerBase.

func (*AssemblerImpl) CompileThreeRegistersToRegister

func (a *AssemblerImpl) CompileThreeRegistersToRegister(
	instruction asm.Instruction,
	src1, src2, src3, dst asm.Register,
)

CompileThreeRegistersToRegister implements Assembler.CompileThreeRegistersToRegister

func (*AssemblerImpl) CompileTwoRegistersToNone

func (a *AssemblerImpl) CompileTwoRegistersToNone(instruction asm.Instruction, src1, src2 asm.Register)

CompileTwoRegistersToNone implements Assembler.CompileTwoRegistersToNone

func (*AssemblerImpl) CompileTwoRegistersToRegister

func (a *AssemblerImpl) CompileTwoRegistersToRegister(instruction asm.Instruction, src1, src2, dst asm.Register)

CompileTwoRegistersToRegister implements Assembler.CompileTwoRegistersToRegister

func (*AssemblerImpl) CompileTwoSIMDBytesToSIMDByteRegister

func (a *AssemblerImpl) CompileTwoSIMDBytesToSIMDByteRegister(
	instruction asm.Instruction,
	srcReg1, srcReg2, dstReg asm.Register,
)

CompileTwoSIMDBytesToSIMDByteRegister implements Assembler.CompileTwoSIMDBytesToSIMDByteRegister

func (*AssemblerImpl) EncodeConstToRegister

func (a *AssemblerImpl) EncodeConstToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeJumpToRegister

func (a *AssemblerImpl) EncodeJumpToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeLeftShiftedRegisterToRegister

func (a *AssemblerImpl) EncodeLeftShiftedRegisterToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeMemoryToRegister

func (a *AssemblerImpl) EncodeMemoryToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeNode

func (a *AssemblerImpl) EncodeNode(n *NodeImpl) (err error)

EncodeNode encodes the given node into writer.

func (*AssemblerImpl) EncodeNoneToNone

func (a *AssemblerImpl) EncodeNoneToNone(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeRegisterAndConstToNone

func (a *AssemblerImpl) EncodeRegisterAndConstToNone(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeRegisterToMemory

func (a *AssemblerImpl) EncodeRegisterToMemory(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeRegisterToRegister

func (a *AssemblerImpl) EncodeRegisterToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeRelativeBranch

func (a *AssemblerImpl) EncodeRelativeBranch(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeSIMDByteToRegister

func (a *AssemblerImpl) EncodeSIMDByteToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeSIMDByteToSIMDByte

func (a *AssemblerImpl) EncodeSIMDByteToSIMDByte(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeThreeRegistersToRegister

func (a *AssemblerImpl) EncodeThreeRegistersToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeTwoRegistersToNone

func (a *AssemblerImpl) EncodeTwoRegistersToNone(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeTwoRegistersToRegister

func (a *AssemblerImpl) EncodeTwoRegistersToRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

func (*AssemblerImpl) EncodeTwoSIMDBytesToSIMDByteRegister

func (a *AssemblerImpl) EncodeTwoSIMDBytesToSIMDByteRegister(n *NodeImpl) (err error)

Exported for inter-op testing with golang-asm. TODO: unexport after golang-asm complete removal.

type NodeImpl

type NodeImpl struct {
	Instruction asm.Instruction

	OffsetInBinaryField asm.NodeOffsetInBinary // Field suffix to dodge conflict with OffsetInBinary

	// JumpTarget holds the target node in the linked for the jump-kind instruction.
	JumpTarget *NodeImpl
	// next holds the next node from this node in the assembled linked list.
	Next *NodeImpl

	Types                            OperandTypes
	SrcReg, SrcReg2, DstReg, DstReg2 asm.Register
	SrcConst, DstConst               asm.ConstantValue

	// JumpOrigins hold all the nodes trying to jump into this node. In other words, all the nodes with .JumpTarget == this.
	JumpOrigins map[*NodeImpl]struct{}
	// contains filtered or unexported fields
}

func (*NodeImpl) AssignDestinationConstant

func (n *NodeImpl) AssignDestinationConstant(value asm.ConstantValue)

AssignDestinationConstant implements the same method as documented on asm.Node.

func (*NodeImpl) AssignJumpTarget

func (n *NodeImpl) AssignJumpTarget(target asm.Node)

AssignJumpTarget implements the same method as documented on asm.Node.

func (*NodeImpl) AssignSourceConstant

func (n *NodeImpl) AssignSourceConstant(value asm.ConstantValue)

AssignSourceConstant implements the same method as documented on asm.Node.

func (*NodeImpl) OffsetInBinary

func (n *NodeImpl) OffsetInBinary() asm.NodeOffsetInBinary

OffsetInBinary implements the same method as documented on asm.Node.

func (*NodeImpl) String

func (n *NodeImpl) String() (ret string)

String implements fmt.Stringer.

This is for debugging purpose, and the format is similar to the AT&T assembly syntax, meaning that this should look like "INSTRUCTION ${from}, ${to}" where each operand might be embraced by '[]' to represent the memory location, and multiple operands are embraced by `()`.

type OperandType

type OperandType byte

OperandType represents where an operand is placed for an instruction. Note: this is almost the same as obj.AddrType in GO assembler.

const (
	OperandTypeNone OperandType = iota
	OperandTypeRegister
	OperandTypeLeftShiftedRegister
	OperandTypeTwoRegisters
	OperandTypeThreeRegisters
	OperandTypeRegisterAndConst
	OperandTypeMemory
	OperandTypeConst
	OperandTypeBranch
	OperandTypeSIMDByte
	OperandTypeTwoSIMDBytes
)

func (OperandType) String

func (o OperandType) String() (ret string)

String implements fmt.Stringer.

type OperandTypes

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

OperandTypes represents the only combinations of two OperandTypes used by wazero

func (OperandTypes) String

func (o OperandTypes) String() string

String implements fmt.Stringer

Jump to

Keyboard shortcuts

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