Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - x86 Platform #1106

Merged
merged 12 commits into from
Aug 7, 2023
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Data/X64-Instructions.json
Original file line number Diff line number Diff line change
@@ -735,7 +735,7 @@
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],opcode=0xF2,opcode2=0x0F,opcode3=0x5A,mod=11,reg=reg3:o1,rm=reg3:o2,rex.r=reg4x:o1,rex.x=0,rex.b=reg4x:o1"
"Encoding": "[x64-rex32],opcode=0xF2,opcode2=0x0F,opcode3=0x5A,mod=11,reg=reg3:r,rm=reg3:o1,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o1"
}
]
},
2 changes: 1 addition & 1 deletion Source/Mosa.BareMetal.HelloWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public static void Main()

// var fatFileStream = new FatFileStream(fat, location);

// uint len = (uint)fatFileStream.Length;
// var len = (uint)fatFileStream.Length;

// Console.WriteLine(" - Length: " + len + " bytes");

7 changes: 7 additions & 0 deletions Source/Mosa.Compiler.Framework/Stages/CILDecoderStage.cs
Original file line number Diff line number Diff line change
@@ -1849,6 +1849,13 @@ private bool Compare(Context context, Stack<StackEntry> stack, ConditionCode con
context.AppendInstruction(IRInstruction.Compare64x32, conditionCode, result, entry1.Operand, entry2.Operand);
return true;

case PrimitiveType.Int64 when entry2.PrimitiveType == PrimitiveType.Int32:
var v1 = MethodCompiler.VirtualRegisters.Allocate64();

context.AppendInstruction(IRInstruction.ZeroExtend32x64, v1, entry2.Operand);
context.AppendInstruction(IRInstruction.Compare64x32, conditionCode, result, entry1.Operand, v1);
return true;

default:

// TODO: Managed Pointers
4 changes: 2 additions & 2 deletions Source/Mosa.Platform.x64/Instructions/Cvtsd2ss.cs
Original file line number Diff line number Diff line change
@@ -25,14 +25,14 @@ public override void Emit(InstructionNode node, OpcodeEncoder opcodeEncoder)
opcodeEncoder.SuppressByte(0x40);
opcodeEncoder.Append4Bits(0b0100);
opcodeEncoder.Append1Bit(0b0);
opcodeEncoder.Append1Bit(node.Operand1.Register.RegisterCode >> 3);
opcodeEncoder.Append1Bit(node.Result.Register.RegisterCode >> 3);
opcodeEncoder.Append1Bit(0b0);
opcodeEncoder.Append1Bit(node.Operand1.Register.RegisterCode >> 3);
opcodeEncoder.Append8Bits(0xF2);
opcodeEncoder.Append8Bits(0x0F);
opcodeEncoder.Append8Bits(0x5A);
opcodeEncoder.Append2Bits(0b11);
opcodeEncoder.Append3Bits(node.Result.Register.RegisterCode);
opcodeEncoder.Append3Bits(node.Operand1.Register.RegisterCode);
opcodeEncoder.Append3Bits(node.Operand2.Register.RegisterCode);
}
}
18 changes: 0 additions & 18 deletions Source/Mosa.Platform.x64/Intrinsic/SuppressStackFrame.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Platform.x64.Transforms.AddressMode;
using Mosa.Platform.x64.Transforms.FixedRegisters;
using Mosa.Platform.x64.Transforms.Optimizations.Manual.Special;
using Mosa.Platform.x64.Transforms.Stack;
using Mosa.Platform.x64.Transforms.Tweak;

@@ -20,6 +22,13 @@ public PlatformTransformationStage()
AddTranforms(TweakTransforms.List);
AddTranforms(FixedRegistersTransforms.List);
AddTranforms(StackTransforms.List);
AddTranforms(AddressModeTransforms.List);
AddTranforms(SpecialTransforms.List);

