summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@gmail.com>2010-12-28 22:38:46 -0800
committerTom Stellard <tstellar@gmail.com>2010-12-28 22:38:46 -0800
commit766e69ab2cba94cf4b3df211f137e89249100024 (patch)
tree5bd7af61fa3b6e26f1ad3ffc2ffef586f1b1a599
parentf5c76883babf67f33d8b52bf32abc71176f92c8b (diff)
Add MAD instruction
-rw-r--r--instruction.cpp18
-rw-r--r--instruction.h9
2 files changed, 27 insertions, 0 deletions
diff --git a/instruction.cpp b/instruction.cpp
index 41d4987..fd4df6c 100644
--- a/instruction.cpp
+++ b/instruction.cpp
@@ -88,3 +88,21 @@ mul_instruction::execute(emulator & emulator)
emulator.set_value(m_dst[i], val);
}
}
+
+mad_instruction::mad_instruction(std::vector<register_address> dst) :
+ instruction("MAD", NULL, dst, 3)
+ { }
+
+void
+mad_instruction::execute(emulator & emulator)
+{
+ unsigned int i;
+ for(i = 0; i < m_dst.size(); i++) {
+ tree_value * mul = new tree_value(new mul_evaluator(),
+ emulator.get_value(m_src_regs[0][i]),
+ emulator.get_value(m_src_regs[1][i]));
+ tree_value * mad = new tree_value(new add_evaluator(),
+ mul, emulator.get_value(m_src_regs[2][i]));
+ emulator.set_value(m_dst[i], mad);
+ }
+}
diff --git a/instruction.h b/instruction.h
index 10c61b9..5a87bd0 100644
--- a/instruction.h
+++ b/instruction.h
@@ -55,4 +55,13 @@ public:
void execute(emulator & emulator);
};
+/**
+ * dst = src0 * src1 + src2
+ */
+class mad_instruction : public instruction {
+public:
+ mad_instruction(std::vector<register_address> dst);
+ void execute(emulator & emulator);
+};
+
#endif //INSTRUCTION_H_