floating_point_add.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "shader_recompiler/exception.h"
  6. #include "shader_recompiler/frontend/maxwell/translate/impl/common_encoding.h"
  7. #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
  8. namespace Shader::Maxwell {
  9. namespace {
  10. void FADD(TranslatorVisitor& v, u64 insn, bool sat, bool cc, bool ftz, FpRounding fp_rounding,
  11. const IR::F32& src_b, bool abs_a, bool neg_a, bool abs_b, bool neg_b) {
  12. union {
  13. u64 raw;
  14. BitField<0, 8, IR::Reg> dest_reg;
  15. BitField<8, 8, IR::Reg> src_a;
  16. } const fadd{insn};
  17. if (cc) {
  18. throw NotImplementedException("FADD CC");
  19. }
  20. const IR::F32 op_a{v.ir.FPAbsNeg(v.F(fadd.src_a), abs_a, neg_a)};
  21. const IR::F32 op_b{v.ir.FPAbsNeg(src_b, abs_b, neg_b)};
  22. IR::FpControl control{
  23. .no_contraction{true},
  24. .rounding{CastFpRounding(fp_rounding)},
  25. .fmz_mode{ftz ? IR::FmzMode::FTZ : IR::FmzMode::None},
  26. };
  27. IR::F32 value{v.ir.FPAdd(op_a, op_b, control)};
  28. if (sat) {
  29. value = v.ir.FPSaturate(value);
  30. }
  31. v.F(fadd.dest_reg, value);
  32. }
  33. void FADD(TranslatorVisitor& v, u64 insn, const IR::F32& src_b) {
  34. union {
  35. u64 raw;
  36. BitField<39, 2, FpRounding> fp_rounding;
  37. BitField<44, 1, u64> ftz;
  38. BitField<45, 1, u64> neg_b;
  39. BitField<46, 1, u64> abs_a;
  40. BitField<47, 1, u64> cc;
  41. BitField<48, 1, u64> neg_a;
  42. BitField<49, 1, u64> abs_b;
  43. BitField<50, 1, u64> sat;
  44. } const fadd{insn};
  45. FADD(v, insn, fadd.sat != 0, fadd.cc != 0, fadd.ftz != 0, fadd.fp_rounding, src_b,
  46. fadd.abs_a != 0, fadd.neg_a != 0, fadd.abs_b != 0, fadd.neg_b != 0);
  47. }
  48. } // Anonymous namespace
  49. void TranslatorVisitor::FADD_reg(u64 insn) {
  50. FADD(*this, insn, GetFloatReg20(insn));
  51. }
  52. void TranslatorVisitor::FADD_cbuf(u64 insn) {
  53. FADD(*this, insn, GetFloatCbuf(insn));
  54. }
  55. void TranslatorVisitor::FADD_imm(u64 insn) {
  56. FADD(*this, insn, GetFloatImm20(insn));
  57. }
  58. void TranslatorVisitor::FADD32I(u64) {
  59. throw NotImplementedException("FADD32I");
  60. }
  61. } // namespace Shader::Maxwell