2018-04-08 12:17:35 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Gal.Shader.ShaderDecodeHelper;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static partial class ShaderDecode
|
|
|
|
{
|
2019-01-31 04:43:24 -08:00
|
|
|
private enum HalfOutputType
|
|
|
|
{
|
|
|
|
PackedFp16,
|
|
|
|
Fp32,
|
|
|
|
MergeH0,
|
|
|
|
MergeH1
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Bfe_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Bfe_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Bfe_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitBfe(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.CR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fadd_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-27 19:55:08 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Immf32_20();
|
2018-06-27 19:55:08 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(53);
|
|
|
|
bool AbsA = OpCode.Read(54);
|
|
|
|
bool NegA = OpCode.Read(56);
|
|
|
|
bool AbsB = OpCode.Read(57);
|
2018-06-27 19:55:08 -07:00
|
|
|
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Fadd, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-06-27 19:55:08 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFadd(Block, OpCode, ShaderOper.RR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Ffma_CR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.CR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Ffma_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Ffma_RC(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.RC);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Ffma_RR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
EmitFfma(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmnmx_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.CR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmnmx_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmnmx_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitFmnmx(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmul_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-19 12:18:30 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Immf32_20();
|
2018-04-19 12:18:30 -07:00
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Fmul, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-19 12:18:30 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmul_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.CR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmul_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.Immf);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fmul_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 15:46:36 -07:00
|
|
|
EmitFmul(Block, OpCode, ShaderOper.RR);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fset_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-25 19:11:26 -07:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fset_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-25 19:11:26 -07:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fset_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-25 19:11:26 -07:00
|
|
|
{
|
|
|
|
EmitFset(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fsetp_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fsetp_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Fsetp_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitFsetp(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2019-01-31 04:43:24 -08: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-17 21:30:35 -07:00
|
|
|
public static void Iadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
|
|
|
ShaderIrNode OperB = OpCode.Imm32_20();
|
2018-07-17 12:50:00 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegA = OpCode.Read(56);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
|
|
|
OperA = GetAluIneg(OperA, NegA);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Add, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-07-17 12:50:00 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd3_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd3_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iadd3_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIadd3(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Imnmx_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Imnmx_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Imnmx_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitImnmx(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Ipa(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Abuf28();
|
|
|
|
ShaderIrNode OperB = OpCode.Gpr20();
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIpaMode Mode = (ShaderIpaMode)(OpCode.Read(54, 3));
|
2018-09-01 14:44:19 -07:00
|
|
|
|
|
|
|
ShaderIrMetaIpa Meta = new ShaderIrMetaIpa(Mode);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Ipa, OperA, OperB, null, Meta);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iscadd_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iscadd_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iscadd_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitIscadd(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iset_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iset_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Iset_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitIset(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Isetp_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 12:50:32 -07:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Isetp_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 12:50:32 -07:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Isetp_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-10 12:50:32 -07:00
|
|
|
{
|
|
|
|
EmitIsetp(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Lop_I32(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
int SubOp = OpCode.Read(53, 3);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool InvA = OpCode.Read(55);
|
|
|
|
bool InvB = OpCode.Read(56);
|
2018-04-08 12:17:35 -07: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 10:51:50 -07:00
|
|
|
ShaderIrNode OperB = GetAluNot(OpCode.Imm32_20(), InvB);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
//SubOp == 3 is pass, used by the not instruction
|
|
|
|
//which just moves the inverted register value.
|
|
|
|
if (SubOp < 3)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = GetAluNot(OpCode.Gpr8(), InvA);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperB)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Lop_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Lop_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Lop_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-17 12:50:00 -07:00
|
|
|
{
|
|
|
|
EmitLop(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Mufu(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
int SubOp = OpCode.Read(20, 0xf);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
ShaderIrInst Inst = 0;
|
|
|
|
|
|
|
|
switch (SubOp)
|
|
|
|
{
|
2018-06-22 22:00:44 -07: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 12:17:35 -07:00
|
|
|
|
|
|
|
default: throw new NotImplementedException(SubOp.ToString());
|
|
|
|
}
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
ShaderIrOp Op = new ShaderIrOp(Inst, GetAluFabsFneg(OperA, AbsA, NegA));
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Psetp(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-01 20:50:56 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegA = OpCode.Read(15);
|
|
|
|
bool NegB = OpCode.Read(32);
|
|
|
|
bool NegP = OpCode.Read(42);
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop24();
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Pred12();
|
|
|
|
ShaderIrNode OperB = OpCode.Pred29();
|
2018-06-01 20:50:56 -07: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 10:51:50 -07:00
|
|
|
ShaderIrOperPred P0Node = OpCode.Pred3();
|
|
|
|
ShaderIrOperPred P1Node = OpCode.Pred0();
|
|
|
|
ShaderIrOperPred P2Node = OpCode.Pred39();
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
LopInst = OpCode.BLop45();
|
2018-06-01 20:50:56 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P1Node, Op)));
|
2018-06-01 20:50:56 -07:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, P0Node, P2NNode);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-06-01 20:50:56 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Rro_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-01 20:50:56 -07:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Rro_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-01 20:50:56 -07:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.Immf);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Rro_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-06-01 20:50:56 -07:00
|
|
|
{
|
|
|
|
EmitRro(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shl_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.CR, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shl_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.Imm, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shl_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.RR, ShaderIrInst.Lsl);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shr_C(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.CR, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shr_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.Imm, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Shr_R(ShaderIrBlock Block, long OpCode, int Position)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
EmitAluBinary(Block, OpCode, ShaderOper.RR, GetShrInst(OpCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ShaderIrInst GetShrInst(long OpCode)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool Signed = OpCode.Read(48);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
return Signed ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Vmad(ShaderIrBlock Block, long OpCode, int Position)
|
2018-07-18 22:33:27 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-07-18 22:33:27 -07:00
|
|
|
|
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
if (OpCode.Read(50))
|
2018-07-18 22:33:27 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperB = OpCode.Gpr20();
|
2018-07-18 22:33:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperB = OpCode.Imm19_20();
|
2018-07-18 22:33:27 -07:00
|
|
|
}
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrOperGpr OperC = OpCode.Gpr39();
|
2018-07-18 22:33:27 -07:00
|
|
|
|
|
|
|
ShaderIrNode Tmp = new ShaderIrOp(ShaderIrInst.Mul, OperA, OperB);
|
|
|
|
|
|
|
|
ShaderIrNode Final = new ShaderIrOp(ShaderIrInst.Add, Tmp, OperC);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
int Shr = OpCode.Read(51, 3);
|
2018-07-18 22:33:27 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Final)));
|
2018-07-18 22:33:27 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Xmad_CR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.CR);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Xmad_I(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.Imm);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Xmad_RC(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.RC);
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
public static void Xmad_RR(ShaderIrBlock Block, long OpCode, int Position)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
|
|
|
EmitXmad(Block, OpCode, ShaderOper.RR);
|
|
|
|
}
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
private static void EmitAluBinary(
|
|
|
|
ShaderIrBlock Block,
|
|
|
|
long OpCode,
|
|
|
|
ShaderOper Oper,
|
|
|
|
ShaderIrInst Inst)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:17:35 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(Inst, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
private static void EmitBfe(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-05-17 11:25:42 -07: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 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegA = OpCode.Read(49);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-05-17 11:25:42 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 11:25:42 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode Op;
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool Signed = OpCode.Read(48); //?
|
2018-05-17 11:25:42 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-05-17 11:25:42 -07:00
|
|
|
}
|
|
|
|
|
2018-08-13 15:46:36 -07:00
|
|
|
private static void EmitFadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
|
|
|
bool AbsB = OpCode.Read(49);
|
2018-10-13 19:54:14 -07:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-08-13 15:46:36 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-08-13 15:46:36 -07:00
|
|
|
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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-13 15:46:36 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(ShaderIrInst.Fadd, OperA, OperB);
|
|
|
|
|
2018-10-13 19:54:14 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-08-13 15:46:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitFmul(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(48);
|
2018-10-13 19:54:14 -07:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-08-13 15:46:36 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-08-13 15:46:36 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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-13 15:46:36 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB = GetAluFneg(OperB, NegB);
|
|
|
|
|
|
|
|
ShaderIrNode Op = new ShaderIrOp(ShaderIrInst.Fmul, OperA, OperB);
|
|
|
|
|
2018-10-13 19:54:14 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-08-13 15:46:36 -07:00
|
|
|
}
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
private static void EmitFfma(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegC = OpCode.Read(49);
|
2018-10-13 19:54:14 -07:00
|
|
|
bool Sat = OpCode.Read(50);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB, OperC;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:17:35 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
OperB = GetAluFneg(OperB, NegB);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
if (Oper == ShaderOper.RC)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperC = GetAluFneg(OpCode.Cbuf34(), NegC);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperC = GetAluFneg(OpCode.Gpr39(), NegC);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Ffma, OperA, OperB, OperC);
|
|
|
|
|
2018-10-13 19:54:14 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), GetAluFsat(Op, Sat))));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-07-17 12:50:00 -07:00
|
|
|
private static void EmitIadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8();
|
2018-07-17 12:50:00 -07:00
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:50:00 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegA = OpCode.Read(49);
|
|
|
|
bool NegB = OpCode.Read(48);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
|
|
|
OperA = GetAluIneg(OperA, NegA);
|
|
|
|
OperB = GetAluIneg(OperB, NegB);
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(ShaderIrInst.Add, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-07-17 12:50:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitIadd3(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
int Mode = OpCode.Read(37, 3);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool Neg1 = OpCode.Read(51);
|
|
|
|
bool Neg2 = OpCode.Read(50);
|
|
|
|
bool Neg3 = OpCode.Read(49);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
int Height1 = OpCode.Read(35, 3);
|
|
|
|
int Height2 = OpCode.Read(33, 3);
|
|
|
|
int Height3 = OpCode.Read(31, 3);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:50:00 -07: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 10:51:50 -07:00
|
|
|
ShaderIrNode Src1 = GetAluIneg(ApplyHeight(OpCode.Gpr8(), Height1), Neg1);
|
2018-10-23 13:59:52 -07:00
|
|
|
ShaderIrNode Src2 = GetAluIneg(ApplyHeight(OperB, Height2), Neg2);
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode Src3 = GetAluIneg(ApplyHeight(OpCode.Gpr39(), Height3), Neg3);
|
2018-07-17 12:50:00 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), new ShaderIrOp(ShaderIrInst.Add, Sum, Src3))));
|
2018-07-17 12:50:00 -07:00
|
|
|
}
|
|
|
|
|
2018-06-01 20:50:56 -07:00
|
|
|
private static void EmitIscadd(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(48);
|
|
|
|
bool NegA = OpCode.Read(49);
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-06-01 20:50:56 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrOperImm Scale = OpCode.Imm5_39();
|
2018-06-01 20:50:56 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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-01 20:50:56 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), AddOp)));
|
2018-06-01 20:50:56 -07:00
|
|
|
}
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
private static void EmitFmnmx(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-05-29 16:37:10 -07: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 11:25:42 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool NegB = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(46);
|
|
|
|
bool NegA = OpCode.Read(48);
|
|
|
|
bool AbsB = OpCode.Read(49);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-05-29 16:37:10 -07:00
|
|
|
if (IsFloat)
|
|
|
|
{
|
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OperA = GetAluIabsIneg(OperA, AbsA, NegA);
|
|
|
|
}
|
2018-05-17 11:25:42 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 11:25:42 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-05-29 16:37:10 -07:00
|
|
|
if (IsFloat)
|
|
|
|
{
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OperB = GetAluIabsIneg(OperB, AbsB, NegB);
|
|
|
|
}
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrOperPred Pred = OpCode.Pred39();
|
2018-05-17 11:25:42 -07:00
|
|
|
|
|
|
|
ShaderIrOp Op;
|
|
|
|
|
2018-05-29 16:37:10 -07:00
|
|
|
ShaderIrInst MaxInst = IsFloat ? ShaderIrInst.Fmax : ShaderIrInst.Max;
|
|
|
|
ShaderIrInst MinInst = IsFloat ? ShaderIrInst.Fmin : ShaderIrInst.Min;
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
if (Pred.IsConst)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool IsMax = OpCode.Read(42);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(IsMax
|
2018-05-29 16:37:10 -07:00
|
|
|
? MaxInst
|
|
|
|
: MinInst, OperA, OperB);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-05-17 11:25:42 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode PredN = OpCode.Pred39N();
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-05-29 16:37:10 -07:00
|
|
|
ShaderIrOp OpMax = new ShaderIrOp(MaxInst, OperA, OperB);
|
|
|
|
ShaderIrOp OpMin = new ShaderIrOp(MinInst, OperA, OperB);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrAsg AsgMax = new ShaderIrAsg(OpCode.Gpr0(), OpMax);
|
|
|
|
ShaderIrAsg AsgMin = new ShaderIrAsg(OpCode.Gpr0(), OpMin);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrCond(PredN, AsgMax, Not: true)));
|
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrCond(PredN, AsgMin, Not: false)));
|
2018-05-17 11:25:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-02 07:44:52 -07:00
|
|
|
private static void EmitRro(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-05-17 11:25:42 -07:00
|
|
|
{
|
2018-06-01 20:50:56 -07: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 10:51:50 -07:00
|
|
|
bool NegA = OpCode.Read(45);
|
|
|
|
bool AbsA = OpCode.Read(49);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-06-01 20:50:56 -07:00
|
|
|
ShaderIrNode OperA;
|
2018-05-17 11:25:42 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 11:25:42 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-06-01 20:50:56 -07:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
2018-05-17 11:25:42 -07:00
|
|
|
|
2018-07-18 22:33:27 -07:00
|
|
|
Block.AddNode(new ShaderIrCmnt("Stubbed."));
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperA)));
|
2018-05-17 11:25:42 -07:00
|
|
|
}
|
|
|
|
|
2018-04-25 19:11:26 -07: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 10:51:50 -07:00
|
|
|
bool NegA = OpCode.Read(43);
|
|
|
|
bool AbsB = OpCode.Read(44);
|
|
|
|
bool NegB = OpCode.Read(53);
|
|
|
|
bool AbsA = OpCode.Read(54);
|
2018-08-03 09:54:34 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool BoolFloat = OpCode.Read(IsFloat ? 52 : 44);
|
2018-04-25 19:11:26 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-25 19:11:26 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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-25 19:11:26 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrInst CmpInst;
|
|
|
|
|
|
|
|
if (IsFloat)
|
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabsFneg(OperB, AbsB, NegB);
|
2018-04-25 19:11:26 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
CmpInst = OpCode.CmpF();
|
2018-04-25 19:11:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
CmpInst = OpCode.Cmp();
|
2018-04-25 19:11:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp Op = new ShaderIrOp(CmpInst, OperA, OperB);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop45();
|
2018-04-25 19:11:26 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrOperPred PNode = OpCode.Pred39();
|
2018-04-25 19:11:26 -07:00
|
|
|
|
2018-05-17 11:25:42 -07: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-25 19:11:26 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode Asg0 = new ShaderIrAsg(OpCode.Gpr0(), Imm0);
|
|
|
|
ShaderIrNode Asg1 = new ShaderIrAsg(OpCode.Gpr0(), Imm1);
|
2018-04-25 19:11:26 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(Asg0));
|
|
|
|
Block.AddNode(OpCode.PredNode(Asg1));
|
2018-04-25 19:11:26 -07:00
|
|
|
}
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
private static void EmitFsetp(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
2018-04-10 12:50:32 -07: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 12:17:35 -07:00
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
bool AbsA = OpCode.Read(7);
|
|
|
|
bool NegP = OpCode.Read(42);
|
|
|
|
bool NegA = OpCode.Read(43);
|
|
|
|
bool AbsB = OpCode.Read(44);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:17:35 -07:00
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:50:32 -07:00
|
|
|
ShaderIrInst CmpInst;
|
|
|
|
|
|
|
|
if (IsFloat)
|
|
|
|
{
|
2018-05-17 11:25:42 -07:00
|
|
|
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
|
|
|
OperB = GetAluFabs (OperB, AbsB);
|
2018-04-10 12:50:32 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
CmpInst = OpCode.CmpF();
|
2018-04-10 12:50:32 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
CmpInst = OpCode.Cmp();
|
2018-04-10 12:50:32 -07:00
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-04-10 12:50:32 -07:00
|
|
|
ShaderIrOp Op = new ShaderIrOp(CmpInst, OperA, OperB);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrOperPred P0Node = OpCode.Pred3();
|
|
|
|
ShaderIrOperPred P1Node = OpCode.Pred0();
|
|
|
|
ShaderIrOperPred P2Node = OpCode.Pred39();
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrInst LopInst = OpCode.BLop45();
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
if (LopInst == ShaderIrInst.Band && P1Node.IsConst && P2Node.IsConst)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrNode P2NNode = P2Node;
|
|
|
|
|
2018-05-17 11:25:42 -07:00
|
|
|
if (NegP)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
P2NNode = new ShaderIrOp(ShaderIrInst.Bnot, P2NNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(ShaderIrInst.Bnot, P0Node);
|
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, Op, P2NNode);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P1Node, Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
Op = new ShaderIrOp(LopInst, P0Node, P2NNode);
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(P0Node, Op)));
|
2018-07-17 12:50:00 -07:00
|
|
|
}
|
|
|
|
|
2019-01-31 04:43:24 -08: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 12:50:00 -07:00
|
|
|
private static void EmitLop(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
int SubOp = OpCode.Read(41, 3);
|
2018-07-17 12:50:00 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
bool InvA = OpCode.Read(39);
|
|
|
|
bool InvB = OpCode.Read(40);
|
2018-07-17 12:50:00 -07: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 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = GetAluNot(OpCode.Gpr8(), InvA);
|
2018-07-17 12:50:00 -07:00
|
|
|
ShaderIrNode OperB;
|
|
|
|
|
|
|
|
switch (Oper)
|
|
|
|
{
|
2018-09-08 10:51:50 -07: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 12:50:00 -07: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 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Pred48(), Compare)));
|
2018-07-17 12:50:00 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
private enum XmadMode
|
|
|
|
{
|
|
|
|
Cfull = 0,
|
|
|
|
Clo = 1,
|
|
|
|
Chi = 2,
|
|
|
|
Csfu = 3,
|
|
|
|
Cbcc = 4
|
|
|
|
}
|
|
|
|
|
2018-05-29 16:37:10 -07:00
|
|
|
private static void EmitXmad(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
|
|
|
{
|
2019-02-14 19:23:14 -08:00
|
|
|
bool SignedA = OpCode.Read(48);
|
|
|
|
bool SignedB = OpCode.Read(49);
|
|
|
|
bool HighB = OpCode.Read(52);
|
|
|
|
bool HighA = OpCode.Read(53);
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
int Mode = OpCode.Read(50, 7);
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ShaderIrNode OperA = OpCode.Gpr8(), OperB, OperC;
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
switch (Oper)
|
|
|
|
{
|
|
|
|
case ShaderOper.CR: OperB = OpCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: OperB = OpCode.ImmU16_20(); break;
|
|
|
|
case ShaderOper.RC: OperB = OpCode.Gpr39(); break;
|
|
|
|
case ShaderOper.RR: OperB = OpCode.Gpr20(); break;
|
|
|
|
|
|
|
|
default: throw new ArgumentException(nameof(Oper));
|
|
|
|
}
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
ShaderIrNode OperB2 = OperB;
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
if (Oper == ShaderOper.Imm)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
2019-02-14 19:23:14 -08:00
|
|
|
int Imm = ((ShaderIrOperImm)OperB2).Value;
|
|
|
|
|
|
|
|
if (!HighB)
|
|
|
|
{
|
|
|
|
Imm <<= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SignedB)
|
|
|
|
{
|
|
|
|
Imm >>= 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Imm = (int)((uint)Imm >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
OperB2 = new ShaderIrOperImm(Imm);
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
ShaderIrOperImm Imm16 = new ShaderIrOperImm(16);
|
|
|
|
|
|
|
|
//If we are working with the lower 16-bits of the A/B operands,
|
|
|
|
//we need to shift the lower 16-bits to the top 16-bits. Later,
|
|
|
|
//they will be right shifted. For U16 types, this will be a logical
|
|
|
|
//right shift, and for S16 types, a arithmetic right shift.
|
|
|
|
if (!HighA)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
2019-02-14 19:23:14 -08:00
|
|
|
OperA = new ShaderIrOp(ShaderIrInst.Lsl, OperA, Imm16);
|
|
|
|
}
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
if (!HighB && Oper != ShaderOper.Imm)
|
|
|
|
{
|
|
|
|
OperB2 = new ShaderIrOp(ShaderIrInst.Lsl, OperB2, Imm16);
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
ShaderIrInst ShiftA = SignedA ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
ShaderIrInst ShiftB = SignedB ? ShaderIrInst.Asr : ShaderIrInst.Lsr;
|
|
|
|
|
|
|
|
OperA = new ShaderIrOp(ShiftA, OperA, Imm16);
|
|
|
|
|
|
|
|
if (Oper != ShaderOper.Imm)
|
|
|
|
{
|
|
|
|
OperB2 = new ShaderIrOp(ShiftB, OperB2, Imm16);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProductShiftLeft = false;
|
|
|
|
bool Merge = false;
|
2018-05-29 16:37:10 -07:00
|
|
|
|
|
|
|
if (Oper == ShaderOper.RC)
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperC = OpCode.Cbuf34();
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-08 10:51:50 -07:00
|
|
|
OperC = OpCode.Gpr39();
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
ProductShiftLeft = OpCode.Read(36);
|
|
|
|
Merge = OpCode.Read(37);
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
ShaderIrOp MulOp = new ShaderIrOp(ShaderIrInst.Mul, OperA, OperB2);
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
if (ProductShiftLeft)
|
|
|
|
{
|
|
|
|
MulOp = new ShaderIrOp(ShaderIrInst.Lsl, MulOp, Imm16);
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
switch ((XmadMode)Mode)
|
2018-05-29 16:37:10 -07:00
|
|
|
{
|
2019-02-14 19:23:14 -08:00
|
|
|
case XmadMode.Clo: OperC = ExtendTo32(OperC, Signed: false, Size: 16); break;
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
case XmadMode.Chi: OperC = new ShaderIrOp(ShaderIrInst.Lsr, OperC, Imm16); break;
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
case XmadMode.Cbcc:
|
|
|
|
{
|
|
|
|
ShaderIrOp OperBLsh16 = new ShaderIrOp(ShaderIrInst.Lsl, OperB, Imm16);
|
|
|
|
|
|
|
|
OperC = new ShaderIrOp(ShaderIrInst.Add, OperC, OperBLsh16);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XmadMode.Csfu:
|
|
|
|
{
|
|
|
|
ShaderIrOperImm Imm31 = new ShaderIrOperImm(31);
|
|
|
|
|
|
|
|
ShaderIrOp SignAdjustA = new ShaderIrOp(ShaderIrInst.Lsr, OperA, Imm31);
|
|
|
|
ShaderIrOp SignAdjustB = new ShaderIrOp(ShaderIrInst.Lsr, OperB2, Imm31);
|
|
|
|
|
|
|
|
SignAdjustA = new ShaderIrOp(ShaderIrInst.Lsl, SignAdjustA, Imm16);
|
|
|
|
SignAdjustB = new ShaderIrOp(ShaderIrInst.Lsl, SignAdjustB, Imm16);
|
|
|
|
|
|
|
|
ShaderIrOp SignAdjust = new ShaderIrOp(ShaderIrInst.Add, SignAdjustA, SignAdjustB);
|
|
|
|
|
|
|
|
OperC = new ShaderIrOp(ShaderIrInst.Sub, OperC, SignAdjust);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIrOp AddOp = new ShaderIrOp(ShaderIrInst.Add, MulOp, OperC);
|
|
|
|
|
|
|
|
if (Merge)
|
|
|
|
{
|
2019-02-14 19:23:14 -08:00
|
|
|
ShaderIrOperImm Imm16Mask = new ShaderIrOperImm(0xffff);
|
2018-05-29 16:37:10 -07:00
|
|
|
|
2019-02-14 19:23:14 -08:00
|
|
|
AddOp = new ShaderIrOp(ShaderIrInst.And, AddOp, Imm16Mask);
|
2018-05-29 16:37:10 -07:00
|
|
|
OperB = new ShaderIrOp(ShaderIrInst.Lsl, OperB, Imm16);
|
|
|
|
AddOp = new ShaderIrOp(ShaderIrInst.Or, AddOp, OperB);
|
|
|
|
}
|
|
|
|
|
2018-09-08 10:51:50 -07:00
|
|
|
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), AddOp)));
|
2018-05-29 16:37:10 -07:00
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
}
|