From da69085b3c3525219c9824f872b017de48a9d37c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 23 Nov 2019 12:53:44 +1000 Subject: [PATCH] CPU/Recompiler: Implement nor --- src/core/cpu_recompiler_code_generator.cpp | 36 ++++++++++++++++++++++ src/core/cpu_recompiler_code_generator.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/core/cpu_recompiler_code_generator.cpp b/src/core/cpu_recompiler_code_generator.cpp index 93d9e7de1..ee6cd97c5 100644 --- a/src/core/cpu_recompiler_code_generator.cpp +++ b/src/core/cpu_recompiler_code_generator.cpp @@ -122,6 +122,7 @@ bool CodeGenerator::CompileInstruction(const CodeBlockInstruction& cbi) case InstructionFunct::and_: case InstructionFunct::or_: case InstructionFunct::xor_: + case InstructionFunct::nor: result = Compile_Bitwise(cbi); break; @@ -663,6 +664,37 @@ Value CodeGenerator::XorValues(const Value& lhs, const Value& rhs) return res; } +Value CodeGenerator::NotValue(const Value& val) +{ + if (val.IsConstant()) + { + u64 new_cv = ~val.constant_value; + switch (val.size) + { + case RegSize_8: + return Value::FromConstantU8(Truncate8(new_cv)); + + case RegSize_16: + return Value::FromConstantU16(Truncate16(new_cv)); + + case RegSize_32: + return Value::FromConstantU32(Truncate32(new_cv)); + + case RegSize_64: + return Value::FromConstantU64(new_cv); + + default: + return Value(); + } + } + + // TODO: Don't allocate scratch if the lhs is a scratch? + Value res = m_register_cache.AllocateScratch(RegSize_32); + EmitCopyValue(res.host_reg, val); + EmitNot(res.host_reg, val.size); + return res; +} + void CodeGenerator::BlockPrologue() { EmitStoreCPUStructField(offsetof(Core, m_exception_raised), Value::FromConstantU8(0)); @@ -910,6 +942,10 @@ bool CodeGenerator::Compile_Bitwise(const CodeBlockInstruction& cbi) result = XorValues(lhs, rhs); break; + case InstructionFunct::nor: + result = NotValue(OrValues(lhs, rhs)); + break; + default: UnreachableCode(); break; diff --git a/src/core/cpu_recompiler_code_generator.h b/src/core/cpu_recompiler_code_generator.h index 31202a801..02a401fc1 100644 --- a/src/core/cpu_recompiler_code_generator.h +++ b/src/core/cpu_recompiler_code_generator.h @@ -143,6 +143,7 @@ public: Value OrValues(const Value& lhs, const Value& rhs); Value AndValues(const Value& lhs, const Value& rhs); Value XorValues(const Value& lhs, const Value& rhs); + Value NotValue(const Value& val); private: // Host register setup