arithmetic_half.cpp 2.4 KB

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