summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/maxwell/instruction.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/instruction.h')
-rw-r--r--src/shader_recompiler/frontend/maxwell/instruction.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/instruction.h b/src/shader_recompiler/frontend/maxwell/instruction.h
new file mode 100644
index 000000000..743d68d61
--- /dev/null
+++ b/src/shader_recompiler/frontend/maxwell/instruction.h
@@ -0,0 +1,63 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/bit_field.h"
8#include "common/common_types.h"
9#include "shader_recompiler/frontend/ir/flow_test.h"
10#include "shader_recompiler/frontend/ir/reg.h"
11
12namespace Shader::Maxwell {
13
14struct Predicate {
15 Predicate() = default;
16 Predicate(unsigned index_, bool negated_ = false) : index{index_}, negated{negated_} {}
17 Predicate(bool value) : index{7}, negated{!value} {}
18 Predicate(u64 raw) : index{static_cast<unsigned>(raw & 7)}, negated{(raw & 8) != 0} {}
19
20 unsigned index;
21 bool negated;
22};
23
24inline bool operator==(const Predicate& lhs, const Predicate& rhs) noexcept {
25 return lhs.index == rhs.index && lhs.negated == rhs.negated;
26}
27
28inline bool operator!=(const Predicate& lhs, const Predicate& rhs) noexcept {
29 return !(lhs == rhs);
30}
31
32union Instruction {
33 Instruction(u64 raw_) : raw{raw_} {}
34
35 u64 raw;
36
37 union {
38 BitField<5, 1, u64> is_cbuf;
39 BitField<0, 5, IR::FlowTest> flow_test;
40
41 [[nodiscard]] u32 Absolute() const noexcept {
42 return static_cast<u32>(absolute);
43 }
44
45 [[nodiscard]] s32 Offset() const noexcept {
46 return static_cast<s32>(offset);
47 }
48
49 private:
50 BitField<20, 24, s64> offset;
51 BitField<20, 32, u64> absolute;
52 } branch;
53
54 [[nodiscard]] Predicate Pred() const noexcept {
55 return Predicate{pred};
56 }
57
58private:
59 BitField<16, 4, u64> pred;
60};
61static_assert(std::is_trivially_copyable_v<Instruction>);
62
63} // namespace Shader::Maxwell