summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/opcodes.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-04-21 00:25:46 -0300
committerGravatar ameerj2021-07-22 21:51:28 -0400
commit6944cabb899c4367a63cde97ae2bc2eb1a0fb790 (patch)
treeb52f0687254b6c5c123dd1b5171bad124055c6dc /src/shader_recompiler/frontend/ir/opcodes.cpp
parentshader: Inline common IR::Block methods (diff)
downloadyuzu-6944cabb899c4367a63cde97ae2bc2eb1a0fb790.tar.gz
yuzu-6944cabb899c4367a63cde97ae2bc2eb1a0fb790.tar.xz
yuzu-6944cabb899c4367a63cde97ae2bc2eb1a0fb790.zip
shader: Inline common Opcode and Inst functions
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.cpp90
1 files changed, 1 insertions, 89 deletions
diff --git a/src/shader_recompiler/frontend/ir/opcodes.cpp b/src/shader_recompiler/frontend/ir/opcodes.cpp
index 4207d548c..24d024ad7 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.cpp
+++ b/src/shader_recompiler/frontend/ir/opcodes.cpp
@@ -2,102 +2,14 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
6#include <array>
7#include <string_view> 5#include <string_view>
8 6
9#include "shader_recompiler/exception.h"
10#include "shader_recompiler/frontend/ir/opcodes.h" 7#include "shader_recompiler/frontend/ir/opcodes.h"
11 8
12namespace Shader::IR { 9namespace Shader::IR {
13namespace {
14struct OpcodeMeta {
15 std::string_view name;
16 Type type;
17 std::array<Type, 5> arg_types;
18};
19
20// using enum Type;
21constexpr Type Void{Type::Void};
22constexpr Type Opaque{Type::Opaque};
23constexpr Type Label{Type::Label};
24constexpr Type Reg{Type::Reg};
25constexpr Type Pred{Type::Pred};
26constexpr Type Attribute{Type::Attribute};
27constexpr Type Patch{Type::Patch};
28constexpr Type U1{Type::U1};
29constexpr Type U8{Type::U8};
30constexpr Type U16{Type::U16};
31constexpr Type U32{Type::U32};
32constexpr Type U64{Type::U64};
33constexpr Type F16{Type::F16};
34constexpr Type F32{Type::F32};
35constexpr Type F64{Type::F64};
36constexpr Type U32x2{Type::U32x2};
37constexpr Type U32x3{Type::U32x3};
38constexpr Type U32x4{Type::U32x4};
39constexpr Type F16x2{Type::F16x2};
40constexpr Type F16x3{Type::F16x3};
41constexpr Type F16x4{Type::F16x4};
42constexpr Type F32x2{Type::F32x2};
43constexpr Type F32x3{Type::F32x3};
44constexpr Type F32x4{Type::F32x4};
45constexpr Type F64x2{Type::F64x2};
46constexpr Type F64x3{Type::F64x3};
47constexpr Type F64x4{Type::F64x4};
48
49constexpr std::array META_TABLE{
50#define OPCODE(name_token, type_token, ...) \
51 OpcodeMeta{ \
52 .name{#name_token}, \
53 .type = type_token, \
54 .arg_types{__VA_ARGS__}, \
55 },
56#include "opcodes.inc"
57#undef OPCODE
58};
59
60constexpr size_t CalculateNumArgsOf(Opcode op) {
61 const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types};
62 return std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void));
63}
64
65constexpr std::array NUM_ARGS{
66#define OPCODE(name_token, type_token, ...) CalculateNumArgsOf(Opcode::name_token),
67#include "opcodes.inc"
68#undef OPCODE
69};
70
71void ValidateOpcode(Opcode op) {
72 const size_t raw{static_cast<size_t>(op)};
73 if (raw >= META_TABLE.size()) {
74 throw InvalidArgument("Invalid opcode with raw value {}", raw);
75 }
76}
77} // Anonymous namespace
78
79Type TypeOf(Opcode op) {
80 ValidateOpcode(op);
81 return META_TABLE[static_cast<size_t>(op)].type;
82}
83
84size_t NumArgsOf(Opcode op) {
85 ValidateOpcode(op);
86 return NUM_ARGS[static_cast<size_t>(op)];
87}
88
89Type ArgTypeOf(Opcode op, size_t arg_index) {
90 ValidateOpcode(op);
91 const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types};
92 if (arg_index >= arg_types.size() || arg_types[arg_index] == Type::Void) {
93 throw InvalidArgument("Out of bounds argument");
94 }
95 return arg_types[arg_index];
96}
97 10
98std::string_view NameOf(Opcode op) { 11std::string_view NameOf(Opcode op) {
99 ValidateOpcode(op); 12 return Detail::META_TABLE[static_cast<size_t>(op)].name;
100 return META_TABLE[static_cast<size_t>(op)].name;
101} 13}
102 14
103} // namespace Shader::IR 15} // namespace Shader::IR