AddTranform(new Mov32Unless());
AddTranform(new Mov64Unless());
AddTranform(new Mov32Coalescing());
AddTranform(new Mov64Coalescing());
AddTranform(new Deadcode());
}
}
29 changes: 29 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/AddCarryIn64.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// AddCarryIn64
/// </summary>
[Transform("x64.IR")]
public sealed class AddCarryIn64 : BaseIRTransform
{
public AddCarryIn64() : base(IRInstruction.AddCarryIn64, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var operand1 = context.Operand1;
var operand2 = context.Operand2;
var operand3 = context.Operand3;

var v1 = transform.VirtualRegisters.Allocate64();

context.SetInstruction(X64.Bt32, v1, operand3, Operand.Constant64_0);
context.AppendInstruction(X64.Adc64, result, operand1, operand2);
}
}
30 changes: 30 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/AddCarryOut64.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// AddCarryOut32
/// </summary>
[Transform("x64.IR")]
public sealed class AddCarryOut64 : BaseIRTransform
{
public AddCarryOut64() : base(IRInstruction.AddCarryOut64, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var result2 = context.Result2;
var operand1 = context.Operand1;
var operand2 = context.Operand2;

var v1 = transform.VirtualRegisters.Allocate64();

context.SetInstruction(X64.Add64, result, operand1, operand2);
context.AppendInstruction(X64.Setcc, ConditionCode.Carry, v1);
context.AppendInstruction(X64.Movzx8To64, result2, v1);
}
}
30 changes: 30 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/AddOverflowOut32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// AddOverflowOut32
/// </summary>
[Transform("x64.IR")]
public sealed class AddOverflowOut32 : BaseIRTransform
{
public AddOverflowOut32() : base(IRInstruction.AddOverflowOut32, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var result2 = context.Result2;
var operand1 = context.Operand1;
var operand2 = context.Operand2;

var v1 = transform.VirtualRegisters.Allocate32();

context.SetInstruction(X64.Add32, result, operand1, operand2);
context.AppendInstruction(X64.Setcc, ConditionCode.Overflow, v1);
context.AppendInstruction(X64.Movzx8To32, result2, v1);
}
}
30 changes: 30 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/AddOverflowOut64.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// AddOverflowOut64
/// </summary>
[Transform("x64.IR")]
public sealed class AddOverflowOut64 : BaseIRTransform
{
public AddOverflowOut64() : base(IRInstruction.AddOverflowOut64, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var result2 = context.Result2;
var operand1 = context.Operand1;
var operand2 = context.Operand2;

var v1 = transform.VirtualRegisters.Allocate64();

context.SetInstruction(X64.Adc64, result, operand1, operand2);
context.AppendInstruction(X64.Setcc, ConditionCode.Overflow, v1);
context.AppendInstruction(X64.Movzx8To64, result2, v1);
}
}
21 changes: 21 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/BitCopy32ToR4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// BitCopy32ToR4
/// </summary>
[Transform("x64.IR")]
public sealed class BitCopy32ToR4 : BaseIRTransform
{
public BitCopy32ToR4() : base(IRInstruction.BitCopy32ToR4, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
//context.ReplaceInstruction(X64.Movdi32ss); // TODO
}
}
26 changes: 26 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/BitCopyR4To32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// BitCopyR4To32
/// </summary>
[Transform("x64.IR")]
public sealed class BitCopyR4To32 : BaseIRTransform
{
public BitCopyR4To32() : base(IRInstruction.BitCopyR4To32, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var operand1 = context.Operand1;

operand1 = MoveConstantToFloatRegister(transform, context, operand1);

//context.SetInstruction(X64.Movdssi64, result, operand1); // TODO
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Transforms/IR/ConvertR4ToI64.cs
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ public ConvertR4ToI64() : base(IRInstruction.ConvertR4ToI64, TransformType.Manua

public override void Transform(Context context, TransformContext transform)
{
context.ReplaceInstruction(X64.Cvtss2sd);
context.ReplaceInstruction(X64.Cvttss2si64);
}
}
26 changes: 26 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/ConvertR4ToU32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// ConvertR4ToU32
/// </summary>
[Transform("x64.IR")]
public sealed class ConvertR4ToU32 : BaseIRTransform
{
public ConvertR4ToU32() : base(IRInstruction.ConvertR4ToU32, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var operand1 = context.Operand1;

operand1 = MoveConstantToFloatRegister(transform, context, operand1);

context.SetInstruction(X64.Cvttss2si64, result, operand1);
}
}
21 changes: 21 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/ConvertR4ToU64.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// ConvertR4ToU64
/// </summary>
[Transform("x64.IR")]
public sealed class ConvertR4ToU64 : BaseIRTransform
{
public ConvertR4ToU64() : base(IRInstruction.ConvertR4ToI64, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
//context.ReplaceInstruction(X64.Cvttss2si64); //
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Transforms/IR/ConvertR8ToR4.cs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public ConvertR8ToR4() : base(IRInstruction.ConvertR8ToR4, TransformType.Manual

public override void Transform(Context context, TransformContext transform)
{
Debug.Assert(context.Result.IsFloatingPoint && !context.Result.IsFloatingPoint);
Debug.Assert(context.Result.IsFloatingPoint && context.Result.IsFloatingPoint);

var result = context.Result;
var operand1 = context.Operand1;
26 changes: 26 additions & 0 deletions Source/Mosa.Platform.x64/Transforms/IR/ConvertR8ToU32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Platform.x64.Transforms.IR;

/// <summary>
/// ConvertR8ToU32
/// </summary>
[Transform("x64.IR")]
public sealed class ConvertR8ToU32 : BaseIRTransform
{
public ConvertR8ToU32() : base(IRInstruction.ConvertR8ToU32, TransformType.Manual | TransformType.Transform)
{
}

public override void Transform(Context context, TransformContext transform)
{
var result = context.Result;
var operand1 = context.Operand1;

operand1 = MoveConstantToFloatRegister(transform, context, operand1);

context.SetInstruction(X64.Cvttsd2si32, result, operand1);
}
}
10 changes: 6 additions & 4 deletions Source/Mosa.Platform.x64/Transforms/IR/DivSigned32.cs
Original file line number Diff line number Diff line change
@@ -21,10 +21,12 @@ public override void Transform(Context context, TransformContext transform)
var result = context.Result;

var v1 = transform.VirtualRegisters.Allocate32();
var v2 = transform.VirtualRegisters.Allocate32();
var v3 = transform.VirtualRegisters.Allocate32();

context.SetInstruction2(X64.Cdq32, v1, v2, operand1);
context.AppendInstruction2(X64.IDiv32, v3, result, v1, v2, operand2);
var rax = Operand.CreateCPURegister32(CPURegister.RAX);
var rdx = Operand.CreateCPURegister32(CPURegister.RDX);

context.SetInstruction(X64.Mov32, rax, operand1);
context.AppendInstruction(X64.Cdq32, rdx, rax);
context.AppendInstruction2(X64.IDiv32, v1, result, rdx, rax, operand2);
}
}
Loading