arithmetic_integer.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/common_types.h"
  6. #include "video_core/engines/shader_bytecode.h"
  7. #include "video_core/shader/shader_ir.h"
  8. namespace VideoCommon::Shader {
  9. using Tegra::Shader::Instruction;
  10. using Tegra::Shader::OpCode;
  11. u32 ShaderIR::DecodeArithmeticInteger(BasicBlock& bb, u32 pc) {
  12. const Instruction instr = {program_code[pc]};
  13. const auto opcode = OpCode::Decode(instr);
  14. Node op_a = GetRegister(instr.gpr8);
  15. Node op_b = [&]() {
  16. if (instr.is_b_imm) {
  17. return Immediate(instr.alu.GetSignedImm20_20());
  18. } else if (instr.is_b_gpr) {
  19. return GetRegister(instr.gpr20);
  20. } else {
  21. return GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset);
  22. }
  23. }();
  24. switch (opcode->get().GetId()) {
  25. case OpCode::Id::IADD_C:
  26. case OpCode::Id::IADD_R:
  27. case OpCode::Id::IADD_IMM: {
  28. UNIMPLEMENTED_IF_MSG(instr.generates_cc,
  29. "Condition codes generation in IADD is not implemented");
  30. UNIMPLEMENTED_IF_MSG(instr.alu.saturate_d, "IADD saturation not implemented");
  31. op_a = GetOperandAbsNegInteger(op_a, false, instr.alu_integer.negate_a, true);
  32. op_b = GetOperandAbsNegInteger(op_b, false, instr.alu_integer.negate_b, true);
  33. SetRegister(bb, instr.gpr0, Operation(OperationCode::IAdd, PRECISE, op_a, op_b));
  34. break;
  35. }
  36. case OpCode::Id::ISCADD_C:
  37. case OpCode::Id::ISCADD_R:
  38. case OpCode::Id::ISCADD_IMM: {
  39. UNIMPLEMENTED_IF_MSG(instr.generates_cc,
  40. "Condition codes generation in ISCADD is not implemented");
  41. op_a = GetOperandAbsNegInteger(op_a, false, instr.alu_integer.negate_a, true);
  42. op_b = GetOperandAbsNegInteger(op_b, false, instr.alu_integer.negate_b, true);
  43. const Node shift = Immediate(static_cast<u32>(instr.alu_integer.shift_amount));
  44. const Node shifted_a = Operation(OperationCode::ILogicalShiftLeft, NO_PRECISE, op_a, shift);
  45. const Node value = Operation(OperationCode::IAdd, NO_PRECISE, shifted_a, op_b);
  46. SetRegister(bb, instr.gpr0, value);
  47. break;
  48. }
  49. case OpCode::Id::SEL_C:
  50. case OpCode::Id::SEL_R:
  51. case OpCode::Id::SEL_IMM: {
  52. const Node condition = GetPredicate(instr.sel.pred, instr.sel.neg_pred != 0);
  53. const Node value = Operation(OperationCode::Select, PRECISE, condition, op_a, op_b);
  54. SetRegister(bb, instr.gpr0, value);
  55. break;
  56. }
  57. case OpCode::Id::LOP_C:
  58. case OpCode::Id::LOP_R:
  59. case OpCode::Id::LOP_IMM: {
  60. UNIMPLEMENTED_IF_MSG(instr.generates_cc,
  61. "Condition codes generation in LOP is not implemented");
  62. if (instr.alu.lop.invert_a)
  63. op_a = Operation(OperationCode::IBitwiseNot, NO_PRECISE, op_a);
  64. if (instr.alu.lop.invert_b)
  65. op_b = Operation(OperationCode::IBitwiseNot, NO_PRECISE, op_b);
  66. WriteLogicOperation(bb, instr.gpr0, instr.alu.lop.operation, op_a, op_b,
  67. instr.alu.lop.pred_result_mode, instr.alu.lop.pred48);
  68. break;
  69. }
  70. default:
  71. UNIMPLEMENTED_MSG("Unhandled ArithmeticInteger instruction: {}", opcode->get().GetName());
  72. }
  73. return pc;
  74. }
  75. } // namespace VideoCommon::Shader