public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand1.Definitions[0].Operand1; var t2 = context.Operand1.Definitions[0].Operand2; var t3 = context.Operand2; var t4 = context.Operand3; var e1 = transformContext.CreateConstant(Add32(To32(t2), To32(t3))); context.SetInstruction(IRInstruction.StoreR4, result, t1, e1, t4); }
public override void Transform(Context context, TransformContext transformContext) { Debug.Assert(context.ConditionCode != ConditionCode.Equal); var result = context.Result; var operand1 = context.Operand1; var operand2 = context.Operand2; var branch = context.ConditionCode; var branchUnsigned = context.ConditionCode.GetUnsigned(); var nextBlock = transformContext.Split(context); var newBlocks = transformContext.CreateNewBlockContexts(5, context.Label); TransformContext.UpdatePHIInstructionTargets(nextBlock.Block.NextBlocks, context.Block, nextBlock.Block); var op0Low = transformContext.AllocateVirtualRegister32(); var op0High = transformContext.AllocateVirtualRegister32(); var op1Low = transformContext.AllocateVirtualRegister32(); var op1High = transformContext.AllocateVirtualRegister32(); var resultLow = transformContext.AllocateVirtualRegister32(); context.SetInstruction(IRInstruction.GetLow32, op0Low, operand1); context.AppendInstruction(IRInstruction.GetHigh32, op0High, operand1); context.AppendInstruction(IRInstruction.GetLow32, op1Low, operand2); context.AppendInstruction(IRInstruction.GetHigh32, op1High, operand2); // Compare high context.AppendInstruction(IRInstruction.Branch32, ConditionCode.Equal, null, op0High, op1High, newBlocks[1].Block); context.AppendInstruction(IRInstruction.Jmp, newBlocks[0].Block); newBlocks[0].AppendInstruction(IRInstruction.Branch32, branch, null, op0High, op1High, newBlocks[2].Block); newBlocks[0].AppendInstruction(IRInstruction.Jmp, newBlocks[3].Block); // Compare low newBlocks[1].AppendInstruction(IRInstruction.Branch32, branchUnsigned, null, op0Low, op1Low, newBlocks[2].Block); newBlocks[1].AppendInstruction(IRInstruction.Jmp, newBlocks[3].Block); // Success newBlocks[2].AppendInstruction(IRInstruction.Move32, resultLow, transformContext.CreateConstant((uint)1)); newBlocks[2].AppendInstruction(IRInstruction.Jmp, newBlocks[4].Block); // Failed newBlocks[3].AppendInstruction(IRInstruction.Move32, resultLow, transformContext.ConstantZero32); newBlocks[3].AppendInstruction(IRInstruction.Jmp, newBlocks[4].Block); // Exit newBlocks[4].AppendInstruction(IRInstruction.Move32, result, resultLow); newBlocks[4].AppendInstruction(IRInstruction.Jmp, nextBlock.Block); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand1.Definitions[0].Operand1; var t2 = context.Operand1.Definitions[0].Operand2; var t3 = context.Operand2; var v1 = transformContext.AllocateVirtualRegister(transformContext.I8); var e1 = transformContext.CreateConstant(MulUnsigned64(To64(t2), To64(t3))); context.SetInstruction(IRInstruction.Sub64, v1, t1, e1); context.AppendInstruction(IRInstruction.Compare64x64, ConditionCode.UnsignedLess, result, v1, t2); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand1; var t2 = context.Operand2.Definitions[0].Operand1; var t3 = context.Operand2.Definitions[0].Operand2; var v1 = transformContext.AllocateVirtualRegister(transformContext.I4); var e1 = transformContext.CreateConstant(MulUnsigned32(To32(t3), To32(t1))); context.SetInstruction(IRInstruction.Sub32, v1, t2, e1); context.AppendInstruction(IRInstruction.Compare32x32, ConditionCode.UnsignedLess, result, v1, t3); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand1.Definitions[0].Operand1.Definitions[0].Operand1; var t2 = context.Operand1.Definitions[0].Operand2.Definitions[0].Operand1; var v1 = transformContext.AllocateVirtualRegister(transformContext.I8); var v2 = transformContext.AllocateVirtualRegister(transformContext.I8); var e1 = transformContext.CreateConstant(DivSigned64(ToSigned64(t2), 2)); context.SetInstruction(IRInstruction.Add64, v1, t1, e1); context.AppendInstruction(IRInstruction.Add64, v2, t1, e1); context.AppendInstruction(IRInstruction.MulSigned64, result, v2, v1); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand2.Definitions[0].Operand1.Definitions[0].Operand1; var t2 = context.Operand2.Definitions[0].Operand1.Definitions[0].Operand2; var v1 = transformContext.AllocateVirtualRegister(transformContext.I4); var v2 = transformContext.AllocateVirtualRegister(transformContext.I4); var e1 = transformContext.CreateConstant(DivUnsigned32(To32(t1), 2)); context.SetInstruction(IRInstruction.Add32, v1, t2, e1); context.AppendInstruction(IRInstruction.Add32, v2, t2, e1); context.AppendInstruction(IRInstruction.MulUnsigned32, result, v2, v1); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var t1 = context.Operand1.Definitions[0].Operand1; var t2 = context.Operand1.Definitions[0].Operand2; var t3 = context.Operand2; var e1 = transformContext.CreateConstant(Add32(To32(t2), To32(t3))); //Debug.Assert(t1 != result); if (t1 == result) { throw new CompilerException($"Invalid transformation: {context}"); } context.SetInstruction(IRInstruction.Add32, result, t1, e1); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var address = context.Operand1; var offset = context.Operand2; var resultLow = transformContext.AllocateVirtualRegister32(); var resultHigh = transformContext.AllocateVirtualRegister32(); var offsetLow = transformContext.AllocateVirtualRegister32(); var addressLow = transformContext.AllocateVirtualRegister32(); var offset4 = transformContext.AllocateVirtualRegister32(); context.SetInstruction(IRInstruction.GetLow32, addressLow, address); context.AppendInstruction(IRInstruction.GetLow32, offsetLow, offset); context.AppendInstruction(IRInstruction.Load32, resultLow, addressLow, offset); context.AppendInstruction(IRInstruction.Add32, offset4, offsetLow, transformContext.CreateConstant((uint)4)); context.AppendInstruction(IRInstruction.Load32, resultHigh, addressLow, offset4); context.AppendInstruction(IRInstruction.To64, result, resultLow, resultHigh); }
public override void Transform(Context context, TransformContext transformContext) { var address = context.Operand1; var offset = context.Operand2; var value = context.Operand3; var valueLow = transformContext.AllocateVirtualRegister32(); var valueHigh = transformContext.AllocateVirtualRegister32(); var offsetLow = transformContext.AllocateVirtualRegister32(); var addressLow = transformContext.AllocateVirtualRegister32(); var offset4 = transformContext.AllocateVirtualRegister32(); context.SetInstruction(IRInstruction.GetLow32, valueLow, value); context.AppendInstruction(IRInstruction.GetHigh32, valueHigh, value); context.AppendInstruction(IRInstruction.GetLow32, addressLow, address); context.AppendInstruction(IRInstruction.GetLow32, offsetLow, offset); context.AppendInstruction(IRInstruction.Store32, null, addressLow, offset, valueLow); context.AppendInstruction(IRInstruction.Add32, offset4, offsetLow, transformContext.CreateConstant((uint)4)); context.AppendInstruction(IRInstruction.Store32, null, addressLow, offset4, valueHigh); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var operand1 = context.Operand1; var resultLow = transformContext.AllocateVirtualRegister32(); var resultHigh = transformContext.AllocateVirtualRegister32(); context.SetInstruction(IRInstruction.Move32, resultLow, operand1); context.AppendInstruction(IRInstruction.ArithShiftRight32, resultHigh, resultLow, transformContext.CreateConstant(31)); context.AppendInstruction(IRInstruction.To64, result, resultLow, resultHigh); }
public override void Transform(Context context, TransformContext transformContext) { var operand1 = transformContext.CreateConstant(1); context.SetInstruction(IRInstruction.Move32, context.Result, operand1); }
public override void Transform(Context context, TransformContext transformContext) { var result = context.Result; var operand1 = context.Operand1; transformContext.SplitLongOperand(operand1, out Operand op0Low, out Operand _); var resultLow = transformContext.AllocateVirtualRegister32(); var resultHigh = transformContext.AllocateVirtualRegister32(); context.SetInstruction(IRInstruction.LoadParamSignExtend8x32, resultLow, op0Low); context.AppendInstruction(IRInstruction.ArithShiftRight32, resultHigh, resultLow, transformContext.CreateConstant(31)); context.AppendInstruction(IRInstruction.To64, result, resultLow, resultHigh); }
public override void Transform(Context context, TransformContext transformContext) { var constant = transformContext.CreateConstant(-context.Operand2.ConstantSigned32); context.SetInstruction(X86.Lea32, context.Result, context.Operand1, constant); }