find_leading_one.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/bit_field.h"
  4. #include "common/common_types.h"
  5. #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
  6. namespace Shader::Maxwell {
  7. namespace {
  8. void FLO(TranslatorVisitor& v, u64 insn, IR::U32 src) {
  9. union {
  10. u64 insn;
  11. BitField<0, 8, IR::Reg> dest_reg;
  12. BitField<40, 1, u64> tilde;
  13. BitField<41, 1, u64> shift;
  14. BitField<47, 1, u64> cc;
  15. BitField<48, 1, u64> is_signed;
  16. } const flo{insn};
  17. if (flo.cc != 0) {
  18. throw NotImplementedException("CC");
  19. }
  20. if (flo.tilde != 0) {
  21. src = v.ir.BitwiseNot(src);
  22. }
  23. IR::U32 result{flo.is_signed != 0 ? v.ir.FindSMsb(src) : v.ir.FindUMsb(src)};
  24. if (flo.shift != 0) {
  25. const IR::U1 not_found{v.ir.IEqual(result, v.ir.Imm32(-1))};
  26. result = IR::U32{v.ir.Select(not_found, result, v.ir.BitwiseXor(result, v.ir.Imm32(31)))};
  27. }
  28. v.X(flo.dest_reg, result);
  29. }
  30. } // Anonymous namespace
  31. void TranslatorVisitor::FLO_reg(u64 insn) {
  32. FLO(*this, insn, GetReg20(insn));
  33. }
  34. void TranslatorVisitor::FLO_cbuf(u64 insn) {
  35. FLO(*this, insn, GetCbuf(insn));
  36. }
  37. void TranslatorVisitor::FLO_imm(u64 insn) {
  38. FLO(*this, insn, GetImm20(insn));
  39. }
  40. } // namespace Shader::Maxwell