summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@gmail.com>2011-01-04 23:47:49 -0800
committerTom Stellard <tstellar@gmail.com>2011-01-04 23:47:49 -0800
commitedd462da966af8338e24b7b67b8df33bc2726dc2 (patch)
treebe3b0b97ac61fce661c4967fbfa64d0300135423
parentd7be2c024ed9bd61416c1c8546276fe0189cb92a (diff)
Add dp_instructionHEADmaster
-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_