1 // Copyright 2018 yuzu Emulator Project
2 // Licensed under GPLv2 or any later version
3 // Refer to the license.txt file included.
4 
5 #include "common/assert.h"
6 #include "common/common_types.h"
7 #include "video_core/engines/shader_bytecode.h"
8 #include "video_core/shader/node_helper.h"
9 #include "video_core/shader/shader_ir.h"
10 
11 namespace VideoCommon::Shader {
12 
13 using Tegra::Shader::Instruction;
14 using Tegra::Shader::OpCode;
15 
DecodeBfi(NodeBlock & bb,u32 pc)16 u32 ShaderIR::DecodeBfi(NodeBlock& bb, u32 pc) {
17     const Instruction instr = {program_code[pc]};
18     const auto opcode = OpCode::Decode(instr);
19 
20     const auto [packed_shift, base] = [&]() -> std::pair<Node, Node> {
21         switch (opcode->get().GetId()) {
22         case OpCode::Id::BFI_RC:
23             return {GetRegister(instr.gpr39),
24                     GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset())};
25         case OpCode::Id::BFI_IMM_R:
26             return {Immediate(instr.alu.GetSignedImm20_20()), GetRegister(instr.gpr39)};
27         default:
28             UNREACHABLE();
29             return {Immediate(0), Immediate(0)};
30         }
31     }();
32     const Node insert = GetRegister(instr.gpr8);
33     const Node offset = BitfieldExtract(packed_shift, 0, 8);
34     const Node bits = BitfieldExtract(packed_shift, 8, 8);
35 
36     const Node value =
37         Operation(OperationCode::UBitfieldInsert, PRECISE, base, insert, offset, bits);
38 
39     SetInternalFlagsFromInteger(bb, value, instr.generates_cc);
40     SetRegister(bb, instr.gpr0, value);
41 
42     return pc;
43 }
44 
45 } // namespace VideoCommon::Shader
46