integer_popcount.cpp 974 B

123456789101112131415161718192021222324252627282930313233343536
  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/impl.h"
  7. namespace Shader::Maxwell {
  8. namespace {
  9. void POPC(TranslatorVisitor& v, u64 insn, const IR::U32& src) {
  10. union {
  11. u64 raw;
  12. BitField<0, 8, IR::Reg> dest_reg;
  13. BitField<40, 1, u64> tilde;
  14. } const popc{insn};
  15. const IR::U32 operand = popc.tilde == 0 ? src : v.ir.BitwiseNot(src);
  16. const IR::U32 result = v.ir.BitCount(operand);
  17. v.X(popc.dest_reg, result);
  18. }
  19. } // Anonymous namespace
  20. void TranslatorVisitor::POPC_reg(u64 insn) {
  21. POPC(*this, insn, GetReg20(insn));
  22. }
  23. void TranslatorVisitor::POPC_cbuf(u64 insn) {
  24. POPC(*this, insn, GetCbuf(insn));
  25. }
  26. void TranslatorVisitor::POPC_imm(u64 insn) {
  27. POPC(*this, insn, GetImm20(insn));
  28. }
  29. } // namespace Shader::Maxwell