arithmetic_half.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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::DecodeArithmeticHalf(NodeBlock& bb, u32 pc) {
  12. const Instruction instr = {program_code[pc]};
  13. const auto opcode = OpCode::Decode(instr);
  14. if (opcode->get().GetId() == OpCode::Id::HADD2_C ||
  15. opcode->get().GetId() == OpCode::Id::HADD2_R) {
  16. UNIMPLEMENTED_IF(instr.alu_half.ftz != 0);
  17. }
  18. UNIMPLEMENTED_IF_MSG(instr.alu_half.saturate != 0, "Half float saturation not implemented");
  19. const bool negate_a =
  20. opcode->get().GetId() != OpCode::Id::HMUL2_R && instr.alu_half.negate_a != 0;
  21. const bool negate_b =
  22. opcode->get().GetId() != OpCode::Id::HMUL2_C && instr.alu_half.negate_b != 0;
  23. const Node op_a = GetOperandAbsNegHalf(GetRegister(instr.gpr8), instr.alu_half.abs_a, negate_a);
  24. // instr.alu_half.type_a
  25. Node op_b = [&]() {
  26. switch (opcode->get().GetId()) {
  27. case OpCode::Id::HADD2_C:
  28. case OpCode::Id::HMUL2_C:
  29. return GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset());
  30. case OpCode::Id::HADD2_R:
  31. case OpCode::Id::HMUL2_R:
  32. return GetRegister(instr.gpr20);
  33. default:
  34. UNREACHABLE();
  35. return Immediate(0);
  36. }
  37. }();
  38. op_b = GetOperandAbsNegHalf(op_b, instr.alu_half.abs_b, negate_b);
  39. Node value = [&]() {
  40. MetaHalfArithmetic meta{true, {instr.alu_half_imm.type_a, instr.alu_half.type_b}};
  41. switch (opcode->get().GetId()) {
  42. case OpCode::Id::HADD2_C:
  43. case OpCode::Id::HADD2_R:
  44. return Operation(OperationCode::HAdd, meta, op_a, op_b);
  45. case OpCode::Id::HMUL2_C:
  46. case OpCode::Id::HMUL2_R:
  47. return Operation(OperationCode::HMul, meta, op_a, op_b);
  48. default:
  49. UNIMPLEMENTED_MSG("Unhandled half float instruction: {}", opcode->get().GetName());
  50. return Immediate(0);
  51. }
  52. }();
  53. value = HalfMerge(GetRegister(instr.gpr0), value, instr.alu_half.merge);
  54. SetRegister(bb, instr.gpr0, value);
  55. return pc;
  56. }
  57. } // namespace VideoCommon::Shader