mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
- Fixed Single.ToString() on special cases (infinities, NaN and 0) and aumented the range of printable values - Fixed Double.ToString(): it always printed "Double Overrange" for a bug in opcode ldarga - Fixed opcode ldarga: the displacement of the argument variable was off of 4 bytes - Fixed opcodes shr, shr_un and shl when the shift was more that 32 bytes, added to BCL relative tests - Added BLC tests regarding BitConverter and unsafe code - Moved the meat of the code of Single.ToString() and Double.ToString() to the class StringHelper together with the analogous methods for numer types - Re-added _floatsignbit to CosmosAssembler.cs so the neg test should not fail anymore - Removed all code relative to x87 that I had left under #if false - Clean up
75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using System;
|
|
using CPUx86 = Cosmos.Assembler.x86;
|
|
using Cosmos.Assembler.x86;
|
|
using Cosmos.Assembler.x86.x87;
|
|
using XSharp.Compiler;
|
|
using static XSharp.Compiler.XSRegisters;
|
|
|
|
namespace Cosmos.IL2CPU.X86.IL
|
|
{
|
|
[Cosmos.IL2CPU.OpCode(ILOpCode.Code.Sub)]
|
|
public class Sub: ILOp
|
|
{
|
|
public Sub(Cosmos.Assembler.Assembler aAsmblr)
|
|
: base(aAsmblr)
|
|
{
|
|
}
|
|
|
|
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
|
|
{
|
|
var xStackTop = aOpCode.StackPopTypes[0];
|
|
var xStackTop2 = aOpCode.StackPopTypes[0];
|
|
var xStackTopSize = SizeOfType(xStackTop);
|
|
var xStackTop2Size = SizeOfType(xStackTop2);
|
|
if (xStackTopSize != xStackTop2Size)
|
|
{
|
|
throw new Exception("Different size for substract: " + aMethod.MethodBase + "!");
|
|
}
|
|
|
|
var xStackTopIsFloat = TypeIsFloat(xStackTop);
|
|
|
|
switch (xStackTopSize)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 4:
|
|
if (xStackTopIsFloat)
|
|
{
|
|
XS.SSE.MoveSS(XMM0, ESP, sourceIsIndirect: true);
|
|
XS.Add(ESP, 4);
|
|
XS.SSE.MoveSS(XMM1, ESP, sourceIsIndirect: true);
|
|
//XS.LiteralCode("movss XMM1, [ESP + 4]");
|
|
XS.SSE.SubSS(XMM1, XMM0);
|
|
XS.SSE.MoveSS(ESP, XMM1, destinationIsIndirect: true);
|
|
}
|
|
else
|
|
{
|
|
XS.Pop(XSRegisters.ECX);
|
|
XS.Pop(XSRegisters.EAX);
|
|
XS.Sub(XSRegisters.EAX, XSRegisters.ECX);
|
|
XS.Push(XSRegisters.EAX);
|
|
}
|
|
break;
|
|
case 8:
|
|
if (xStackTopIsFloat)
|
|
{
|
|
XS.SSE2.MoveSD(XMM0, ESP, sourceIsIndirect: true);
|
|
XS.Add(ESP, 8);
|
|
XS.SSE2.MoveSD(XMM1, ESP, sourceIsIndirect: true);
|
|
XS.SSE2.SubSD(XMM1, XMM0);
|
|
XS.SSE2.MoveSD(ESP, XMM1, destinationIsIndirect: true);
|
|
}
|
|
else
|
|
{
|
|
XS.Pop(EAX);
|
|
XS.Pop(EDX);
|
|
XS.Sub(ESP, EAX, destinationIsIndirect: true);
|
|
XS.SubWithCarry(ESP, EDX, destinationDisplacement: 4);
|
|
}
|
|
break;
|
|
default:
|
|
throw new NotImplementedException("not implemented");
|
|
}
|
|
}
|
|
}
|
|
}
|