From 4b81d19a1a4f3edd09a5e83d0ceae43462cb4ef1 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 19 Sep 2019 20:56:29 -0400 Subject: [PATCH 1/2] Shader_IR: Implement ICMP. --- src/video_core/engines/shader_bytecode.h | 11 ++++++++ .../shader/decode/arithmetic_integer.cpp | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 052e6d24e..82d912c76 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h @@ -933,6 +933,11 @@ union Instruction { BitField<49, 3, PredCondition> cond; } isetp; + union { + BitField<48, 1, u64> is_signed; + BitField<49, 3, PredCondition> cond; + } icmp; + union { BitField<0, 3, u64> pred0; BitField<3, 3, u64> pred3; @@ -1628,6 +1633,9 @@ public: SEL_C, SEL_R, SEL_IMM, + ICMP_RC, + ICMP_R, + ICMP_CR, MUFU, // Multi-Function Operator RRO_C, // Range Reduction Operator RRO_R, @@ -1892,6 +1900,9 @@ private: INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"), INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"), INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"), + INST("010100110100----", Id::ICMP_RC, Type::ArithmeticInteger, "ICMP_RC"), + INST("010110110100----", Id::ICMP_R, Type::ArithmeticInteger, "ICMP_R"), + INST("010010110100----", Id::ICMP_CR, Type::ArithmeticInteger, "ICMP_CR"), INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"), INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"), INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"), diff --git a/src/video_core/shader/decode/arithmetic_integer.cpp b/src/video_core/shader/decode/arithmetic_integer.cpp index c8c1a7f40..1aa21010a 100644 --- a/src/video_core/shader/decode/arithmetic_integer.cpp +++ b/src/video_core/shader/decode/arithmetic_integer.cpp @@ -138,6 +138,32 @@ u32 ShaderIR::DecodeArithmeticInteger(NodeBlock& bb, u32 pc) { SetRegister(bb, instr.gpr0, value); break; } + case OpCode::Id::ICMP_CR: + case OpCode::Id::ICMP_R: + case OpCode::Id::ICMP_RC: { + UNIMPLEMENTED_IF(instr.icmp.is_signed != 0); + const Node zero = Immediate(0); + + const auto [op_a, op_b] = [&]() -> std::tuple { + switch (opcode->get().GetId()) { + case OpCode::Id::ICMP_CR: + return {GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset), + GetRegister(instr.gpr39)}; + case OpCode::Id::ICMP_R: + return {GetRegister(instr.gpr20), GetRegister(instr.gpr39)}; + case OpCode::Id::ICMP_RC: + return {GetRegister(instr.gpr39), + GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset)}; + default: + UNIMPLEMENTED(); + return {zero, zero}; + } + }(); + const Node test = GetRegister(instr.gpr8); + const Node comparison = GetPredicateComparisonInteger(instr.icmp.cond, false, test, zero); + SetRegister(bb, instr.gpr0, Operation(OperationCode::Select, comparison, op_a, op_b)); + break; + } case OpCode::Id::LOP_C: case OpCode::Id::LOP_R: case OpCode::Id::LOP_IMM: { From 527b841c1567fd7552153eea0fdcee119e44c53f Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 20 Sep 2019 11:41:05 -0400 Subject: [PATCH 2/2] Shader_IR: ICMP corrections and fixes --- src/video_core/engines/shader_bytecode.h | 2 ++ .../shader/decode/arithmetic_integer.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 82d912c76..203e7758c 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h @@ -1636,6 +1636,7 @@ public: ICMP_RC, ICMP_R, ICMP_CR, + ICMP_IMM, MUFU, // Multi-Function Operator RRO_C, // Range Reduction Operator RRO_R, @@ -1903,6 +1904,7 @@ private: INST("010100110100----", Id::ICMP_RC, Type::ArithmeticInteger, "ICMP_RC"), INST("010110110100----", Id::ICMP_R, Type::ArithmeticInteger, "ICMP_R"), INST("010010110100----", Id::ICMP_CR, Type::ArithmeticInteger, "ICMP_CR"), + INST("0011011-0100----", Id::ICMP_IMM, Type::ArithmeticInteger, "ICMP_IMM"), INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"), INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"), INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"), diff --git a/src/video_core/shader/decode/arithmetic_integer.cpp b/src/video_core/shader/decode/arithmetic_integer.cpp index 1aa21010a..b73f6536e 100644 --- a/src/video_core/shader/decode/arithmetic_integer.cpp +++ b/src/video_core/shader/decode/arithmetic_integer.cpp @@ -140,11 +140,11 @@ u32 ShaderIR::DecodeArithmeticInteger(NodeBlock& bb, u32 pc) { } case OpCode::Id::ICMP_CR: case OpCode::Id::ICMP_R: - case OpCode::Id::ICMP_RC: { - UNIMPLEMENTED_IF(instr.icmp.is_signed != 0); + case OpCode::Id::ICMP_RC: + case OpCode::Id::ICMP_IMM: { const Node zero = Immediate(0); - const auto [op_a, op_b] = [&]() -> std::tuple { + const auto [op_b, test] = [&]() -> std::pair { switch (opcode->get().GetId()) { case OpCode::Id::ICMP_CR: return {GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset), @@ -154,13 +154,16 @@ u32 ShaderIR::DecodeArithmeticInteger(NodeBlock& bb, u32 pc) { case OpCode::Id::ICMP_RC: return {GetRegister(instr.gpr39), GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset)}; + case OpCode::Id::ICMP_IMM: + return {Immediate(instr.alu.GetSignedImm20_20()), GetRegister(instr.gpr39)}; default: - UNIMPLEMENTED(); + UNREACHABLE(); return {zero, zero}; } }(); - const Node test = GetRegister(instr.gpr8); - const Node comparison = GetPredicateComparisonInteger(instr.icmp.cond, false, test, zero); + const Node op_a = GetRegister(instr.gpr8); + const Node comparison = + GetPredicateComparisonInteger(instr.icmp.cond, instr.icmp.is_signed != 0, test, zero); SetRegister(bb, instr.gpr0, Operation(OperationCode::Select, comparison, op_a, op_b)); break; }