2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Gal.Shader.ShaderDecodeHelper;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static partial class ShaderDecode
|
|
|
|
{
|
2019-01-31 13:43:24 +01:00
|
|
|
private enum HalfOutputType
|
|
|
|
{
|
|
|
|
PackedFp16,
|
|
|
|
Fp32,
|
|
|
|
MergeH0,
|
|
|
|
MergeH1
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Bfe_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Bfe_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Bfe_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.CR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fadd_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-28 04:55:08 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Immf32_20();
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(53);
|
|
|
|
bool AbsA = OpCode.Read(54);
|
|
|
|
bool NegA = OpCode.Read(56);
|
|
|
|
bool AbsB = OpCode.Read(57);
|
2018-06-28 04:55:08 +02:00
|
|
|
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Fadd, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-06-28 04:55:08 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.RR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Ffma_CR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.CR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Ffma_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Ffma_RC(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.RC);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Ffma_RR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmnmx_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.CR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmnmx_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmnmx_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmul_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-19 21:18:30 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Immf32_20();
|
2018-04-19 21:18:30 +02:00
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Fmul, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-19 21:18:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmul_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.CR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmul_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fmul_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-14 00:46:36 +02:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.RR);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fset_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fset_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fset_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fsetp_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fsetp_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Fsetp_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2019-01-31 13:43:24 +01:00
|
|
|
public static void Hadd2_R(ShaderIrBlock Block, long OpCode, int Position)
|
|
|
|
{
|
|
|
|
EmitBinaryHalfOp(Block, OpCode, ShaderIrInst.Fadd);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Hmul2_R(ShaderIrBlock Block, long OpCode, int Position)
|
|
|
|
{
|
|
|
|
EmitBinaryHalfOp(Block, OpCode, ShaderIrInst.Fmul);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Imm32_20();
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegA = OpCode.Read(56);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
OperA = GetAluIneg(OperA, NegA);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Add, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd3_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd3_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iadd3_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Imnmx_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Imnmx_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Imnmx_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Ipa(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Abuf28();
|
|
|
|
ShaderIrNode OperB = OpCode.Gpr20();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIpaMode Mode = (ShaderIpaMode)(OpCode.Read(54, 3));
|
2018-09-01 23:44:19 +02:00
|
|
|
|
|
|
|
ShaderIrMetaIpa Meta = new ShaderIrMetaIpa(Mode);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Ipa, OperA, OperB, null, Meta);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iscadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iscadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iscadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iset_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iset_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Iset_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Isetp_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Isetp_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Isetp_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Lop_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
int SubOp = OpCode.Read(53, 3);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool InvA = OpCode.Read(55);
|
|
|
|
bool InvB = OpCode.Read(56);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
ShaderIrInst Inst = 0;
|
|
|
|
|
|
|
|
switch (SubOp)
|
|
|
|
{
|
|
|
|
case 0: Inst = ShaderIrInst.And; break;
|
|
|
|
case 1: Inst = ShaderIrInst.Or; break;
|
|
|
|
case 2: Inst = ShaderIrInst.Xor; break;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperB = GetAluNot(OpCode.Imm32_20(), InvB);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
//SubOp == 3 is pass, used by the not instruction
|
|
|
|
//which just moves the inverted register value.
|
|
|
|
if (SubOp < 3)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = GetAluNot(OpCode.Gpr8(), InvA);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperB)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Lop_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Lop_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Lop_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Mufu(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
int SubOp = OpCode.Read(20, 0xf);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
ShaderIrInst Inst = 0;
|
|
|
|
|
|
|
|
switch (SubOp)
|
|
|
|
{
|
2018-06-23 07:00:44 +02:00
|
|
|
case 0: Inst = ShaderIrInst.Fcos; break;
|
|
|
|
case 1: Inst = ShaderIrInst.Fsin; break;
|
|
|
|
case 2: Inst = ShaderIrInst.Fex2; break;
|
|
|
|
case 3: Inst = ShaderIrInst.Flg2; break;
|
|
|
|
case 4: Inst = ShaderIrInst.Frcp; break;
|
|
|
|
case 5: Inst = ShaderIrInst.Frsq; break;
|
|
|
|
case 8: Inst = ShaderIrInst.Fsqrt; break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
default: throw new NotImplementedException(SubOp.ToString());
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
ShaderIrOp Op = new ShaderIrOp(Inst, GetAluFabsFneg(OperA, AbsA, NegA));
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Psetp(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-02 05:50:56 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegA = OpCode.Read(15);
|
|
|
|
bool NegB = OpCode.Read(32);
|
|
|
|
bool NegP = OpCode.Read(42);
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop24();
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Pred12();
|
|
|
|
ShaderIrNode OperB = OpCode.Pred29();
|
2018-06-02 05:50:56 +02:00
|
|
|
|
|
|
|
if (NegA)
|
|
|
|
{
|
|
|
|
OperA = new ShaderIrOp(ShaderIrInst.Bnot, OperA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NegB)
|
|
|
|
{
|
|
|
|
OperB = new ShaderIrOp(ShaderIrInst.Bnot, OperB);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(LopInst, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperPred P0Node = OpCode.Pred3();
|
|
|
|
ShaderIrOperPred P1Node = OpCode.Pred0();
|
|
|
|
ShaderIrOperPred P2Node = OpCode.Pred39();
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
LopInst = OpCode.BLop45();
|
2018-06-02 05:50:56 +02:00
|
|
|
|
|
|
|
if (LopInst == ShaderIrInst.Band && P1Node.IsConst && P2Node.IsConst)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode P2NNode = P2Node;
|
|
|
|
|
|
|
|
if (NegP)
|
|
|
|
{
|
|
|
|
P2NNode = new ShaderIrOp(ShaderIrInst.Bnot, P2NNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(ShaderIrInst.Bnot, P0Node);
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, Op, P2NNode);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P1Node, Op)));
|
2018-06-02 05:50:56 +02:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, P0Node, P2NNode);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-06-02 05:50:56 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Rro_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-02 05:50:56 +02:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Rro_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-02 05:50:56 +02:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Rro_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-02 05:50:56 +02:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shl_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.CR, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shl_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.Imm, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shl_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.RR, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shr_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.CR, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shr_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.Imm, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Shr_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.RR, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ShaderIrInst GetShrInst(long OpCode)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool Signed = OpCode.Read(48);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
return Signed ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Vmad(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-19 07:33:27 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-07-19 07:33:27 +02:00
|
|
|
|
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
if (OpCode.Read(50))
|
2018-07-19 07:33:27 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperB = OpCode.Gpr20();
|
2018-07-19 07:33:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperB = OpCode.Imm19_20();
|
2018-07-19 07:33:27 +02:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperGpr OperC = OpCode.Gpr39();
|
2018-07-19 07:33:27 +02:00
|
|
|
|
|
|
|
ShaderIrNode Tmp = new ShaderIrOp(ShaderIrInst.Mul, OperA, OperB);
|
|
|
|
|
|
|
|
ShaderIrNode Final = new ShaderIrOp(ShaderIrInst.Add, Tmp, OperC);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
int Shr = OpCode.Read(51, 3);
|
2018-07-19 07:33:27 +02:00
|
|
|
|
|
|
|
if (Shr != 0)
|
|
|
|
{
|
|
|
|
int Shift = (Shr == 2) ? 15 : 7;
|
|
|
|
|
|
|
|
Final = new ShaderIrOp(ShaderIrInst.Lsr, Final, new ShaderIrOperImm(Shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
Block.AddNode(new ShaderIrCmnt("Stubbed. Instruction is reduced to a * b + c"));
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Final)));
|
2018-07-19 07:33:27 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Xmad_CR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Xmad_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Xmad_RC(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.RC);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
public static void Xmad_RR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
private static void EmitAluBinary(
|
|
|
|
ShaderIrBlock Block,
|
|
|
|
long OpCode,
|
|
|
|
ShaderOper Oper,
|
|
|
|
ShaderIrInst Inst)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
private static void EmitBfe(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
//TODO: Handle the case where position + length
|
|
|
|
//is greater than the word size, in this case the sign bit
|
|
|
|
//needs to be replicated to fill the remaining space.
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegA = OpCode.Read(49);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode Op;
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool Signed = OpCode.Read(48); //?
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
if (OperB is ShaderIrOperImm PosLen)
|
|
|
|
{
|
|
|
|
int Position = (PosLen.Value >> 0) & 0xff;
|
|
|
|
int Length = (PosLen.Value >> 8) & 0xff;
|
|
|
|
|
|
|
|
int LSh = 32 - (Position + Length);
|
|
|
|
|
|
|
|
ShaderIrInst RightShift = Signed
|
|
|
|
? ShaderIrInst.Asr
|
|
|
|
: ShaderIrInst.Lsr;
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(ShaderIrInst.Lsl, OperA, new ShaderIrOperImm(LSh));
|
|
|
|
Op = new ShaderIrOp(RightShift, Op, new ShaderIrOperImm(LSh + Position));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShaderIrOperImm Shift = new ShaderIrOperImm(8);
|
|
|
|
ShaderIrOperImm Mask = new ShaderIrOperImm(0xff);
|
|
|
|
|
|
|
|
ShaderIrNode OpPos, OpLen;
|
|
|
|
|
|
|
|
OpPos = new ShaderIrOp(ShaderIrInst.And, OperB, Mask);
|
|
|
|
OpLen = new ShaderIrOp(ShaderIrInst.Lsr, OperB, Shift);
|
|
|
|
OpLen = new ShaderIrOp(ShaderIrInst.And, OpLen, Mask);
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(ShaderIrInst.Lsr, OperA, OpPos);
|
|
|
|
|
|
|
|
Op = ExtendTo32(Op, Signed, OpLen);
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 00:46:36 +02:00
|
|
|
private static void EmitFadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
|
|
|
bool AbsB = OpCode.Read(49);
|
2018-10-14 04:54:14 +02:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-08-14 00:46:36 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-08-14 00:46:36 +02:00
|
|
|
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-08-14 00:46:36 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(ShaderIrInst.Fadd, OperA, OperB);
|
|
|
|
|
2018-10-14 04:54:14 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-08-14 00:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFmul(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(48);
|
2018-10-14 04:54:14 +02:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-08-14 00:46:36 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-08-14 00:46:36 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-08-14 00:46:36 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB = GetAluFneg(OperB, NegB);
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(ShaderIrInst.Fmul, OperA, OperB);
|
|
|
|
|
2018-10-14 04:54:14 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-08-14 00:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
private static void EmitFfma(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegC = OpCode.Read(49);
|
2018-10-14 04:54:14 +02:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB, OperC;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RC: OperB = OpCode.Gpr39(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
OperB = GetAluFneg(OperB, NegB);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
if (Oper == ShaderOper.RC)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperC = GetAluFneg(OpCode.Cbuf34(), NegC);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperC = GetAluFneg(OpCode.Gpr39(), NegC);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Ffma, OperA, OperB, OperC);
|
|
|
|
|
2018-10-14 04:54:14 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 21:50:00 +02:00
|
|
|
private static void EmitIadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-07-17 21:50:00 +02:00
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegA = OpCode.Read(49);
|
|
|
|
bool NegB = OpCode.Read(48);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
OperA = GetAluIneg(OperA, NegA);
|
|
|
|
OperB = GetAluIneg(OperB, NegB);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Add, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitIadd3(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
int Mode = OpCode.Read(37, 3);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool Neg1 = OpCode.Read(51);
|
|
|
|
bool Neg2 = OpCode.Read(50);
|
|
|
|
bool Neg3 = OpCode.Read(49);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
int Height1 = OpCode.Read(35, 3);
|
|
|
|
int Height2 = OpCode.Read(33, 3);
|
|
|
|
int Height3 = OpCode.Read(31, 3);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode ApplyHeight(ShaderIrNode Src, int Height)
|
|
|
|
{
|
|
|
|
if (Oper != ShaderOper.RR)
|
|
|
|
{
|
|
|
|
return Src;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Height)
|
|
|
|
{
|
|
|
|
case 0: return Src;
|
|
|
|
case 1: return new ShaderIrOp(ShaderIrInst.And, Src, new ShaderIrOperImm(0xffff));
|
|
|
|
case 2: return new ShaderIrOp(ShaderIrInst.Lsr, Src, new ShaderIrOperImm(16));
|
|
|
|
|
|
|
|
default: throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode Src1 = GetAluIneg(ApplyHeight(OpCode.Gpr8(), Height1), Neg1);
|
2018-10-23 22:59:52 +02:00
|
|
|
ShaderIrNode Src2 = GetAluIneg(ApplyHeight(OperB, Height2), Neg2);
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode Src3 = GetAluIneg(ApplyHeight(OpCode.Gpr39(), Height3), Neg3);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
ShaderIrOp Sum = new ShaderIrOp(ShaderIrInst.Add, Src1, Src2);
|
|
|
|
|
|
|
|
if (Oper == ShaderOper.RR)
|
|
|
|
{
|
|
|
|
switch (Mode)
|
|
|
|
{
|
|
|
|
case 1: Sum = new ShaderIrOp(ShaderIrInst.Lsr, Sum, new ShaderIrOperImm(16)); break;
|
|
|
|
case 2: Sum = new ShaderIrOp(ShaderIrInst.Lsl, Sum, new ShaderIrOperImm(16)); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Note: Here there should be a "+ 1" when carry flag is set
|
|
|
|
//but since carry is mostly ignored by other instructions, it's excluded for now
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), new ShaderIrOp(ShaderIrInst.Add, Sum, Src3))));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2018-06-02 05:50:56 +02:00
|
|
|
private static void EmitIscadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegA = OpCode.Read(49);
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperImm Scale = OpCode.Imm5_39();
|
2018-06-02 05:50:56 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-06-02 05:50:56 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperA = GetAluIneg(OperA, NegA);
|
|
|
|
OperB = GetAluIneg(OperB, NegB);
|
|
|
|
|
|
|
|
ShaderIrOp ScaleOp = new ShaderIrOp(ShaderIrInst.Lsl, OperA, Scale);
|
|
|
|
ShaderIrOp AddOp = new ShaderIrOp(ShaderIrInst.Add, OperB, ScaleOp);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), AddOp)));
|
2018-06-02 05:50:56 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
private static void EmitFmnmx(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-05-30 01:37:10 +02:00
|
|
|
{
|
|
|
|
EmitMnmx(Block, OpCode, true, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitImnmx(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
|
|
|
EmitMnmx(Block, OpCode, false, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitMnmx(ShaderIrBlock Block, long OpCode, bool IsFloat, ShaderOper Oper)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegB = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
|
|
|
bool AbsB = OpCode.Read(49);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-05-30 01:37:10 +02:00
|
|
|
if (IsFloat)
|
|
|
|
{
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OperA = GetAluIabsIneg(OperA, AbsA, NegA);
|
|
|
|
}
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-05-30 01:37:10 +02:00
|
|
|
if (IsFloat)
|
|
|
|
{
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OperB = GetAluIabsIneg(OperB, AbsB, NegB);
|
|
|
|
}
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperPred Pred = OpCode.Pred39();
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
ShaderIrOp Op;
|
|
|
|
|
2018-05-30 01:37:10 +02:00
|
|
|
ShaderIrInst MaxInst = IsFloat ? ShaderIrInst.Fmax : ShaderIrInst.Max;
|
|
|
|
ShaderIrInst MinInst = IsFloat ? ShaderIrInst.Fmin : ShaderIrInst.Min;
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
if (Pred.IsConst)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool IsMax = OpCode.Read(42);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(IsMax
|
2018-05-30 01:37:10 +02:00
|
|
|
? MaxInst
|
|
|
|
: MinInst, OperA, OperB);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode PredN = OpCode.Pred39N();
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-05-30 01:37:10 +02:00
|
|
|
ShaderIrOp OpMax = new ShaderIrOp(MaxInst, OperA, OperB);
|
|
|
|
ShaderIrOp OpMin = new ShaderIrOp(MinInst, OperA, OperB);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrAsg AsgMax = new ShaderIrAsg(OpCode.Gpr0(), OpMax);
|
|
|
|
ShaderIrAsg AsgMin = new ShaderIrAsg(OpCode.Gpr0(), OpMin);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrCond(PredN, AsgMax, Not: true)));
|
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrCond(PredN, AsgMin, Not: false)));
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-02 16:44:52 +02:00
|
|
|
private static void EmitRro(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2018-06-02 05:50:56 +02:00
|
|
|
//Note: this is a range reduction instruction and is supposed to
|
|
|
|
//be used with Mufu, here it just moves the value and ignores the operation.
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegA = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(49);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-06-02 05:50:56 +02:00
|
|
|
ShaderIrNode OperA;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperA = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: OperA = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperA = OpCode.Gpr20(); break;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-06-02 05:50:56 +02:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-07-19 07:33:27 +02:00
|
|
|
Block.AddNode(new ShaderIrCmnt("Stubbed."));
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperA)));
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 04:11:26 +02:00
|
|
|
private static void EmitFset(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
|
|
|
EmitSet(Block, OpCode, true, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitIset(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
|
|
|
EmitSet(Block, OpCode, false, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitSet(ShaderIrBlock Block, long OpCode, bool IsFloat, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool NegA = OpCode.Read(43);
|
|
|
|
bool AbsB = OpCode.Read(44);
|
|
|
|
bool NegB = OpCode.Read(53);
|
|
|
|
bool AbsA = OpCode.Read(54);
|
2018-08-03 18:54:34 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool BoolFloat = OpCode.Read(IsFloat ? 52 : 44);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrInst CmpInst;
|
|
|
|
|
|
|
|
if (IsFloat)
|
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
CmpInst = OpCode.CmpF();
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
CmpInst = OpCode.Cmp();
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(CmpInst, OperA, OperB);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop45();
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperPred PNode = OpCode.Pred39();
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
ShaderIrNode Imm0, Imm1;
|
|
|
|
|
|
|
|
if (BoolFloat)
|
|
|
|
{
|
|
|
|
Imm0 = new ShaderIrOperImmf(0);
|
|
|
|
Imm1 = new ShaderIrOperImmf(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Imm0 = new ShaderIrOperImm(0);
|
|
|
|
Imm1 = new ShaderIrOperImm(-1);
|
|
|
|
}
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode Asg0 = new ShaderIrAsg(OpCode.Gpr0(), Imm0);
|
|
|
|
ShaderIrNode Asg1 = new ShaderIrAsg(OpCode.Gpr0(), Imm1);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
|
|
|
if (LopInst != ShaderIrInst.Band || !PNode.IsConst)
|
|
|
|
{
|
|
|
|
ShaderIrOp Op2 = new ShaderIrOp(LopInst, Op, PNode);
|
|
|
|
|
|
|
|
Asg0 = new ShaderIrCond(Op2, Asg0, Not: true);
|
|
|
|
Asg1 = new ShaderIrCond(Op2, Asg1, Not: false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Asg0 = new ShaderIrCond(Op, Asg0, Not: true);
|
|
|
|
Asg1 = new ShaderIrCond(Op, Asg1, Not: false);
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(Asg0));
|
|
|
|
Block.AddNode(OpCode.PredNode(Asg1));
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
private static void EmitFsetp(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
EmitSetp(Block, OpCode, true, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitIsetp(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
|
|
|
EmitSetp(Block, OpCode, false, Oper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitSetp(ShaderIrBlock Block, long OpCode, bool IsFloat, ShaderOper Oper)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
bool AbsA = OpCode.Read(7);
|
|
|
|
bool NegP = OpCode.Read(42);
|
|
|
|
bool NegA = OpCode.Read(43);
|
|
|
|
bool AbsB = OpCode.Read(44);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.Immf: OperB = OpCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:50:32 +02:00
|
|
|
ShaderIrInst CmpInst;
|
|
|
|
|
|
|
|
if (IsFloat)
|
|
|
|
{
|
2018-05-17 20:25:42 +02:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabs (OperB, AbsB);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
CmpInst = OpCode.CmpF();
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
CmpInst = OpCode.Cmp();
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-04-10 21:50:32 +02:00
|
|
|
ShaderIrOp Op = new ShaderIrOp(CmpInst, OperA, OperB);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrOperPred P0Node = OpCode.Pred3();
|
|
|
|
ShaderIrOperPred P1Node = OpCode.Pred0();
|
|
|
|
ShaderIrOperPred P2Node = OpCode.Pred39();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop45();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
if (LopInst == ShaderIrInst.Band && P1Node.IsConst && P2Node.IsConst)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode P2NNode = P2Node;
|
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
if (NegP)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
P2NNode = new ShaderIrOp(ShaderIrInst.Bnot, P2NNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(ShaderIrInst.Bnot, P0Node);
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, Op, P2NNode);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P1Node, Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, P0Node, P2NNode);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-01-31 13:43:24 +01:00
|
|
|
private static void EmitBinaryHalfOp(ShaderIrBlock Block, long OpCode, ShaderIrInst Inst)
|
|
|
|
{
|
|
|
|
bool AbsB = OpCode.Read(30);
|
|
|
|
bool NegB = OpCode.Read(31);
|
|
|
|
bool Sat = OpCode.Read(32);
|
|
|
|
bool AbsA = OpCode.Read(44);
|
|
|
|
|
|
|
|
ShaderIrOperGpr[] VecA = OpCode.GprHalfVec8();
|
|
|
|
ShaderIrOperGpr[] VecB = OpCode.GprHalfVec20();
|
|
|
|
|
|
|
|
HalfOutputType OutputType = (HalfOutputType)OpCode.Read(49, 3);
|
|
|
|
|
|
|
|
int Elems = OutputType == HalfOutputType.PackedFp16 ? 2 : 1;
|
|
|
|
int First = OutputType == HalfOutputType.MergeH1 ? 1 : 0;
|
|
|
|
|
|
|
|
for (int Index = First; Index < Elems; Index++)
|
|
|
|
{
|
|
|
|
ShaderIrNode OperA = GetAluFabs (VecA[Index], AbsA);
|
|
|
|
ShaderIrNode OperB = GetAluFabsFneg(VecB[Index], AbsB, NegB);
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
|
|
|
|
ShaderIrOperGpr Dst = GetHalfDst(OpCode, OutputType, Index);
|
|
|
|
|
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(Dst, GetAluFsat(Op, Sat))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ShaderIrOperGpr GetHalfDst(long OpCode, HalfOutputType OutputType, int Index)
|
|
|
|
{
|
|
|
|
switch (OutputType)
|
|
|
|
{
|
|
|
|
case HalfOutputType.PackedFp16: return OpCode.GprHalf0(Index);
|
|
|
|
case HalfOutputType.Fp32: return OpCode.Gpr0();
|
|
|
|
case HalfOutputType.MergeH0: return OpCode.GprHalf0(0);
|
|
|
|
case HalfOutputType.MergeH1: return OpCode.GprHalf0(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArgumentException(nameof(OutputType));
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:50:00 +02:00
|
|
|
private static void EmitLop(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
int SubOp = OpCode.Read(41, 3);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
bool InvA = OpCode.Read(39);
|
|
|
|
bool InvB = OpCode.Read(40);
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
ShaderIrInst Inst = 0;
|
|
|
|
|
|
|
|
switch (SubOp)
|
|
|
|
{
|
|
|
|
case 0: Inst = ShaderIrInst.And; break;
|
|
|
|
case 1: Inst = ShaderIrInst.Or; break;
|
|
|
|
case 2: Inst = ShaderIrInst.Xor; break;
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = GetAluNot(OpCode.Gpr8(), InvA);
|
2018-07-17 21:50:00 +02:00
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-07-17 21:50:00 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB = GetAluNot(OperB, InvB);
|
|
|
|
|
|
|
|
ShaderIrNode Op;
|
|
|
|
|
|
|
|
if (SubOp < 3)
|
|
|
|
{
|
|
|
|
Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Op = OperB;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode Compare = new ShaderIrOp(ShaderIrInst.Cne, Op, new ShaderIrOperImm(0));
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Pred48(), Compare)));
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-05-30 01:37:10 +02:00
|
|
|
|
|
|
|
private static void EmitXmad(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
|
|
|
//TODO: Confirm SignAB/C, it is just a guess.
|
|
|
|
//TODO: Implement Mode 3 (CSFU), what it does?
|
2018-09-08 19:51:50 +02:00
|
|
|
bool SignAB = OpCode.Read(48);
|
|
|
|
bool SignC = OpCode.Read(49);
|
|
|
|
bool HighB = OpCode.Read(52);
|
|
|
|
bool HighA = OpCode.Read(53);
|
2018-05-30 01:37:10 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
int Mode = OpCode.Read(50, 7);
|
2018-05-30 01:37:10 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB, OperC;
|
2018-05-30 01:37:10 +02:00
|
|
|
|
|
|
|
ShaderIrOperImm Imm16 = new ShaderIrOperImm(16);
|
|
|
|
ShaderIrOperImm ImmMsk = new ShaderIrOperImm(0xffff);
|
|
|
|
|
|
|
|
ShaderIrInst ShiftAB = SignAB ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
ShaderIrInst ShiftC = SignC ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
|
|
|
|
if (HighA)
|
|
|
|
{
|
|
|
|
OperA = new ShaderIrOp(ShiftAB, OperA, Imm16);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.RC: OperB = OpCode.Gpr39(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
2018-05-30 01:37:10 +02:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProductShiftLeft = false, Merge = false;
|
|
|
|
|
|
|
|
if (Oper == ShaderOper.RC)
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperC = OpCode.Cbuf34();
|
2018-05-30 01:37:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 19:51:50 +02:00
|
|
|
OperC = OpCode.Gpr39();
|
2018-05-30 01:37:10 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
ProductShiftLeft = OpCode.Read(36);
|
|
|
|
Merge = OpCode.Read(37);
|
2018-05-30 01:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Mode)
|
|
|
|
{
|
|
|
|
//CLO.
|
|
|
|
case 1: OperC = ExtendTo32(OperC, SignC, 16); break;
|
|
|
|
|
|
|
|
//CHI.
|
|
|
|
case 2: OperC = new ShaderIrOp(ShiftC, OperC, Imm16); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode OperBH = OperB;
|
|
|
|
|
|
|
|
if (HighB)
|
|
|
|
{
|
|
|
|
OperBH = new ShaderIrOp(ShiftAB, OperBH, Imm16);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp MulOp = new ShaderIrOp(ShaderIrInst.Mul, OperA, OperBH);
|
|
|
|
|
|
|
|
if (ProductShiftLeft)
|
|
|
|
{
|
|
|
|
MulOp = new ShaderIrOp(ShaderIrInst.Lsl, MulOp, Imm16);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp AddOp = new ShaderIrOp(ShaderIrInst.Add, MulOp, OperC);
|
|
|
|
|
|
|
|
if (Merge)
|
|
|
|
{
|
|
|
|
AddOp = new ShaderIrOp(ShaderIrInst.And, AddOp, ImmMsk);
|
|
|
|
OperB = new ShaderIrOp(ShaderIrInst.Lsl, OperB, Imm16);
|
|
|
|
AddOp = new ShaderIrOp(ShaderIrInst.Or, AddOp, OperB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Mode == 4)
|
|
|
|
{
|
|
|
|
OperB = new ShaderIrOp(ShaderIrInst.Lsl, OperB, Imm16);
|
|
|
|
AddOp = new ShaderIrOp(ShaderIrInst.Or, AddOp, OperB);
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), AddOp)));
|
2018-05-30 01:37:10 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|