github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/asm/arm64/assembler.go (about) 1 package arm64 2 3 import ( 4 "github.com/wasilibs/wazerox/internal/asm" 5 ) 6 7 // Assembler is the interface for arm64 specific assembler. 8 type Assembler interface { 9 asm.AssemblerBase 10 11 // CompileMemoryWithRegisterOffsetToRegister adds an instruction where source operand is the memory address 12 // specified as `srcBaseReg + srcOffsetReg` and dst is the register `dstReg`. 13 CompileMemoryWithRegisterOffsetToRegister(instruction asm.Instruction, srcBaseReg, srcOffsetReg, dstReg asm.Register) 14 15 // CompileMemoryWithRegisterSourceToRegister adds an instruction where source operand is the memory address 16 // and dst is the register `dstReg`. 17 CompileMemoryWithRegisterSourceToRegister(instruction asm.Instruction, srcReg, dstReg asm.Register) 18 19 // CompileRegisterToMemoryWithRegisterOffset adds an instruction where source operand is the register `srcReg`, 20 // and the destination is the memory address specified as `dstBaseReg + dstOffsetReg` 21 CompileRegisterToMemoryWithRegisterOffset(instruction asm.Instruction, srcReg, dstBaseReg, dstOffsetReg asm.Register) 22 23 // CompileRegisterToMemoryWithRegisterDest adds an instruction where source operand is the register `srcReg`, 24 // and the destination is the memory address specified as `dstReg` 25 CompileRegisterToMemoryWithRegisterDest(instruction asm.Instruction, srcReg, dstReg asm.Register) 26 27 // CompileTwoRegistersToRegister adds an instruction where source operands consists of two registers `src1` and `src2`, 28 // and the destination is the register `dst`. 29 CompileTwoRegistersToRegister(instruction asm.Instruction, src1, src2, dst asm.Register) 30 31 // CompileThreeRegistersToRegister adds an instruction where source operands consist of three registers 32 // `src1`, `src2` and `src3`, and destination operands consist of `dst` register. 33 CompileThreeRegistersToRegister(instruction asm.Instruction, src1, src2, src3, dst asm.Register) 34 35 // CompileTwoRegistersToNone adds an instruction where source operands consist of two registers `src1` and `src2`, 36 // and destination operand is unspecified. 37 CompileTwoRegistersToNone(instruction asm.Instruction, src1, src2 asm.Register) 38 39 // CompileRegisterAndConstToNone adds an instruction where source operands consist of one register `src` and 40 // constant `srcConst`, and destination operand is unspecified. 41 CompileRegisterAndConstToNone(instruction asm.Instruction, src asm.Register, srcConst asm.ConstantValue) 42 43 // CompileRegisterAndConstToRegister adds an instruction where source operands consist of one register `src` and 44 // constant `srcConst`, and destination operand is a register `dst`. 45 CompileRegisterAndConstToRegister(instruction asm.Instruction, src asm.Register, srcConst asm.ConstantValue, dst asm.Register) 46 47 // CompileLeftShiftedRegisterToRegister adds an instruction where source operand is the "left shifted register" 48 // represented as `srcReg << shiftNum` and the destination is the register `dstReg`. 49 CompileLeftShiftedRegisterToRegister( 50 instruction asm.Instruction, 51 shiftedSourceReg asm.Register, 52 shiftNum asm.ConstantValue, 53 srcReg, dstReg asm.Register, 54 ) 55 56 // CompileConditionalRegisterSet adds an instruction to set 1 on dstReg if the condition satisfies, 57 // otherwise set 0. 58 CompileConditionalRegisterSet(cond asm.ConditionalRegisterState, dstReg asm.Register) 59 60 // CompileMemoryToVectorRegister adds an instruction where source operands is the memory address specified by 61 // `srcBaseReg+srcOffset` and the destination is `dstReg` vector register. 62 CompileMemoryToVectorRegister(instruction asm.Instruction, srcBaseReg asm.Register, srcOffset asm.ConstantValue, 63 dstReg asm.Register, arrangement VectorArrangement) 64 65 // CompileMemoryWithRegisterOffsetToVectorRegister is the same as CompileMemoryToVectorRegister except that the 66 // offset is specified by the `srcOffsetRegister` register. 67 CompileMemoryWithRegisterOffsetToVectorRegister(instruction asm.Instruction, srcBaseReg, 68 srcOffsetRegister asm.Register, dstReg asm.Register, arrangement VectorArrangement) 69 70 // CompileVectorRegisterToMemory adds an instruction where source operand is `srcReg` vector register and the 71 // destination is the memory address specified by `dstBaseReg+dstOffset`. 72 CompileVectorRegisterToMemory(instruction asm.Instruction, srcReg, dstBaseReg asm.Register, 73 dstOffset asm.ConstantValue, arrangement VectorArrangement) 74 75 // CompileVectorRegisterToMemoryWithRegisterOffset is the same as CompileVectorRegisterToMemory except that the 76 // offset is specified by the `dstOffsetRegister` register. 77 CompileVectorRegisterToMemoryWithRegisterOffset(instruction asm.Instruction, srcReg, dstBaseReg, 78 dstOffsetRegister asm.Register, arrangement VectorArrangement) 79 80 // CompileRegisterToVectorRegister adds an instruction where source operand is `srcReg` general purpose register and 81 // the destination is the `dstReg` vector register. The destination vector's arrangement and index of element can be 82 // given by `arrangement` and `index`, but not all the instructions will use them. 83 CompileRegisterToVectorRegister(instruction asm.Instruction, srcReg, dstReg asm.Register, 84 arrangement VectorArrangement, index VectorIndex) 85 86 // CompileVectorRegisterToRegister adds an instruction where destination operand is `dstReg` general purpose register 87 // and the source is the `srcReg` vector register. The source vector's arrangement and index of element can be 88 // given by `arrangement` and `index`, but not all the instructions will use them. 89 CompileVectorRegisterToRegister(instruction asm.Instruction, srcReg, dstReg asm.Register, 90 arrangement VectorArrangement, index VectorIndex) 91 92 // CompileVectorRegisterToVectorRegister adds an instruction where both source and destination operands are vector 93 // registers. The vector's arrangement can be specified `arrangement`, and the source and destination element's 94 // index are given by `srcIndex` and `dstIndex` respectively, but not all the instructions will use them. 95 CompileVectorRegisterToVectorRegister(instruction asm.Instruction, srcReg, dstReg asm.Register, 96 arrangement VectorArrangement, srcIndex, dstIndex VectorIndex) 97 98 // CompileVectorRegisterToVectorRegisterWithConst is the same as CompileVectorRegisterToVectorRegister but the 99 // additional constant can be provided. 100 // For example, the const can be used to specify the shift amount for USHLL instruction. 101 CompileVectorRegisterToVectorRegisterWithConst(instruction asm.Instruction, srcReg, dstReg asm.Register, 102 arrangement VectorArrangement, c asm.ConstantValue) 103 104 // CompileStaticConstToRegister adds an instruction where the source operand is StaticConstant located in 105 // the memory and the destination is the dstReg. 106 CompileStaticConstToRegister(instruction asm.Instruction, c *asm.StaticConst, dstReg asm.Register) 107 108 // CompileStaticConstToVectorRegister adds an instruction where the source operand is StaticConstant located in 109 // the memory and the destination is the dstReg. 110 CompileStaticConstToVectorRegister(instruction asm.Instruction, c *asm.StaticConst, dstReg asm.Register, 111 arrangement VectorArrangement) 112 113 // CompileTwoVectorRegistersToVectorRegister adds an instruction where source are two vectors and destination is one 114 // vector. The vector's arrangement can be specified `arrangement`. 115 CompileTwoVectorRegistersToVectorRegister(instruction asm.Instruction, srcReg, srcReg2, dstReg asm.Register, 116 arrangement VectorArrangement) 117 118 // CompileTwoVectorRegistersToVectorRegisterWithConst is the same as CompileTwoVectorRegistersToVectorRegister except 119 // that this also accept additional constant. 120 // For example EXIT instruction needs the extraction target immediate as const. 121 CompileTwoVectorRegistersToVectorRegisterWithConst(instruction asm.Instruction, srcReg, srcReg2, dstReg asm.Register, 122 arrangement VectorArrangement, c asm.ConstantValue) 123 }