summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/expr.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2019-06-29 02:54:21 +0200
committerFernandoS27 <fsahmkow27@gmail.com>2019-10-05 00:52:48 +0200
commit8be6e1c5221066a49b6ad27efbd20a999a7c16b3 (patch)
treea00263eb962503bec08ec4bc870a9546c3b80d22 /src/video_core/shader/expr.cpp
parentshader_ir: Add basic goto elimination (diff)
downloadyuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.gz
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.bz2
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.lz
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.xz
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.zst
yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.zip
Diffstat (limited to 'src/video_core/shader/expr.cpp')
-rw-r--r--src/video_core/shader/expr.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp
new file mode 100644
index 000000000..ebce6339b
--- /dev/null
+++ b/src/video_core/shader/expr.cpp
@@ -0,0 +1,75 @@
+// Copyright 2019 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <variant>
+
+#include "video_core/shader/expr.h"
+
+namespace VideoCommon::Shader {
+
+bool ExprAnd::operator==(const ExprAnd& b) const {
+ return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
+}
+
+bool ExprOr::operator==(const ExprOr& b) const {
+ return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
+}
+
+bool ExprNot::operator==(const ExprNot& b) const {
+ return (*operand1 == *b.operand1);
+}
+
+bool ExprIsBoolean(Expr expr) {
+ return std::holds_alternative<ExprBoolean>(*expr);
+}
+
+bool ExprBooleanGet(Expr expr) {
+ return std::get_if<ExprBoolean>(expr.get())->value;
+}
+
+Expr MakeExprNot(Expr first) {
+ if (std::holds_alternative<ExprNot>(*first)) {
+ return std::get_if<ExprNot>(first.get())->operand1;
+ }
+ return MakeExpr<ExprNot>(first);
+}
+
+Expr MakeExprAnd(Expr first, Expr second) {
+ if (ExprIsBoolean(first)) {
+ return ExprBooleanGet(first) ? second : first;
+ }
+ if (ExprIsBoolean(second)) {
+ return ExprBooleanGet(second) ? first : second;
+ }
+ return MakeExpr<ExprAnd>(first, second);
+}
+
+Expr MakeExprOr(Expr first, Expr second) {
+ if (ExprIsBoolean(first)) {
+ return ExprBooleanGet(first) ? first : second;
+ }
+ if (ExprIsBoolean(second)) {
+ return ExprBooleanGet(second) ? second : first;
+ }
+ return MakeExpr<ExprOr>(first, second);
+}
+
+bool ExprAreEqual(Expr first, Expr second) {
+ return (*first) == (*second);
+}
+
+bool ExprAreOpposite(Expr first, Expr second) {
+ if (std::holds_alternative<ExprNot>(*first)) {
+ return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second);
+ }
+ if (std::holds_alternative<ExprNot>(*second)) {
+ return ExprAreEqual(std::get_if<ExprNot>(second.get())->operand1, first);
+ }
+ return false;
+}
+
+} // namespace VideoCommon::Shader