float_set.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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::DecodeFloatSet(BasicBlock& bb, u32 pc) {
  12. const Instruction instr = {program_code[pc]};
  13. const auto opcode = OpCode::Decode(instr);
  14. const Node op_a = GetOperandAbsNegFloat(GetRegister(instr.gpr8), instr.fset.abs_a != 0,
  15. instr.fset.neg_a != 0);
  16. Node op_b = [&]() {
  17. if (instr.is_b_imm) {
  18. return GetImmediate19(instr);
  19. } else if (instr.is_b_gpr) {
  20. return GetRegister(instr.gpr20);
  21. } else {
  22. return GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset);
  23. }
  24. }();
  25. op_b = GetOperandAbsNegFloat(op_b, instr.fset.abs_b != 0, instr.fset.neg_b != 0);
  26. // The fset instruction sets a register to 1.0 or -1 (depending on the bf bit) if the
  27. // condition is true, and to 0 otherwise.
  28. const Node second_pred = GetPredicate(instr.fset.pred39, instr.fset.neg_pred != 0);
  29. const OperationCode combiner = GetPredicateCombiner(instr.fset.op);
  30. const Node first_pred = GetPredicateComparisonFloat(instr.fset.cond, op_a, op_b);
  31. const Node predicate = Operation(combiner, first_pred, second_pred);
  32. const Node true_value = instr.fset.bf ? Immediate(1.0f) : Immediate(-1);
  33. const Node false_value = instr.fset.bf ? Immediate(0.0f) : Immediate(0);
  34. const Node value =
  35. Operation(OperationCode::Select, PRECISE, predicate, true_value, false_value);
  36. SetRegister(bb, instr.gpr0, value);
  37. if (instr.generates_cc) {
  38. const Node is_zero = Operation(OperationCode::LogicalFEqual, value, Immediate(0.0f));
  39. SetInternalFlag(bb, InternalFlag::Zero, is_zero);
  40. LOG_WARNING(HW_GPU, "FSET condition code is incomplete");
  41. }
  42. return pc;
  43. }
  44. } // namespace VideoCommon::Shader