[Avida-SVN] r1142 - development/source/cpu
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Wed Dec 13 13:12:32 PST 2006
Author: barrick
Date: 2006-12-13 16:12:32 -0500 (Wed, 13 Dec 2006)
New Revision: 1142
Modified:
development/source/cpu/cHardwareCPU.cc
Log:
Instructions assigned a "prob-fail" were not advancing the instruction pointer after they failed, resulting in a try-and-try-again repetiti
on until they were successful. Now the IP is advanced even if they fail.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2006-12-13 04:46:37 UTC (rev 1141)
+++ development/source/cpu/cHardwareCPU.cc 2006-12-13 21:12:32 UTC (rev 1142)
@@ -500,7 +500,7 @@
const cInstruction& cur_inst = IP().GetInst();
// Test if costs have been paid and it is okay to execute this now...
- const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
+ bool exec = SingleProcess_PayCosts(ctx, cur_inst);
// Now execute the instruction...
if (exec == true) {
@@ -509,8 +509,14 @@
// certain classes of instructions (namely divide instructions) @DMB
const int addl_time_cost = m_inst_set->GetAddlTimeCost(cur_inst);
- SingleProcess_ExecuteInst(ctx, cur_inst);
+ // Prob of exec (moved from SingleProcess_PayCosts so that we advance IP after a fail)
+ if ( m_inst_set->GetProbFail(cur_inst) > 0.0 )
+ {
+ exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+ }
+ if (exec == true) SingleProcess_ExecuteInst(ctx, cur_inst);
+
// Some instruction (such as jump) may turn m_advance_ip off. Usually
// we now want to move to the next instruction in the memory.
if (m_advance_ip == true) IP().Advance();
@@ -556,10 +562,6 @@
}
}
- // Prob of exec
- if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ){
- return !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
- }
#endif
return true;
}
More information about the Avida-cvs
mailing list