InstEmitConditionCode.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Ryujinx.Graphics.Shader.Decoders;
  2. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  3. using Ryujinx.Graphics.Shader.Translation;
  4. using static Ryujinx.Graphics.Shader.Instructions.InstEmitAluHelper;
  5. using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
  6. using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
  7. namespace Ryujinx.Graphics.Shader.Instructions
  8. {
  9. static partial class InstEmit
  10. {
  11. public static void Cset(EmitterContext context)
  12. {
  13. InstCset op = context.GetOp<InstCset>();
  14. Operand res = GetCondition(context, op.Ccc);
  15. Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
  16. res = GetPredLogicalOp(context, op.Bop, res, srcPred);
  17. Operand dest = GetDest(op.Dest);
  18. if (op.BVal)
  19. {
  20. context.Copy(dest, context.ConditionalSelect(res, ConstF(1), Const(0)));
  21. }
  22. else
  23. {
  24. context.Copy(dest, res);
  25. }
  26. // TODO: CC.
  27. }
  28. public static void Csetp(EmitterContext context)
  29. {
  30. InstCsetp op = context.GetOp<InstCsetp>();
  31. Operand p0Res = GetCondition(context, op.Ccc);
  32. Operand p1Res = context.BitwiseNot(p0Res);
  33. Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
  34. p0Res = GetPredLogicalOp(context, op.Bop, p0Res, srcPred);
  35. p1Res = GetPredLogicalOp(context, op.Bop, p1Res, srcPred);
  36. context.Copy(Register(op.DestPred, RegisterType.Predicate), p0Res);
  37. context.Copy(Register(op.DestPredInv, RegisterType.Predicate), p1Res);
  38. // TODO: CC.
  39. }
  40. private static Operand GetCondition(EmitterContext context, Ccc cond, int defaultCond = IrConsts.True)
  41. {
  42. return cond switch
  43. {
  44. Ccc.F => Const(IrConsts.False),
  45. Ccc.Lt => context.BitwiseExclusiveOr(context.BitwiseAnd(GetNF(), context.BitwiseNot(GetZF())), GetVF()),
  46. Ccc.Eq => context.BitwiseAnd(context.BitwiseNot(GetNF()), GetZF()),
  47. Ccc.Le => context.BitwiseExclusiveOr(GetNF(), context.BitwiseOr(GetZF(), GetVF())),
  48. Ccc.Gt => context.BitwiseNot(context.BitwiseOr(context.BitwiseExclusiveOr(GetNF(), GetVF()), GetZF())),
  49. Ccc.Ne => context.BitwiseNot(GetZF()),
  50. Ccc.Ge => context.BitwiseNot(context.BitwiseExclusiveOr(GetNF(), GetVF())),
  51. Ccc.Num => context.BitwiseNot(context.BitwiseAnd(GetNF(), GetZF())),
  52. Ccc.Nan => context.BitwiseAnd(GetNF(), GetZF()),
  53. Ccc.Ltu => context.BitwiseExclusiveOr(GetNF(), GetVF()),
  54. Ccc.Equ => GetZF(),
  55. Ccc.Leu => context.BitwiseOr(context.BitwiseExclusiveOr(GetNF(), GetVF()), GetZF()),
  56. Ccc.Gtu => context.BitwiseExclusiveOr(context.BitwiseNot(GetNF()), context.BitwiseOr(GetVF(), GetZF())),
  57. Ccc.Neu => context.BitwiseOr(GetNF(), context.BitwiseNot(GetZF())),
  58. Ccc.Geu => context.BitwiseExclusiveOr(context.BitwiseOr(context.BitwiseNot(GetNF()), GetZF()), GetVF()),
  59. Ccc.T => Const(IrConsts.True),
  60. Ccc.Off => context.BitwiseNot(GetVF()),
  61. Ccc.Lo => context.BitwiseNot(GetCF()),
  62. Ccc.Sff => context.BitwiseNot(GetNF()),
  63. Ccc.Ls => context.BitwiseOr(GetZF(), context.BitwiseNot(GetCF())),
  64. Ccc.Hi => context.BitwiseAnd(GetCF(), context.BitwiseNot(GetZF())),
  65. Ccc.Sft => GetNF(),
  66. Ccc.Hs => GetCF(),
  67. Ccc.Oft => GetVF(),
  68. Ccc.Rle => context.BitwiseOr(GetNF(), GetZF()),
  69. Ccc.Rgt => context.BitwiseNot(context.BitwiseOr(GetNF(), GetZF())),
  70. _ => Const(defaultCond)
  71. };
  72. }
  73. }
  74. }