summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--instruction.cpp35
-rw-r--r--instruction.h10
2 files changed, 45 insertions, 0 deletions
diff --git a/instruction.cpp b/instruction.cpp
index 8febec0..fdc1656 100644
--- a/instruction.cpp
+++ b/instruction.cpp
@@ -139,3 +139,38 @@ min_instruction::min_instruction(std::vector<register_address> dst) :
max_instruction::max_instruction(std::vector<register_address> dst) :
instruction("MAX", new max_evaluator(), dst, 2)
{ }
+
+dp_instruction::dp_instruction(
+ unsigned int components,
+ std::vector<register_address> dst)
+ :
+ instruction("DP", NULL, dst, 2),
+ m_components(components)
+ { }
+
+void
+dp_instruction::execute(emulator & emulator)
+{
+ std::vector<tree_value *> mul;
+ tree_value * dp;
+
+ unsigned int i;
+ int j;
+ for (i = 0; i < m_components; i++) {
+ mul.push_back(new tree_value(
+ new mul_evaluator(),
+ emulator.get_value(m_src_regs[0][i]),
+ emulator.get_value(m_src_regs[1][i])));
+ }
+
+ dp = new tree_value(new add_evaluator(), mul[mul.size() -1],
+ mul[mul.size() -2]);
+ for (j = mul.size() - 3; j >= 0; j--) {
+ dp = new tree_value(new add_evaluator(), mul[j], dp);
+ }
+
+ for (i = 0; i < m_dst.size(); i++) {
+ emulator.queue_write(m_dst[i], dp->clone());
+ }
+ delete dp;
+}
diff --git a/instruction.h b/instruction.h
index e200845..b76c53e 100644
--- a/instruction.h
+++ b/instruction.h
@@ -93,4 +93,14 @@ public:
max_instruction(std::vector<register_address> dst);
};
+class dp_instruction : public instruction {
+public:
+ dp_instruction(
+ unsigned int components,
+ std::vector<register_address> dst);
+ void execute(emulator & emulator);
+private:
+ unsigned int m_components;
+};
+
#endif //INSTRUCTION_H_