mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-12-15 00:20:39 +01:00
9becbd7d72
* dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format CA1069 warnings * Address or silence dotnet format CA2211 warnings * Address review comments * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Run dotnet format after rebase * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Add trailing commas * Remove unused members and most unnecessary value assignments * Remove more unnecessary assignments * Remove NRE suppressor
117 lines
4.2 KiB
C#
117 lines
4.2 KiB
C#
using Ryujinx.Graphics.Shader.Decoders;
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
using Ryujinx.Graphics.Shader.Translation;
|
|
using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
|
|
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
|
|
|
|
namespace Ryujinx.Graphics.Shader.Instructions
|
|
{
|
|
static partial class InstEmit
|
|
{
|
|
public static void Vmad(EmitterContext context)
|
|
{
|
|
InstVmad op = context.GetOp<InstVmad>();
|
|
|
|
bool aSigned = (op.ASelect & VectorSelect.S8B0) != 0;
|
|
bool bSigned = (op.BSelect & VectorSelect.S8B0) != 0;
|
|
|
|
Operand srcA = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcA), op.ASelect);
|
|
Operand srcC = context.INegate(GetSrcReg(context, op.SrcC), op.AvgMode == AvgMode.NegB);
|
|
Operand srcB;
|
|
|
|
if (op.BVideo)
|
|
{
|
|
srcB = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcB), op.BSelect);
|
|
}
|
|
else
|
|
{
|
|
int imm = op.Imm16;
|
|
|
|
if (bSigned)
|
|
{
|
|
imm = (imm << 16) >> 16;
|
|
}
|
|
|
|
srcB = Const(imm);
|
|
}
|
|
|
|
Operand productLow = context.IMultiply(srcA, srcB);
|
|
Operand productHigh;
|
|
|
|
if (aSigned == bSigned)
|
|
{
|
|
productHigh = aSigned
|
|
? context.MultiplyHighS32(srcA, srcB)
|
|
: context.MultiplyHighU32(srcA, srcB);
|
|
}
|
|
else
|
|
{
|
|
Operand temp = aSigned
|
|
? context.IMultiply(srcB, context.ShiftRightS32(srcA, Const(31)))
|
|
: context.IMultiply(srcA, context.ShiftRightS32(srcB, Const(31)));
|
|
|
|
productHigh = context.IAdd(temp, context.MultiplyHighU32(srcA, srcB));
|
|
}
|
|
|
|
if (op.AvgMode == AvgMode.NegA)
|
|
{
|
|
(productLow, productHigh) = InstEmitAluHelper.NegateLong(context, productLow, productHigh);
|
|
}
|
|
|
|
Operand resLow = InstEmitAluHelper.AddWithCarry(context, productLow, srcC, out Operand sumCarry);
|
|
Operand resHigh = context.IAdd(productHigh, sumCarry);
|
|
|
|
if (op.AvgMode == AvgMode.PlusOne)
|
|
{
|
|
resLow = InstEmitAluHelper.AddWithCarry(context, resLow, Const(1), out Operand poCarry);
|
|
resHigh = context.IAdd(resHigh, poCarry);
|
|
}
|
|
|
|
bool resSigned = op.ASelect == VectorSelect.S32 ||
|
|
op.BSelect == VectorSelect.S32 ||
|
|
op.AvgMode == AvgMode.NegB ||
|
|
op.AvgMode == AvgMode.NegA;
|
|
|
|
int shift = op.VideoScale switch
|
|
{
|
|
VideoScale.Shr7 => 7,
|
|
VideoScale.Shr15 => 15,
|
|
_ => 0,
|
|
};
|
|
|
|
if (shift != 0)
|
|
{
|
|
// Low = (Low >> Shift) | (High << (32 - Shift))
|
|
// High >>= Shift
|
|
resLow = context.ShiftRightU32(resLow, Const(shift));
|
|
resLow = context.BitwiseOr(resLow, context.ShiftLeft(resHigh, Const(32 - shift)));
|
|
resHigh = resSigned
|
|
? context.ShiftRightS32(resHigh, Const(shift))
|
|
: context.ShiftRightU32(resHigh, Const(shift));
|
|
}
|
|
|
|
Operand res = resLow;
|
|
|
|
if (op.Sat)
|
|
{
|
|
Operand sign = context.ShiftRightS32(resHigh, Const(31));
|
|
|
|
if (resSigned)
|
|
{
|
|
Operand overflow = context.ICompareNotEqual(resHigh, context.ShiftRightS32(resLow, Const(31)));
|
|
Operand clampValue = context.ConditionalSelect(sign, Const(int.MinValue), Const(int.MaxValue));
|
|
res = context.ConditionalSelect(overflow, clampValue, resLow);
|
|
}
|
|
else
|
|
{
|
|
Operand overflow = context.ICompareNotEqual(resHigh, Const(0));
|
|
res = context.ConditionalSelect(overflow, context.BitwiseNot(sign), resLow);
|
|
}
|
|
}
|
|
|
|
context.Copy(GetDest(op.Dest), res);
|
|
|
|
// TODO: CC.
|
|
}
|
|
}
|
|
}
|