github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/isa/arm64/abi_test.go (about) 1 package arm64 2 3 import ( 4 "testing" 5 6 "github.com/tetratelabs/wazero/internal/engine/wazevo/backend" 7 "github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc" 8 "github.com/tetratelabs/wazero/internal/engine/wazevo/ssa" 9 "github.com/tetratelabs/wazero/internal/testing/require" 10 ) 11 12 func TestMachine_insertAddOrSubStackPointer(t *testing.T) { 13 t.Run("add/small", func(t *testing.T) { 14 _, _, m := newSetupWithMockContext() 15 m.insertAddOrSubStackPointer(spVReg, 0x10, true) 16 require.Equal(t, `add sp, sp, #0x10`, formatEmittedInstructionsInCurrentBlock(m)) 17 }) 18 t.Run("add/large stack", func(t *testing.T) { 19 _, _, m := newSetupWithMockContext() 20 m.insertAddOrSubStackPointer(spVReg, 0xffffffff_8, true) 21 require.Equal(t, `orr x27, xzr, #0xffffffff8 22 add sp, sp, x27`, formatEmittedInstructionsInCurrentBlock(m)) 23 }) 24 t.Run("sub/small", func(t *testing.T) { 25 _, _, m := newSetupWithMockContext() 26 m.insertAddOrSubStackPointer(spVReg, 0x10, false) 27 require.Equal(t, `sub sp, sp, #0x10`, formatEmittedInstructionsInCurrentBlock(m)) 28 }) 29 t.Run("sub/large stack", func(t *testing.T) { 30 _, _, m := newSetupWithMockContext() 31 m.insertAddOrSubStackPointer(spVReg, 0xffffffff_8, false) 32 require.Equal(t, `orr x27, xzr, #0xffffffff8 33 sub sp, sp, x27`, formatEmittedInstructionsInCurrentBlock(m)) 34 }) 35 } 36 37 func TestAbiImpl_callerGenVRegToFunctionArg_constant_inlining(t *testing.T) { 38 _, builder, m := newSetupWithMockContext() 39 40 i64 := builder.AllocateInstruction().AsIconst64(10).Insert(builder) 41 f64 := builder.AllocateInstruction().AsF64const(3.14).Insert(builder) 42 abi := &backend.FunctionABI{} 43 abi.Init(&ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeF64}}, intParamResultRegs, floatParamResultRegs) 44 m.callerGenVRegToFunctionArg(abi, 0, regalloc.VReg(100).SetRegType(regalloc.RegTypeInt), &backend.SSAValueDefinition{Instr: i64, RefCount: 1}, 0) 45 m.callerGenVRegToFunctionArg(abi, 1, regalloc.VReg(50).SetRegType(regalloc.RegTypeFloat), &backend.SSAValueDefinition{Instr: f64, RefCount: 1}, 0) 46 require.Equal(t, `movz x100?, #0xa, lsl 0 47 mov x0, x100? 48 ldr d50?, #8; b 16; data.f64 3.140000 49 mov v0.8b, v50?.8b`, formatEmittedInstructionsInCurrentBlock(m)) 50 }