summaryrefslogtreecommitdiff
path: root/instruction.cpp
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 /instruction.cpp
parentd7be2c024ed9bd61416c1c8546276fe0189cb92a (diff)
Add dp_instructionHEADmaster
Diffstat (limited to 'instruction.cpp')
-rw-r--r--instruction.cpp35
1 files changed, 35 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;
+}