From 591e20c7ecdfcc4fce264a0e8aa6bca2a3ff0e69 Mon Sep 17 00:00:00 2001 From: Trivalik_cp <42497cfff885d3ca0e6fda54fb6262dd42101bd5sx56jUzf> Date: Tue, 24 May 2011 20:28:57 +0000 Subject: [PATCH] add convertSD2SI, mov double dupplicate (without 64 bit support no other way found) fix conv.i4 for case: double k = 50.5; int k2 = (int)k; --- .../Cosmos.Compiler.Assembler.X86.csproj | 5 +++-- .../SSE2/ConvertSD2SI.cs | 7 +++++++ .../{x87 => SSE3}/IntStoreWithTrunc.cs | 0 .../SSE3/MoveDoubleAndDupplicate.cs | 7 +++++++ .../IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs | 20 +++++++++++++------ 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE2/ConvertSD2SI.cs rename source2/Compiler/Cosmos.Compiler.Assembler.X86/{x87 => SSE3}/IntStoreWithTrunc.cs (100%) create mode 100644 source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/MoveDoubleAndDupplicate.cs diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj b/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj index dd3a7051e..7c4a22a92 100644 --- a/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj +++ b/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj @@ -126,9 +126,11 @@ + + @@ -212,7 +214,7 @@ - + @@ -258,7 +260,6 @@ - diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE2/ConvertSD2SI.cs b/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE2/ConvertSD2SI.cs new file mode 100644 index 000000000..41194d2ec --- /dev/null +++ b/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE2/ConvertSD2SI.cs @@ -0,0 +1,7 @@ +namespace Cosmos.Compiler.Assembler.X86.SSE +{ + [OpCode("CVTSD2SI")] + public class ConvertSD2SI : InstructionWithDestinationAndSource + { + } +} \ No newline at end of file diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/x87/IntStoreWithTrunc.cs b/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/IntStoreWithTrunc.cs similarity index 100% rename from source2/Compiler/Cosmos.Compiler.Assembler.X86/x87/IntStoreWithTrunc.cs rename to source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/IntStoreWithTrunc.cs diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/MoveDoubleAndDupplicate.cs b/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/MoveDoubleAndDupplicate.cs new file mode 100644 index 000000000..12fb5d5b2 --- /dev/null +++ b/source2/Compiler/Cosmos.Compiler.Assembler.X86/SSE3/MoveDoubleAndDupplicate.cs @@ -0,0 +1,7 @@ +namespace Cosmos.Compiler.Assembler.X86.SSE +{ + [OpCode("MOVDDUP")] + public class MoveDoubleAndDupplicate : InstructionWithDestinationAndSource + { + } +} \ No newline at end of file diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs index fec00027c..2756a134e 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs @@ -17,12 +17,7 @@ namespace Cosmos.IL2CPU.X86.IL public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) { var xSource = Assembler.Stack.Pop(); - if (xSource.IsFloat) - { - new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; - } + switch( xSource.Size ) { @@ -30,10 +25,23 @@ namespace Cosmos.IL2CPU.X86.IL case 2: case 4: { + if (xSource.IsFloat) + { + new CPUx86.SSE.MoveSS { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSS2SI { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } break; } case 8: { + if (xSource.IsFloat) + { + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SI { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };