integer_compare.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/bit_field.h"
  5. #include "common/common_types.h"
  6. #include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h"
  7. #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
  8. namespace Shader::Maxwell {
  9. namespace {
  10. void ICMP(TranslatorVisitor& v, u64 insn, const IR::U32& src_a, const IR::U32& operand) {
  11. union {
  12. u64 insn;
  13. BitField<0, 8, IR::Reg> dest_reg;
  14. BitField<8, 8, IR::Reg> src_reg;
  15. BitField<48, 1, u64> is_signed;
  16. BitField<49, 3, CompareOp> compare_op;
  17. } const icmp{insn};
  18. const IR::U32 zero{v.ir.Imm32(0)};
  19. const bool is_signed{icmp.is_signed != 0};
  20. const IR::U1 cmp_result{IntegerCompare(v.ir, operand, zero, icmp.compare_op, is_signed)};
  21. const IR::U32 src_reg{v.X(icmp.src_reg)};
  22. const IR::U32 result{v.ir.Select(cmp_result, src_reg, src_a)};
  23. v.X(icmp.dest_reg, result);
  24. }
  25. } // Anonymous namespace
  26. void TranslatorVisitor::ICMP_reg(u64 insn) {
  27. ICMP(*this, insn, GetReg20(insn), GetReg39(insn));
  28. }
  29. void TranslatorVisitor::ICMP_rc(u64 insn) {
  30. ICMP(*this, insn, GetReg39(insn), GetCbuf(insn));
  31. }
  32. void TranslatorVisitor::ICMP_cr(u64 insn) {
  33. ICMP(*this, insn, GetCbuf(insn), GetReg39(insn));
  34. }
  35. void TranslatorVisitor::ICMP_imm(u64 insn) {
  36. ICMP(*this, insn, GetImm20(insn), GetReg39(insn));
  37. }
  38. } // namespace Shader::Maxwell