[Avida-SVN] r1497 - development/source/main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Sun Apr 22 22:04:34 PDT 2007
Author: barrick
Date: 2007-04-23 01:04:33 -0400 (Mon, 23 Apr 2007)
New Revision: 1497
Modified:
development/source/main/cStats.cc
Log:
Fixed cStats initialization for tracking =sense= instructions that was going into an infinite loop whenever < 2 NOPs were used. Now it doesn't initialize if no =sense= instructions are present and gives an error if you try having =sense= and also fewer than 2 NOPs.
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2007-04-21 12:14:54 UTC (rev 1496)
+++ development/source/main/cStats.cc 2007-04-23 05:04:33 UTC (rev 1497)
@@ -154,39 +154,54 @@
// This block calculates how many slots we need to
// make for paying attention to different label combinations
- int on = 1;
- int max_sense_label_length = 0;
- while (on < m_world->GetNumResources())
- {
- max_sense_label_length++;
- sense_size += on;
- on *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
- }
- sense_size += on;
-
- sense_last_count.Resize( sense_size );
- sense_last_count.SetAll(0);
-
- sense_last_exe_count.Resize( sense_size );
- sense_last_exe_count.SetAll(0);
+ // Require sense instruction to be present then die if not at least 2 NOPs
- sense_names.Resize( sense_size );
- int assign_index = 0;
- int num_per = 1;
- for (int i=0; i<= max_sense_label_length; i++)
+ bool sense_used = m_world->GetHardwareManager().GetInstSet().InstInSet( cStringUtil::Stringf("sense") )
+ || m_world->GetHardwareManager().GetInstSet().InstInSet( cStringUtil::Stringf("sense-unit") )
+ || m_world->GetHardwareManager().GetInstSet().InstInSet( cStringUtil::Stringf("sense-m100") );
+ if (sense_used)
{
- for (int j=0; j< num_per; j++)
+ if (m_world->GetHardwareManager().GetInstSet().GetNumNops() < 2)
{
- sense_names[assign_index] = (on > 1) ?
- cStringUtil::Stringf("sense_res.%i-%i", j*on, (j+1)*on-1) :
- cStringUtil::Stringf("sense_res.%i", j);
+ cerr << "Error: If you have a sense instruction in your instruction set, then";
+ cerr << "you MUST also include at least two NOPs in your instruction set. " << endl; exit(1);
+ }
- assign_index++;
+ int on = 1;
+ int max_sense_label_length = 0;
+ while (on < m_world->GetNumResources())
+ {
+ max_sense_label_length++;
+ sense_size += on;
+ on *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
}
- on /= m_world->GetHardwareManager().GetInstSet().GetNumNops();
- num_per *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+ sense_size += on;
+
+ sense_last_count.Resize( sense_size );
+ sense_last_count.SetAll(0);
+
+ sense_last_exe_count.Resize( sense_size );
+ sense_last_exe_count.SetAll(0);
+
+ sense_names.Resize( sense_size );
+ int assign_index = 0;
+ int num_per = 1;
+ for (int i=0; i<= max_sense_label_length; i++)
+ {
+ for (int j=0; j< num_per; j++)
+ {
+ sense_names[assign_index] = (on > 1) ?
+ cStringUtil::Stringf("sense_res.%i-%i", j*on, (j+1)*on-1) :
+ cStringUtil::Stringf("sense_res.%i", j);
+
+ assign_index++;
+ }
+ on /= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+ num_per *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+ }
+ }
+ // End sense tracking initialization
- }
genotype_map.Resize( m_world->GetConfig().WORLD_X.Get() * m_world->GetConfig().WORLD_Y.Get() );
SetupPrintDatabase();
More information about the Avida-cvs
mailing list