2019-10-13 08:02:07 +02:00
|
|
|
using Ryujinx.Graphics.Shader.Decoders;
|
2020-03-25 15:49:10 +01:00
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
2019-10-13 08:02:07 +02:00
|
|
|
using Ryujinx.Graphics.Shader.Translation;
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
|
2020-03-25 15:49:10 +01:00
|
|
|
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
|
2019-10-13 08:02:07 +02:00
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.Instructions
|
|
|
|
{
|
|
|
|
static partial class InstEmit
|
|
|
|
{
|
2020-03-25 15:49:10 +01:00
|
|
|
public static void Vmnmx(EmitterContext context)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstVmnmx op = context.GetOp<InstVmnmx>();
|
2020-03-25 15:49:10 +01:00
|
|
|
|
2022-04-08 12:42:39 +02:00
|
|
|
Operand srcA = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcA), op.ASelect);
|
2021-10-12 22:35:31 +02:00
|
|
|
Operand srcC = GetSrcReg(context, op.SrcC);
|
2020-03-25 15:49:10 +01:00
|
|
|
Operand srcB;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if (op.BVideo)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
2022-04-08 12:42:39 +02:00
|
|
|
srcB = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcB), op.BSelect);
|
2020-03-25 15:49:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
int imm = op.Imm16;
|
|
|
|
|
|
|
|
if ((op.BSelect & VectorSelect.S8B0) != 0)
|
|
|
|
{
|
|
|
|
imm = (imm << 16) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcB = Const(imm);
|
2020-03-25 15:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Operand res;
|
|
|
|
|
|
|
|
bool resSigned;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if ((op.ASelect & VectorSelect.S8B0) != (op.BSelect & VectorSelect.S8B0))
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
|
|
|
// Signedness is different, but for max, result will always fit a U32,
|
|
|
|
// since one of the inputs can't be negative, and the result is the one
|
|
|
|
// with highest value. For min, it will always fit on a S32, since
|
|
|
|
// one of the input can't be greater than INT_MAX and we want the lowest value.
|
2021-10-12 22:35:31 +02:00
|
|
|
resSigned = !op.Mn;
|
2020-03-25 15:49:10 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
res = op.Mn ? context.IMaximumU32(srcA, srcB) : context.IMinimumS32(srcA, srcB);
|
2020-03-25 15:49:10 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if ((op.ASelect & VectorSelect.S8B0) != 0)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
|
|
|
Operand isBGtIntMax = context.ICompareLess(srcB, Const(0));
|
|
|
|
|
|
|
|
res = context.ConditionalSelect(isBGtIntMax, srcB, res);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Operand isAGtIntMax = context.ICompareLess(srcA, Const(0));
|
|
|
|
|
|
|
|
res = context.ConditionalSelect(isAGtIntMax, srcA, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ra and Rb have the same signedness, so doesn't matter which one we test.
|
2021-10-12 22:35:31 +02:00
|
|
|
resSigned = (op.ASelect & VectorSelect.S8B0) != 0;
|
2020-03-25 15:49:10 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if (op.Mn)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
|
|
|
res = resSigned
|
|
|
|
? context.IMaximumS32(srcA, srcB)
|
|
|
|
: context.IMaximumU32(srcA, srcB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = resSigned
|
|
|
|
? context.IMinimumS32(srcA, srcB)
|
|
|
|
: context.IMinimumU32(srcA, srcB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if (op.Sat)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
if (op.DFormat && !resSigned)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
|
|
|
res = context.IMinimumU32(res, Const(int.MaxValue));
|
|
|
|
}
|
2021-10-12 22:35:31 +02:00
|
|
|
else if (!op.DFormat && resSigned)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
|
|
|
res = context.IMaximumS32(res, Const(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
switch (op.VideoOp)
|
2020-03-25 15:49:10 +01:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Acc:
|
2020-03-25 15:49:10 +01:00
|
|
|
res = context.IAdd(res, srcC);
|
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Max:
|
|
|
|
res = op.DFormat ? context.IMaximumS32(res, srcC) : context.IMaximumU32(res, srcC);
|
2020-03-25 15:49:10 +01:00
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Min:
|
|
|
|
res = op.DFormat ? context.IMinimumS32(res, srcC) : context.IMinimumU32(res, srcC);
|
2020-03-25 15:49:10 +01:00
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Mrg16h:
|
2020-03-25 15:49:10 +01:00
|
|
|
res = context.BitfieldInsert(srcC, res, Const(16), Const(16));
|
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Mrg16l:
|
2020-03-25 15:49:10 +01:00
|
|
|
res = context.BitfieldInsert(srcC, res, Const(0), Const(16));
|
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Mrg8b0:
|
2020-03-25 15:49:10 +01:00
|
|
|
res = context.BitfieldInsert(srcC, res, Const(0), Const(8));
|
|
|
|
break;
|
2021-10-12 22:35:31 +02:00
|
|
|
case VideoOp.Mrg8b2:
|
2020-03-25 15:49:10 +01:00
|
|
|
res = context.BitfieldInsert(srcC, res, Const(16), Const(8));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
context.Copy(GetDest(op.Dest), res);
|
2020-03-25 15:49:10 +01:00
|
|
|
}
|
|
|
|
|
2021-10-18 23:38:04 +02:00
|
|
|
public static void Vsetp(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstVsetp op = context.GetOp<InstVsetp>();
|
|
|
|
|
2022-04-08 12:42:39 +02:00
|
|
|
Operand srcA = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcA), op.ASelect);
|
2021-10-18 23:38:04 +02:00
|
|
|
Operand srcB;
|
|
|
|
|
|
|
|
if (op.BVideo)
|
|
|
|
{
|
2022-04-08 12:42:39 +02:00
|
|
|
srcB = InstEmitAluHelper.Extend(context, GetSrcReg(context, op.SrcB), op.BSelect);
|
2021-10-18 23:38:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int imm = op.Imm16;
|
|
|
|
|
|
|
|
if ((op.BSelect & VectorSelect.S8B0) != 0)
|
|
|
|
{
|
|
|
|
imm = (imm << 16) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcB = Const(imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
Operand p0Res;
|
|
|
|
|
|
|
|
bool signedA = (op.ASelect & VectorSelect.S8B0) != 0;
|
|
|
|
bool signedB = (op.BSelect & VectorSelect.S8B0) != 0;
|
|
|
|
|
|
|
|
if (signedA != signedB)
|
|
|
|
{
|
|
|
|
bool a32 = (op.ASelect & ~VectorSelect.S8B0) == VectorSelect.U32;
|
|
|
|
bool b32 = (op.BSelect & ~VectorSelect.S8B0) == VectorSelect.U32;
|
|
|
|
|
|
|
|
if (!a32 && !b32)
|
|
|
|
{
|
|
|
|
// Both values are extended small integer and can always fit in a S32, just do a signed comparison.
|
|
|
|
p0Res = GetIntComparison(context, op.VComp, srcA, srcB, isSigned: true, extended: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: Mismatching sign case.
|
|
|
|
p0Res = Const(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Sign matches, just do a regular comparison.
|
|
|
|
p0Res = GetIntComparison(context, op.VComp, srcA, srcB, signedA, extended: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Operand p1Res = context.BitwiseNot(p0Res);
|
|
|
|
|
|
|
|
Operand pred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
|
|
|
|
|
|
|
|
p0Res = InstEmitAluHelper.GetPredLogicalOp(context, op.BoolOp, p0Res, pred);
|
|
|
|
p1Res = InstEmitAluHelper.GetPredLogicalOp(context, op.BoolOp, p1Res, pred);
|
|
|
|
|
|
|
|
context.Copy(Register(op.DestPred, RegisterType.Predicate), p0Res);
|
|
|
|
context.Copy(Register(op.DestPredInv, RegisterType.Predicate), p1Res);
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|