mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 22:09:12 +00:00
101 lines
4 KiB
C#
101 lines
4 KiB
C#
using System;
|
|
using CPUx86 = Cosmos.Assembler.x86;
|
|
using CPU = Cosmos.Assembler.x86;
|
|
using Cosmos.Assembler.x86;
|
|
using Cosmos.Assembler;
|
|
using Cosmos.Assembler.x86.SSE;
|
|
using Cosmos.Assembler.x86.x87;
|
|
using XSharp.Compiler;
|
|
using static XSharp.Compiler.XSRegisters;
|
|
|
|
namespace Cosmos.IL2CPU.X86.IL
|
|
{
|
|
[Cosmos.IL2CPU.OpCode( ILOpCode.Code.Clt_Un )]
|
|
public class Clt_Un : ILOp
|
|
{
|
|
public Clt_Un( Cosmos.Assembler.Assembler aAsmblr )
|
|
: base( aAsmblr )
|
|
{
|
|
}
|
|
|
|
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
|
|
{
|
|
var xStackItem = aOpCode.StackPopTypes[0];
|
|
var xStackItemSize = SizeOfType(xStackItem);
|
|
var xStackItemIsFloat = TypeIsFloat(xStackItem);
|
|
if( xStackItemSize > 8 )
|
|
{
|
|
throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Clt_Un.cs->Error: StackSizes > 8 not supported");
|
|
}
|
|
string BaseLabel = GetLabel( aMethod, aOpCode ) + ".";
|
|
string LabelTrue = BaseLabel + "True";
|
|
string LabelFalse = BaseLabel + "False";
|
|
if( xStackItemSize > 4 )
|
|
{
|
|
XS.Set(XSRegisters.ESI, 1);
|
|
// esi = 1
|
|
XS.Xor(XSRegisters.EDI, XSRegisters.EDI);
|
|
// edi = 0
|
|
if (xStackItemIsFloat)
|
|
{
|
|
// value 2
|
|
XS.FPU.FloatLoad(ESP, destinationIsIndirect: true, size: RegisterSize.Long64);
|
|
// value 1
|
|
new FloatLoad { DestinationReg = RegistersEnum.ESP, Size = 64, DestinationDisplacement = 8, DestinationIsIndirect = true };
|
|
XS.FPU.FloatCompareAndSet(ST1);
|
|
// if carry is set, ST(0) < ST(i)
|
|
new ConditionalMove { Condition = ConditionalTestEnum.Below, DestinationReg = RegistersEnum.EDI, SourceReg = RegistersEnum.ESI };
|
|
// pops fpu stack
|
|
XS.FPU.FloatStoreAndPop(ST0);
|
|
XS.FPU.FloatStoreAndPop(ST0);
|
|
XS.Add(XSRegisters.ESP, 16);
|
|
}
|
|
else
|
|
{
|
|
XS.Pop(XSRegisters.EAX);
|
|
XS.Pop(XSRegisters.EDX);
|
|
//value2: EDX:EAX
|
|
XS.Pop(XSRegisters.EBX);
|
|
XS.Pop(XSRegisters.ECX);
|
|
//value1: ECX:EBX
|
|
XS.Sub(XSRegisters.EBX, XSRegisters.EAX);
|
|
XS.SubWithCarry(XSRegisters.ECX, XSRegisters.EDX);
|
|
//result = value1 - value2
|
|
new ConditionalMove { Condition = ConditionalTestEnum.Below, DestinationReg = RegistersEnum.EDI, SourceReg = RegistersEnum.ESI };
|
|
}
|
|
XS.Push(XSRegisters.EDI);
|
|
}
|
|
else
|
|
{
|
|
if (xStackItemIsFloat)
|
|
{
|
|
#warning THIS NEEDS TO BE TESTED!!!
|
|
XS.Comment("TEST TODO");
|
|
XS.SSE.MoveSS(XMM0, ESP, sourceIsIndirect: true);
|
|
XS.Add(XSRegisters.ESP, 4);
|
|
XS.SSE.MoveSS(XMM1, ESP, sourceIsIndirect: true);
|
|
new CompareSS { DestinationReg = RegistersEnum.XMM1, SourceReg = RegistersEnum.XMM0, pseudoOpcode = (byte)ComparePseudoOpcodes.LessThan };
|
|
XS.SSE.MoveSS(XMM1, ESP, sourceIsIndirect: true);
|
|
XS.And(ESP, 1, destinationIsIndirect: true);
|
|
}
|
|
else
|
|
{
|
|
XS.Pop(XSRegisters.ECX);
|
|
XS.Pop(XSRegisters.EAX);
|
|
XS.Push(XSRegisters.ECX);
|
|
XS.Compare(EAX, ESP, sourceIsIndirect: true);
|
|
XS.Jump(ConditionalTestEnum.Below, LabelTrue);
|
|
XS.Jump(LabelFalse);
|
|
XS.Label(LabelTrue );
|
|
XS.Add(XSRegisters.ESP, 4);
|
|
XS.Push(1);
|
|
new Jump { DestinationLabel = GetLabel(aMethod, aOpCode.NextPosition) };
|
|
XS.Label(LabelFalse );
|
|
XS.Add(XSRegisters.ESP, 4);
|
|
XS.Push(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|