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

Additional Math functions #620

Merged
merged 29 commits into from Apr 1, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Binary file not shown.
@@ -3912,13 +3912,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],operand-prefix=0x66,opcode=0x0F,opcode2=0xEF,mod=11,reg=reg3:r,rm=reg3:o2,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o2"
"Encoding": "[x64-rex32],operand-prefix=0x66,opcode=0x0F,opcode2=0xEF,mod=11,reg=reg3:r,rm=reg3:o1,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o1"
}
]
},
@@ -4366,13 +4366,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],opcode=0xF3,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o2,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o2"
"Encoding": "[x64-rex32],opcode=0xF3,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o1,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o1"
}
]
},
@@ -4387,13 +4387,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],opcode=0xF2,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o2,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o2"
"Encoding": "[x64-rex32],opcode=0xF2,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o1,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o1"
}
]
},
@@ -2829,13 +2829,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x86],operand-prefix=0x66,opcode=0x0F,opcode2=0xEF,mod=11,reg=reg3:r,rm=reg3:o2"
"Encoding": "[x86],operand-prefix=0x66,opcode=0x0F,opcode2=0xEF,mod=11,reg=reg3:r,rm=reg3:o1"
}
]
},
@@ -3124,13 +3124,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x86],opcode=0xF3,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o2"
"Encoding": "[x86],opcode=0xF3,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o1"
}
]
},
@@ -3145,13 +3145,13 @@
"FlagsUnchanged": "ZCSOP",
"FlagsUndefined": "",
"FlagsUsed": "",
"OperandCount": 2,
"OperandCount": 1,
"ResultCount": 1,
"ThreeTwoAddressConversion": "true",
"ThreeTwoAddressConversion": "false",
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x86],opcode=0xF2,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o2"
"Encoding": "[x86],opcode=0xF2,opcode2=0x0F,opcode3=0x51,mod=11,reg=reg3:r,rm=reg3:o1"
}
]
},
@@ -15,7 +15,7 @@ public static SimpleInstruction ConstantFoldingAndStrengthReductionInteger(Instr

return new SimpleInstruction()
{
Instruction = GetMoveInteger(node.Result),
Instruction = GetMove(node.Result),
Result = node.Result,
Operand1 = operand
};
@@ -118,6 +118,22 @@ private static Operand ConstantFolding1Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, (uint)op1.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.ConvertInt32ToFloatR4)
{
return ConstantOperand.Create(result.Type, (float)op1.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.ConvertInt32ToFloatR8)
{
return ConstantOperand.Create(result.Type, (double)op1.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.ConvertInt64ToFloatR4)
{
return ConstantOperand.Create(result.Type, (float)op1.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.ConvertInt64ToFloatR8)
{
return ConstantOperand.Create(result.Type, (double)op1.ConstantUnsignedLongInteger);
}

return null;
}
@@ -143,6 +159,14 @@ private static Operand ConstantFolding2Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, op1.ConstantUnsignedLongInteger + op2.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.AddFloatR4)
{
return ConstantOperand.Create(result.Type, (op1.ConstantDoubleFloatingPoint + op2.ConstantDoubleFloatingPoint));
}
else if (instruction == IRInstruction.AddFloatR8)
{
return ConstantOperand.Create(result.Type, op1.ConstantDoubleFloatingPoint + op2.ConstantDoubleFloatingPoint);
}
else if (instruction == IRInstruction.Sub32)
{
return ConstantOperand.Create(result.Type, (op1.ConstantUnsignedLongInteger - op2.ConstantUnsignedLongInteger) & 0xFFFFFFFF);
@@ -151,6 +175,14 @@ private static Operand ConstantFolding2Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, op1.ConstantUnsignedLongInteger - op2.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.SubFloatR4)
{
return ConstantOperand.Create(result.Type, op1.ConstantSingleFloatingPoint + op2.ConstantSingleFloatingPoint);
}
else if (instruction == IRInstruction.SubFloatR8)
{
return ConstantOperand.Create(result.Type, op1.ConstantSingleFloatingPoint + op2.ConstantSingleFloatingPoint);
}
else if (instruction == IRInstruction.LogicalAnd32)
{
return ConstantOperand.Create(result.Type, op1.ConstantUnsignedLongInteger & op2.ConstantUnsignedLongInteger & 0xFFFFFFFF);
@@ -183,6 +215,14 @@ private static Operand ConstantFolding2Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, op1.ConstantUnsignedLongInteger * op2.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.MulFloatR4)
{
return ConstantOperand.Create(result.Type, (op1.ConstantSingleFloatingPoint * op2.ConstantSingleFloatingPoint));
}
else if (instruction == IRInstruction.MulFloatR8)
{
return ConstantOperand.Create(result.Type, op1.ConstantDoubleFloatingPoint * op2.ConstantDoubleFloatingPoint);
}
else if (instruction == IRInstruction.DivUnsigned32 && !op2.IsConstantZero)
{
return ConstantOperand.Create(result.Type, (op1.ConstantUnsignedLongInteger / op2.ConstantUnsignedLongInteger) & 0xFFFFFFFF);
@@ -199,6 +239,14 @@ private static Operand ConstantFolding2Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, (ulong)(op1.ConstantSignedLongInteger / op2.ConstantSignedLongInteger));
}
else if (instruction == IRInstruction.DivFloatR4 && !op2.IsConstantZero)
{
return ConstantOperand.Create(result.Type, op1.ConstantSingleFloatingPoint / op2.ConstantSingleFloatingPoint);
}
else if (instruction == IRInstruction.DivFloatR8 && !op2.IsConstantZero)
{
return ConstantOperand.Create(result.Type, op1.ConstantDoubleFloatingPoint / op2.ConstantDoubleFloatingPoint);
}
else if (instruction == IRInstruction.ArithShiftRight32)
{
return ConstantOperand.Create(result.Type, ((ulong)(((long)op1.ConstantUnsignedLongInteger) >> (int)op2.ConstantUnsignedLongInteger)) & 0xFFFFFFFF);
@@ -239,6 +287,14 @@ private static Operand ConstantFolding2Integer(InstructionNode node)
{
return ConstantOperand.Create(result.Type, op1.ConstantUnsignedLongInteger % op2.ConstantUnsignedLongInteger);
}
else if (instruction == IRInstruction.RemFloatR4 && !op2.IsConstantZero)
{
return ConstantOperand.Create(result.Type, op1.ConstantSingleFloatingPoint % op2.ConstantSingleFloatingPoint);
}
else if (instruction == IRInstruction.RemFloatR8 && !op2.IsConstantZero)
{
return ConstantOperand.Create(result.Type, op1.ConstantDoubleFloatingPoint % op2.ConstantDoubleFloatingPoint);
}
else if (instruction == IRInstruction.To64)
{
return ConstantOperand.Create(result.Type, op2.ConstantUnsignedLongInteger << 32 | op1.ConstantUnsignedLongInteger);
@@ -307,19 +363,19 @@ private static Operand StrengthReductionInteger(InstructionNode node)
var op1 = node.Operand1;
var op2 = node.Operand2;

if ((instruction == IRInstruction.Add32 || instruction == IRInstruction.Add64) && op1.IsConstantZero)
if ((instruction == IRInstruction.Add32 || instruction == IRInstruction.Add64 || instruction == IRInstruction.AddFloatR4 || instruction == IRInstruction.AddFloatR8) && op1.IsConstantZero)
{
return op2;
}
else if ((instruction == IRInstruction.Add32 || instruction == IRInstruction.Add64) && op2.IsConstantZero)
else if ((instruction == IRInstruction.Add32 || instruction == IRInstruction.Add64 || instruction == IRInstruction.AddFloatR4 || instruction == IRInstruction.AddFloatR8) && op2.IsConstantZero)
{
return op1;
}
else if ((instruction == IRInstruction.Sub32 || instruction == IRInstruction.Sub64) && op2.IsConstantZero)
else if ((instruction == IRInstruction.Sub32 || instruction == IRInstruction.Sub64 || instruction == IRInstruction.SubFloatR4 || instruction == IRInstruction.SubFloatR8) && op2.IsConstantZero)
{
return op1;
}
else if ((instruction == IRInstruction.Sub32 || instruction == IRInstruction.Sub64) && (op1 == op2))
else if ((instruction == IRInstruction.Sub32 || instruction == IRInstruction.Sub64 || instruction == IRInstruction.SubFloatR4 || instruction == IRInstruction.SubFloatR8) && (op1 == op2))
{
return ConstantOperand.Create(result.Type, 0);
}
@@ -339,31 +395,31 @@ private static Operand StrengthReductionInteger(InstructionNode node)
{
return ConstantOperand.Create(result.Type, 0);
}
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64) && (op1.IsConstantZero || op2.IsConstantZero))
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64 || instruction == IRInstruction.MulFloatR4 || instruction == IRInstruction.MulFloatR8) && (op1.IsConstantZero || op2.IsConstantZero))
{
return ConstantOperand.Create(result.Type, 0);
}
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64) && op1.IsConstantOne)
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64 || instruction == IRInstruction.MulFloatR4 || instruction == IRInstruction.MulFloatR8) && op1.IsConstantOne)
{
return op2;
}
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64) && op2.IsConstantOne)
else if ((instruction == IRInstruction.MulSigned32 || instruction == IRInstruction.MulUnsigned32 || instruction == IRInstruction.MulSigned64 || instruction == IRInstruction.MulUnsigned64 || instruction == IRInstruction.MulFloatR4 || instruction == IRInstruction.MulFloatR8) && op2.IsConstantOne)
{
return op1;
}
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64) && op2.IsConstantOne)
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64 || instruction == IRInstruction.DivFloatR4 || instruction == IRInstruction.DivFloatR8) && op2.IsConstantOne)
{
return op1;
}
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64) && op1.IsConstantZero)
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64 || instruction == IRInstruction.DivFloatR4 || instruction == IRInstruction.DivFloatR8) && op1.IsConstantZero)
{
return ConstantOperand.Create(result.Type, 0);
}
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64) && op1 == op2)
else if ((node.Instruction == IRInstruction.DivSigned32 || node.Instruction == IRInstruction.DivUnsigned32 || node.Instruction == IRInstruction.DivSigned64 || node.Instruction == IRInstruction.DivUnsigned64 || instruction == IRInstruction.DivFloatR4 || instruction == IRInstruction.DivFloatR8) && op1 == op2)
{
return ConstantOperand.Create(result.Type, 1);
}
else if ((node.Instruction == IRInstruction.RemUnsigned32 || node.Instruction == IRInstruction.RemUnsigned64) && op2.IsConstantOne)
else if ((node.Instruction == IRInstruction.RemUnsigned32 || node.Instruction == IRInstruction.RemUnsigned64 || instruction == IRInstruction.RemFloatR4 || instruction == IRInstruction.RemFloatR8) && op2.IsConstantOne)
{
return ConstantOperand.Create(result.Type, 0);
}
@@ -776,6 +832,18 @@ private static BaseInstruction GetMoveInteger(Operand operand)
return operand.Is64BitInteger ? (BaseInstruction)IRInstruction.MoveInt64 : IRInstruction.MoveInt32;
}

