private static void CmpXchg(InstructionNode node, MachineCodeEmitter emitter) { Debug.Assert(node.Result.IsRegister); Debug.Assert(node.Operand1.IsRegister); Debug.Assert(node.Operand2.IsRegister); Debug.Assert(node.GetOperand(3).IsRegister); Debug.Assert(node.Result.Register == GeneralPurposeRegister.EAX); Debug.Assert(node.Operand1.Register == GeneralPurposeRegister.EAX); Debug.Assert(node.ResultCount == 1); var linkreference = node.Operand2.IsLabel || node.Operand2.IsField || node.Operand2.IsSymbol; // Compare EAX with r/m32. If equal, ZF is set and r32 is loaded into r/m32. // Else, clear ZF and load r/m32 into EAX. // memory, register 0000 1111 : 1011 000w : mod reg r/m var opcode = new OpcodeEncoder() .AppendConditionalPrefix(0x66, node.Size == InstructionSize.Size16) // 8:prefix: 16bit .AppendNibble(Bits.b0000) // 4:opcode .AppendNibble(Bits.b1111) // 4:opcode .AppendNibble(Bits.b1011) // 4:opcode .Append3Bits(Bits.b000) // 3:opcode .AppendWidthBit(node.Size != InstructionSize.Size8) // 1:width .ModRegRMSIBDisplacement(node.GetOperand(3), node.Operand2, node.Operand3) // Mod-Reg-RM-?SIB-?Displacement .AppendConditionalIntegerValue(0, linkreference); // 32:memory if (linkreference) emitter.Emit(opcode, node.Operand1, (opcode.Size - 32) / 8); else emitter.Emit(opcode); }
/// <summary> /// Emits the constant operands. /// </summary> /// <param name="node">The node.</param> protected void EmitFloatingPointConstants(InstructionNode node) { for (int i = 0; i < node.OperandCount; i++) { var operand = node.GetOperand(i); if (operand == null || !operand.IsConstant || !operand.IsR) continue; if (operand.IsUnresolvedConstant) continue; var v1 = AllocateVirtualRegister(operand.Type); var symbol = (operand.IsR4) ? MethodCompiler.Linker.GetConstantSymbol(operand.ConstantSingleFloatingPoint) : MethodCompiler.Linker.GetConstantSymbol(operand.ConstantDoubleFloatingPoint); var s1 = Operand.CreateLabel(operand.Type, symbol.Name); var before = new Context(node).InsertBefore(); if (operand.IsR4) { before.SetInstruction(X86.MovssLoad, InstructionSize.Size32, v1, s1, ConstantZero); } else { before.SetInstruction(X86.MovsdLoad, InstructionSize.Size64, v1, s1, ConstantZero); } node.SetOperand(i, v1); } }
/// <summary> /// Returns a <see cref="System.String" /> that represents this instance. /// </summary> /// <param name="node">The context.</param> /// <returns> /// A <see cref="System.String" /> that represents this instance. /// </returns> public string ToString(InstructionNode node) { var sb = new StringBuilder(); sb.AppendFormat("L_{0:X4}", node.Label); if (node.Marked) sb.Append('*'); else sb.Append(' '); sb.Append(ToString()); var size = GetSizeString(node.Size); if (size != string.Empty) sb.Append("/" + size); if (node.ConditionCode != ConditionCode.Undefined) { sb.Append(" ["); sb.Append(GetConditionString(node.ConditionCode)); sb.Append("]"); } if (node.MosaType != null) { sb.Append(" [["); sb.Append(node.MosaType.FullName); sb.Append("]]"); } if (node.MosaField != null) { sb.Append(" [["); sb.Append(node.MosaField.FullName); sb.Append("]]"); } string mod = GetModifier(node); if (mod != null) { sb.Append(" ["); sb.Append(mod); sb.Append("]"); } for (int i = 0; i < node.ResultCount; i++) { var op = node.GetResult(i); sb.Append(" "); sb.Append(op == null ? "[NULL]" : op.ToString()); sb.Append(","); } if (node.ResultCount > 0) { sb.Length = sb.Length - 1; } if (node.ResultCount > 0 && node.OperandCount > 0) { sb.Append(" <="); } for (int i = 0; i < node.OperandCount; i++) { var op = node.GetOperand(i); sb.Append(" "); sb.Append(op == null ? "[NULL]" : op.ToString()); sb.Append(","); } if (node.OperandCount > 0) { sb.Length = sb.Length - 1; } if (node.BranchTargets != null) { sb.Append(' '); for (int i = 0; (i < 2) && (i < node.BranchTargetsCount); i++) { if (i != 0) { sb.Append(", "); } sb.Append(node.BranchTargets[i].ToString()); } if (node.BranchTargetsCount > 2) { sb.Append(", [more]"); } } if (node.InvokeMethod != null) { sb.Append(" {"); sb.Append(node.InvokeMethod.FullName); sb.Append("}"); } if (node.MosaField != null) { sb.Append(" {"); sb.Append(node.MosaField.FullName); sb.Append("}"); } return sb.ToString(); }
/// <summary> /// Returns a <see cref="System.String" /> that represents this instance. /// </summary> /// <param name="node">The context.</param> /// <returns> /// A <see cref="System.String" /> that represents this instance. /// </returns> public string ToString(InstructionNode node) { var sb = new StringBuilder(); sb.AppendFormat("L_{0:X4}", node.Label); if (node.Marked) { sb.Append('*'); } else { sb.Append(' '); } sb.Append(ToString()); var size = GetSizeString(node.Size); if (size != string.Empty) { sb.Append("/" + size); } if (node.ConditionCode != ConditionCode.Undefined) { sb.Append(" ["); sb.Append(GetConditionString(node.ConditionCode)); sb.Append("]"); } if (node.MosaType != null) { sb.Append(" [["); sb.Append(node.MosaType.FullName); sb.Append("]]"); } if (node.MosaField != null) { sb.Append(" [["); sb.Append(node.MosaField.FullName); sb.Append("]]"); } string mod = GetModifier(node); if (mod != null) { sb.Append(" ["); sb.Append(mod); sb.Append("]"); } for (int i = 0; i < node.ResultCount; i++) { var op = node.GetResult(i); sb.Append(" "); sb.Append(op == null ? "[NULL]" : op.ToString()); sb.Append(","); } if (node.ResultCount > 0) { sb.Length = sb.Length - 1; } if (node.ResultCount > 0 && node.OperandCount > 0) { sb.Append(" <="); } for (int i = 0; i < node.OperandCount; i++) { var op = node.GetOperand(i); sb.Append(" "); sb.Append(op == null ? "[NULL]" : op.ToString()); sb.Append(","); } if (node.OperandCount > 0) { sb.Length = sb.Length - 1; } if (node.BranchTargets != null) { sb.Append(' '); for (int i = 0; (i < 2) && (i < node.BranchTargetsCount); i++) { if (i != 0) { sb.Append(", "); } sb.Append(node.BranchTargets[i].ToString()); } if (node.BranchTargetsCount > 2) { sb.Append(", [more]"); } } if (node.InvokeMethod != null) { sb.Append(" {"); sb.Append(node.InvokeMethod.FullName); sb.Append("}"); } if (node.MosaField != null) { sb.Append(" {"); sb.Append(node.MosaField.FullName); sb.Append("}"); } return(sb.ToString()); }