[Avida-SVN] r2268 - development/source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Jan 22 12:55:56 PST 2008
Author: brysonda
Date: 2008-01-22 15:55:56 -0500 (Tue, 22 Jan 2008)
New Revision: 2268
Modified:
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
Log:
Implement the Execurate instruction.
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2008-01-22 04:37:23 UTC (rev 2267)
+++ development/source/cpu/cHardwareExperimental.cc 2008-01-22 20:55:56 UTC (rev 2268)
@@ -142,8 +142,9 @@
tInstLibEntry<tMethod>("numberate", &cHardwareExperimental::Inst_Numberate),
tInstLibEntry<tMethod>("numberate-24", &cHardwareExperimental::Inst_Numberate24),
tInstLibEntry<tMethod>("bit-cons", &cHardwareExperimental::Inst_BitConsensus),
- tInstLibEntry<tMethod>("bit-cons-24", &cHardwareExperimental::Inst_BitConsensus24)
-
+ tInstLibEntry<tMethod>("bit-cons-24", &cHardwareExperimental::Inst_BitConsensus24),
+ tInstLibEntry<tMethod>("execurate", &cHardwareExperimental::Inst_Execurate),
+ tInstLibEntry<tMethod>("execurate-24", &cHardwareExperimental::Inst_Execurate24)
};
@@ -277,11 +278,11 @@
next_label.Clear();
// Promoter model
+ m_execurate = 0;
m_promoter_inst_executed = 0;
}
-
// This function processes the very next command in the genome, and is made
// to be as optimized as possible. This is the heart of avida.
@@ -409,10 +410,15 @@
// instruction execution count incremeneted
organism->GetPhenotype().IncCurInstCount(actual_inst.GetOp());
#endif
-
+
// And execute it.
const bool exec_success = (this->*(m_functions[inst_idx]))(ctx);
-
+
+ if (exec_success) {
+ int code_len = m_world->GetConfig().INST_CODE_LENGTH.Get();
+ m_threads[m_cur_thread].UpdateExecurate(code_len, m_inst_set->GetInstructionCode(actual_inst));
+ }
+
#if INSTRUCTION_COUNT
// decremenet if the instruction was not executed successfully
if (exec_success == false) {
@@ -1619,3 +1625,19 @@
return true;
}
+// Create a number from inst bit codes of the previously executed instructions
+bool cHardwareExperimental::Inst_Execurate(cAvidaContext& ctx)
+{
+ const int reg_used = FindModifiedRegister(REG_BX);
+ GetRegister(reg_used) = m_threads[m_cur_thread].GetExecurate();
+ return true;
+}
+
+// Create a number from inst bit codes of the previously executed instructions, truncated to 24 bits
+bool cHardwareExperimental::Inst_Execurate24(cAvidaContext& ctx)
+{
+ const int reg_used = FindModifiedRegister(REG_BX);
+ GetRegister(reg_used) = (0xFFFFFF & m_threads[m_cur_thread].GetExecurate());
+ return true;
+}
+
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2008-01-22 04:37:23 UTC (rev 2267)
+++ development/source/cpu/cHardwareExperimental.h 2008-01-22 20:55:56 UTC (rev 2268)
@@ -94,7 +94,9 @@
private:
int m_id;
int m_promoter_inst_executed;
+ unsigned int m_execurate;
+
public:
int reg[NUM_REGISTERS];
cHeadCPU heads[NUM_HEADS];
@@ -104,7 +106,7 @@
bool reading;
cCodeLabel read_label;
- cCodeLabel next_label;
+ cCodeLabel next_label;
cLocalThread(cHardwareBase* in_hardware = NULL, int in_id = -1) { Reset(in_hardware, in_id); }
~cLocalThread() { ; }
@@ -112,12 +114,15 @@
void operator=(const cLocalThread& in_thread);
void Reset(cHardwareBase* in_hardware, int in_id);
- int GetID() const { return m_id; }
- void SetID(int in_id) { m_id = in_id; }
+ inline int GetID() const { return m_id; }
+ inline void SetID(int in_id) { m_id = in_id; }
+
+ inline unsigned int GetExecurate() const { return m_execurate; }
+ inline void UpdateExecurate(int code_len, unsigned int inst_code) { m_execurate <<= code_len; m_execurate |= inst_code; }
- int GetPromoterInstExecuted() { return m_promoter_inst_executed; }
- void IncPromoterInstExecuted() { m_promoter_inst_executed++; }
- void ResetPromoterInstExecuted() { m_promoter_inst_executed = 0; }
+ inline int GetPromoterInstExecuted() const { return m_promoter_inst_executed; }
+ inline void IncPromoterInstExecuted() { m_promoter_inst_executed++; }
+ inline void ResetPromoterInstExecuted() { m_promoter_inst_executed = 0; }
};
@@ -367,6 +372,8 @@
bool Inst_BitConsensus24(cAvidaContext& ctx);
bool BitConsensus(cAvidaContext& ctx, const unsigned int num_bits);
+ bool Inst_Execurate(cAvidaContext& ctx);
+ bool Inst_Execurate24(cAvidaContext& ctx);
};
More information about the Avida-cvs
mailing list