github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/asm/amd64/assembler.go (about)

     1  package amd64
     2  
     3  import (
     4  	"github.com/wasilibs/wazerox/internal/asm"
     5  )
     6  
     7  // Assembler is the interface used by amd64 compiler.
     8  type Assembler interface {
     9  	asm.AssemblerBase
    10  
    11  	// CompileJumpToMemory adds jump-type instruction whose destination is stored in the memory address specified by `baseReg+offset`,
    12  	// and returns the corresponding Node in the assembled linked list.
    13  	CompileJumpToMemory(jmpInstruction asm.Instruction, baseReg asm.Register, offset asm.ConstantValue)
    14  
    15  	// CompileRegisterToRegisterWithArg adds an instruction where source and destination
    16  	// are `from` and `to` registers.
    17  	CompileRegisterToRegisterWithArg(instruction asm.Instruction, from, to asm.Register, arg byte)
    18  
    19  	// CompileMemoryWithIndexToRegister adds an instruction where source operand is the memory address
    20  	// specified as `srcBaseReg + srcOffsetConst + srcIndex*srcScale` and destination is the register `dstReg`.
    21  	// Note: sourceScale must be one of 1, 2, 4, 8.
    22  	CompileMemoryWithIndexToRegister(
    23  		instruction asm.Instruction,
    24  		srcBaseReg asm.Register,
    25  		srcOffsetConst int64,
    26  		srcIndex asm.Register,
    27  		srcScale int16,
    28  		dstReg asm.Register,
    29  	)
    30  
    31  	// CompileMemoryWithIndexAndArgToRegister is the same as CompileMemoryWithIndexToRegister except that this
    32  	// also accepts one argument.
    33  	CompileMemoryWithIndexAndArgToRegister(
    34  		instruction asm.Instruction,
    35  		srcBaseReg asm.Register,
    36  		srcOffsetConst int64,
    37  		srcIndex asm.Register,
    38  		srcScale int16,
    39  		dstReg asm.Register,
    40  		arg byte,
    41  	)
    42  
    43  	// CompileRegisterToMemoryWithIndex adds an instruction where source operand is the register `srcReg`,
    44  	// and the destination is the memory address specified as `dstBaseReg + dstOffsetConst + dstIndex*dstScale`
    45  	// Note: dstScale must be one of 1, 2, 4, 8.
    46  	CompileRegisterToMemoryWithIndex(
    47  		instruction asm.Instruction,
    48  		srcReg asm.Register,
    49  		dstBaseReg asm.Register,
    50  		dstOffsetConst int64,
    51  		dstIndex asm.Register,
    52  		dstScale int16,
    53  	)
    54  
    55  	// CompileRegisterToMemoryWithIndexAndArg is the same as CompileRegisterToMemoryWithIndex except that this
    56  	// also accepts one argument.
    57  	CompileRegisterToMemoryWithIndexAndArg(
    58  		instruction asm.Instruction,
    59  		srcReg asm.Register,
    60  		dstBaseReg asm.Register,
    61  		dstOffsetConst int64,
    62  		dstIndex asm.Register,
    63  		dstScale int16,
    64  		arg byte,
    65  	)
    66  
    67  	// CompileRegisterToConst adds an instruction where source operand is the register `srcRegister`,
    68  	// and the destination is the const `value`.
    69  	CompileRegisterToConst(instruction asm.Instruction, srcRegister asm.Register, value int64) asm.Node
    70  
    71  	// CompileRegisterToNone adds an instruction where source operand is the register `register`,
    72  	// and there's no destination operand.
    73  	CompileRegisterToNone(instruction asm.Instruction, register asm.Register)
    74  
    75  	// CompileNoneToRegister adds an instruction where destination operand is the register `register`,
    76  	// and there's no source operand.
    77  	CompileNoneToRegister(instruction asm.Instruction, register asm.Register)
    78  
    79  	// CompileNoneToMemory adds an instruction where destination operand is the memory address specified
    80  	// as `baseReg+offset`. and there's no source operand.
    81  	CompileNoneToMemory(instruction asm.Instruction, baseReg asm.Register, offset int64)
    82  
    83  	// CompileConstToMemory adds an instruction where source operand is the constant `value` and
    84  	// the destination is the memory address specified as `dstBaseReg+dstOffset`.
    85  	CompileConstToMemory(instruction asm.Instruction, value int64, dstBaseReg asm.Register, dstOffset int64) asm.Node
    86  
    87  	// CompileMemoryToConst adds an instruction where source operand is the memory address, and
    88  	// the destination is the constant `value`.
    89  	CompileMemoryToConst(instruction asm.Instruction, srcBaseReg asm.Register, srcOffset int64, value int64) asm.Node
    90  
    91  	// CompileRegisterToMemoryWithIndexAndLock is the same as CompileRegisterToMemoryWithIndex but with LOCK prefix.
    92  	CompileRegisterToMemoryWithIndexAndLock(
    93  		instruction asm.Instruction,
    94  		srcReg asm.Register,
    95  		dstBaseReg asm.Register,
    96  		dstOffsetConst int64,
    97  		dstIndex asm.Register,
    98  		dstScale int16,
    99  	)
   100  
   101  	// CompileStaticConstToRegister adds an instruction where the source operand is asm.StaticConst located in the
   102  	// memory and the destination is the dstReg.
   103  	CompileStaticConstToRegister(instruction asm.Instruction, c *asm.StaticConst, dstReg asm.Register) error
   104  
   105  	// CompileRegisterToStaticConst adds an instruction where the destination operand is asm.StaticConst located in the
   106  	// memory and the source is the srcReg.
   107  	CompileRegisterToStaticConst(instruction asm.Instruction, srcReg asm.Register, c *asm.StaticConst) error
   108  }