summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp225
1 files changed, 225 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp
index e69de29bb..063dcaf13 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp
@@ -0,0 +1,225 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "shader_recompiler/backend/glasm/emit_context.h"
6#include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
7#include "shader_recompiler/frontend/ir/value.h"
8
9namespace Shader::Backend::GLASM {
10namespace {
11template <typename... Values>
12void CompositeConstructU32(EmitContext& ctx, IR::Inst& inst, Values&&... elements) {
13 const Register ret{ctx.reg_alloc.Define(inst)};
14 if (std::ranges::any_of(std::array{elements...},
15 [](const IR::Value& value) { return value.IsImmediate(); })) {
16 const std::array<u32, 4> values{(elements.IsImmediate() ? elements.U32() : 0)...};
17 ctx.Add("MOV.U {},{{{},{},{},{}}};", ret, fmt::to_string(values[0]),
18 fmt::to_string(values[1]), fmt::to_string(values[2]), fmt::to_string(values[3]));
19 }
20 size_t index{};
21 for (const IR::Value& element : {elements...}) {
22 if (!element.IsImmediate()) {
23 const ScalarU32 value{ctx.reg_alloc.Consume(element)};
24 ctx.Add("MOV.U {}.{},{};", ret, "xyzw"[index], value);
25 }
26 ++index;
27 }
28}
29
30void CompositeExtractU32(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) {
31 const Register ret{ctx.reg_alloc.Define(inst)};
32 if (ret == composite && index == 0) {
33 // No need to do anything here, the source and destination are the same register
34 return;
35 }
36 ctx.Add("MOV.U {}.x,{}.{};", ret, composite, "xyzw"[index]);
37}
38} // Anonymous namespace
39
40void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1,
41 const IR::Value& e2) {
42 CompositeConstructU32(ctx, inst, e1, e2);
43}
44
45void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1,
46 const IR::Value& e2, const IR::Value& e3) {
47 CompositeConstructU32(ctx, inst, e1, e2, e3);
48}
49
50void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1,
51 const IR::Value& e2, const IR::Value& e3, const IR::Value& e4) {
52 CompositeConstructU32(ctx, inst, e1, e2, e3, e4);
53}
54
55void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) {
56 CompositeExtractU32(ctx, inst, composite, index);
57}
58
59void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) {
60 CompositeExtractU32(ctx, inst, composite, index);
61}
62
63void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) {
64 CompositeExtractU32(ctx, inst, composite, index);
65}
66
67void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx,
68 [[maybe_unused]] Register composite,
69 [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) {
70 throw NotImplementedException("GLASM instruction");
71}
72
73void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx,
74 [[maybe_unused]] Register composite,
75 [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) {
76 throw NotImplementedException("GLASM instruction");
77}
78
79void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx,
80 [[maybe_unused]] Register composite,
81 [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) {
82 throw NotImplementedException("GLASM instruction");
83}
84
85void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1,
86 [[maybe_unused]] Register e2) {
87 throw NotImplementedException("GLASM instruction");
88}
89
90void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1,
91 [[maybe_unused]] Register e2, [[maybe_unused]] Register e3) {
92 throw NotImplementedException("GLASM instruction");
93}
94
95void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1,
96 [[maybe_unused]] Register e2, [[maybe_unused]] Register e3,
97 [[maybe_unused]] Register e4) {
98 throw NotImplementedException("GLASM instruction");
99}
100
101void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
102 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
103 throw NotImplementedException("GLASM instruction");
104}
105
106void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
107 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
108 throw NotImplementedException("GLASM instruction");
109}
110
111void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
112 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
113 throw NotImplementedException("GLASM instruction");
114}
115
116void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
117 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
118 [[maybe_unused]] u32 index) {
119 throw NotImplementedException("GLASM instruction");
120}
121
122void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
123 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
124 [[maybe_unused]] u32 index) {
125 throw NotImplementedException("GLASM instruction");
126}
127
128void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
129 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
130 [[maybe_unused]] u32 index) {
131 throw NotImplementedException("GLASM instruction");
132}
133
134void EmitCompositeConstructF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1,
135 [[maybe_unused]] ScalarF32 e2) {
136 throw NotImplementedException("GLASM instruction");
137}
138
139void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1,
140 [[maybe_unused]] ScalarF32 e2, [[maybe_unused]] ScalarF32 e3) {
141 throw NotImplementedException("GLASM instruction");
142}
143
144void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1,
145 [[maybe_unused]] ScalarF32 e2, [[maybe_unused]] ScalarF32 e3,
146 [[maybe_unused]] ScalarF32 e4) {
147 throw NotImplementedException("GLASM instruction");
148}
149
150void EmitCompositeExtractF32x2([[maybe_unused]] EmitContext& ctx,
151 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
152 throw NotImplementedException("GLASM instruction");
153}
154
155void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx,
156 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
157 throw NotImplementedException("GLASM instruction");
158}
159
160void EmitCompositeExtractF32x4([[maybe_unused]] EmitContext& ctx,
161 [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) {
162 throw NotImplementedException("GLASM instruction");
163}
164
165void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx,
166 [[maybe_unused]] Register composite,
167 [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) {
168 throw NotImplementedException("GLASM instruction");
169}
170
171void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx,
172 [[maybe_unused]] Register composite,
173 [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) {
174 throw NotImplementedException("GLASM instruction");
175}
176
177void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx,
178 [[maybe_unused]] Register composite,
179 [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) {
180 throw NotImplementedException("GLASM instruction");
181}
182
183void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
184 throw NotImplementedException("GLASM instruction");
185}
186
187void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
188 throw NotImplementedException("GLASM instruction");
189}
190
191void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
192 throw NotImplementedException("GLASM instruction");
193}
194
195void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
196 throw NotImplementedException("GLASM instruction");
197}
198
199void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
200 throw NotImplementedException("GLASM instruction");
201}
202
203void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
204 throw NotImplementedException("GLASM instruction");
205}
206
207void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx,
208 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
209 [[maybe_unused]] u32 index) {
210 throw NotImplementedException("GLASM instruction");
211}
212
213void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx,
214 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
215 [[maybe_unused]] u32 index) {
216 throw NotImplementedException("GLASM instruction");
217}
218
219void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx,
220 [[maybe_unused]] Register composite, [[maybe_unused]] Register object,
221 [[maybe_unused]] u32 index) {
222 throw NotImplementedException("GLASM instruction");
223}
224
225} // namespace Shader::Backend::GLASM