/
Conv_U4.cs
75 lines (71 loc) · 2.27 KB
/
Conv_U4.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using XSharp;
using XSharp.Assembler;
using static XSharp.XSRegisters;
namespace Cosmos.IL2CPU.X86.IL
{
/// <summary>
/// Convert to unsigned int32, pushing int32 on stack.
/// </summary>
[OpCode(ILOpCode.Code.Conv_U4)]
public class Conv_U4 : ILOp
{
public Conv_U4(Assembler aAsmblr)
: base(aAsmblr)
{
}
public override void Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode)
{
var xSource = aOpCode.StackPopTypes[0];
DoExecute(SizeOfType(xSource), TypeIsFloat(xSource), TypeIsSigned(xSource), false, Assembler, aMethod, aOpCode);
}
public static void DoExecute(uint xSourceSize, bool xSourceIsFloat, bool xSourceIsSigned, bool checkOverflow, Assembler assembler, Il2cpuMethodInfo aMethod, ILOpCode aOpCode)
{
var xBaseLabel = GetLabel(aMethod, aOpCode) + ".";
var xSuccessLabel = xBaseLabel + "Success";
var xOverflowLabel = xBaseLabel + "Overflow";
var xPositiveLabel = xBaseLabel + "Positive";
var xNegativeLabel = xBaseLabel + "Negative";
if (xSourceSize <= 4)
{
if (xSourceIsFloat)
{
XS.SSE.MoveSS(XMM0, ESP, sourceIsIndirect: true);
XS.SSE.ConvertSS2SIAndTruncate(EAX, XMM0);
XS.Set(ESP, EAX, destinationIsIndirect: true);
}
else
{
if (checkOverflow)
{
ConvOverflowChecks.CheckOverflowForSmall(4, xSourceIsSigned, false, assembler, aMethod, aOpCode, xSuccessLabel, xOverflowLabel);
}
}
}
else if (xSourceSize <= 8)
{
if (xSourceIsFloat)
{
XS.SSE2.MoveSD(XMM0, ESP, sourceIsIndirect: true);
XS.Add(ESP, 4);
XS.SSE2.ConvertSD2SIAndTruncate(EAX, XMM0);
XS.Set(ESP, EAX, destinationIsIndirect: true);
}
else
{
if (checkOverflow)
{
ConvOverflowChecks.CheckOverflowForLong(4, xSourceIsSigned, false, assembler, aMethod, aOpCode, xSuccessLabel, xOverflowLabel, xPositiveLabel, xNegativeLabel);
}
XS.Pop(EAX);
XS.Add(ESP, 4);
XS.Push(EAX);
}
}
else
{
throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_U4.cs->Error: StackSize > 8 not supported");
}
}
}
}