private static BaseInstruction GetMove(Operand operand)
{
if (operand.IsR4)
return IRInstruction.MoveFloatR4;
else if (operand.IsR8)
return IRInstruction.MoveFloatR8;
else if (operand.Is64BitInteger)
return IRInstruction.MoveInt64;
else
return IRInstruction.MoveInt32;
}

#endregion Helpers
}
}
@@ -28,6 +28,16 @@ public static Operand Create(MosaType type, uint value)
return Operand.CreateConstant(type, value);
}

public static Operand Create(MosaType type, float value)
{
return Operand.CreateConstant(type, value);
}

public static Operand Create(MosaType type, double value)
{
return Operand.CreateConstant(type, value);
}

#endregion Constant Helper Methods
}
}
@@ -477,24 +477,18 @@ private Operand(ShiftType shiftType)
/// <exception cref="CompilerException"></exception>
public static Operand CreateConstant(MosaType type, ulong value)
{
var operand = new Operand(type)
if (type.IsReferenceType && value != 0)
{
throw new CompilerException();
}

return new Operand(type)
{
IsConstant = true,
ConstantUnsignedLongInteger = value,
IsNull = (type.IsReferenceType && value == 0),
IsResolved = true
};
if (type.IsReferenceType && value != 0)
{
throw new CompilerException();
}

//if (!(operand.IsInteger || operand.IsBoolean || operand.IsChar || operand.IsPointer || operand.IsReferenceType))
//{
// throw new CompilerException();
//}

return operand;
}

/// <summary>
@@ -510,6 +504,28 @@ public static Operand CreateConstant(MosaType type, long value)
return CreateConstant(type, (ulong)value);
}

public static Operand CreateConstant(MosaType type, float value)
{
return new Operand(type)
{
IsConstant = true,
ConstantSingleFloatingPoint = value,
IsNull = false,
IsResolved = true
};
}

public static Operand CreateConstant(MosaType type, double value)
{
return new Operand(type)
{
IsConstant = true,
ConstantDoubleFloatingPoint = value,
IsNull = false,
IsResolved = true
};
}

/// <summary>
/// Creates a new constant <see cref="Operand" /> for the given integral value.
/// </summary>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.