[Avida-cvs] [avida-svn] r422 - trunk/source/cpu

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Dec 13 10:59:00 PST 2005


Author: brysonda
Date: 2005-12-13 13:59:00 -0500 (Tue, 13 Dec 2005)
New Revision: 422

Modified:
   trunk/source/cpu/cCPUMemory.cc
   trunk/source/cpu/cCPUMemory.h
   trunk/source/cpu/cHardware4Stack.cc
   trunk/source/cpu/cHardwareCPU.cc
   trunk/source/cpu/cHardwareSMT.cc
   trunk/source/cpu/cHeadCPU.cc
   trunk/source/cpu/cHeadCPU.h
   trunk/source/cpu/cHeadMultiMem.cc
   trunk/source/cpu/cHeadMultiMem.h
Log:
Convert cCPUMemory's flag_array to a tArray of unsigned chars using masked bit fields to hold the flags.  This makes the per-instruction size of the flags about 1/28th what it was.  As a result the memory usage of Avida appears to be dramatically less.  Also, currently the run using this change is running about 73% faster.  Granted, the comparison runs have about 400k difference in their current update, but the reduced memory footprint will help the cache-hit ratio and can easily account for the speedup.  Plus, there is no more pointer indirection of reading/setting flags.

There is some cleanup that should be done.  For example, only cHardwareCPU clears any flags, so only those two are non-virtually implemented in cHeadCPU at the moment.  I will get these later (and up-port the whole change into development).

Modified: trunk/source/cpu/cCPUMemory.cc
===================================================================
--- trunk/source/cpu/cCPUMemory.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cCPUMemory.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -111,7 +111,7 @@
   // Fill in the new information...
   for (int i = 0; i < active_size; i++) {
     genome[i] = other_genome[i];
-    flag_array[i].Clear();
+    flag_array[i] = 0;
   }
 }
 
@@ -126,19 +126,6 @@
   flag_array[to] = flag_array[from];
 }
 
-void cCPUMemory::Clear()
-{
-  for (int i = 0; i < active_size; i++) {
-    genome[i].SetOp(0);
-    flag_array[i].Clear();
-  }
-}
-
-void cCPUMemory::ClearFlags()
-{
-  for (int i = 0; i < active_size; i++) flag_array[i].Clear();
-}
-
 void cCPUMemory::Reset(int new_size)
 {
   assert(new_size >= 0);
@@ -160,7 +147,7 @@
   // Clean up all of the old memory that might need it...
   for (int i = old_size; i < new_size && i < old_array_size; i++) {
     genome[i].SetOp(0);
-    flag_array[i].Clear();
+    flag_array[i] = 0;
   }
 }
 
@@ -181,7 +168,7 @@
 
   SloppyInsert(pos, 1);
   genome[pos] = in_inst;
-  flag_array[pos].Clear();
+  flag_array[pos] = 0;
 }
 
 void cCPUMemory::Insert(int pos, const cGenome & in_genome)
@@ -192,7 +179,7 @@
   SloppyInsert(pos, in_genome.GetSize());
   for (int i = 0; i < in_genome.GetSize(); i++) {
     genome[i+pos] = in_genome[i];
-    flag_array[i+pos].Clear();
+    flag_array[i+pos] = 0;
   }
 }
 

Modified: trunk/source/cpu/cCPUMemory.h
===================================================================
--- trunk/source/cpu/cCPUMemory.h	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cCPUMemory.h	2005-12-13 18:59:00 UTC (rev 422)
@@ -22,12 +22,20 @@
 class cInstruction;
 class cMemoryFlags; // access
 class cString;
-template <class T> class tArray; // aggregate
 
 class cCPUMemory : public cGenome {
 private:
-  tManagedPointerArray<cMemoryFlags> flag_array;
+	static const unsigned char MASK_COPIED   = 0x01;
+	static const unsigned char MASK_MUTATED  = 0x02;
+	static const unsigned char MASK_EXECUTED = 0x04;
+	static const unsigned char MASK_BREAK    = 0x08;
+	static const unsigned char MASK_POINTMUT = 0x10;
+	static const unsigned char MASK_COPYMUT  = 0x20;
+	static const unsigned char MASK_INJECTED = 0x40;
+	static const unsigned char MASK_UNUSED   = 0x80; // unused bit
 
+  tArray<unsigned char> flag_array;
+
   // A collection of sloppy instructions to perform oft-used functions that
   // will need to be cleaned up after this is run.
   void SloppyResize(int new_size);           // Set size, ignore new contents.
@@ -43,27 +51,36 @@
   void operator=(const cGenome & other_genome);
   void Copy(int to, int from);
 
-  void Clear();
-  void ClearFlags();
+  void Clear()
+	{
+		for (int i = 0; i < active_size; i++) {
+			genome[i].SetOp(0);
+			flag_array[i] = 0;
+		}
+	}
+  void ClearFlags() { flag_array.SetAll(0); }
   void Reset(int new_size);     // Reset size, clearing contents...
   void Resize(int new_size);    // Reset size, save contents, init to default
   void ResizeOld(int new_size); // Reset size, save contents, init to previous
 
-  bool FlagCopied(int pos) const     { return flag_array[pos].copied; }
-  bool FlagMutated(int pos) const    { return flag_array[pos].mutated; }
-  bool FlagExecuted(int pos) const   { return flag_array[pos].executed; }
-  bool FlagBreakpoint(int pos) const { return flag_array[pos].breakpoint; }
-  bool FlagPointMut(int pos) const   { return flag_array[pos].point_mut; }
-  bool FlagCopyMut(int pos) const    { return flag_array[pos].copy_mut; }
-  bool FlagInjected(int pos) const   { return flag_array[pos].injected; }
+  bool FlagCopied(int pos) const     { return MASK_COPIED   & flag_array[pos]; }
+  bool FlagMutated(int pos) const    { return MASK_MUTATED  & flag_array[pos]; }
+  bool FlagExecuted(int pos) const   { return MASK_EXECUTED & flag_array[pos]; }
+  bool FlagBreakpoint(int pos) const { return MASK_BREAK    & flag_array[pos]; }
+  bool FlagPointMut(int pos) const   { return MASK_POINTMUT & flag_array[pos]; }
+  bool FlagCopyMut(int pos) const    { return MASK_COPYMUT  & flag_array[pos]; }
+  bool FlagInjected(int pos) const   { return MASK_INJECTED & flag_array[pos]; }
 
-  bool & FlagCopied(int pos)     { return flag_array[pos].copied; }
-  bool & FlagMutated(int pos)    { return flag_array[pos].mutated; }
-  bool & FlagExecuted(int pos)   { return flag_array[pos].executed; }
-  bool & FlagBreakpoint(int pos) { return flag_array[pos].breakpoint; }
-  bool & FlagPointMut(int pos)   { return flag_array[pos].point_mut; }
-  bool & FlagCopyMut(int pos)    { return flag_array[pos].copy_mut; }
-  bool & FlagInjected(int pos)   { return flag_array[pos].injected; }
+  void SetFlagCopied(int pos)     { flag_array[pos] |= MASK_COPIED;   }
+  void SetFlagMutated(int pos)    { flag_array[pos] |= MASK_MUTATED;  }
+  void SetFlagExecuted(int pos)   { flag_array[pos] |= MASK_EXECUTED; }
+  void SetFlagBreakpoint(int pos) { flag_array[pos] |= MASK_BREAK;    }
+  void SetFlagPointMut(int pos)   { flag_array[pos] |= MASK_POINTMUT; }
+  void SetFlagCopyMut(int pos)    { flag_array[pos] |= MASK_COPYMUT;  }
+  void SetFlagInjected(int pos)   { flag_array[pos] |= MASK_INJECTED; }
+	
+	void ClearFlagMutated(int pos)  { flag_array[pos] &= ~MASK_MUTATED;  }
+	void ClearFlagCopyMut(int pos)  { flag_array[pos] &= ~MASK_COPYMUT;  }
 
   void Insert(int pos, const cInstruction & in_inst);
   void Insert(int pos, const cGenome & in_genome);

Modified: trunk/source/cpu/cHardware4Stack.cc
===================================================================
--- trunk/source/cpu/cHardware4Stack.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHardware4Stack.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -360,7 +360,7 @@
     IP().Adjust();
 
 #ifdef BREAKPOINTS
-    if (IP().FlagBreakpoint() == true) {
+    if (IP().FlagBreakpoint()) {
       organism->DoBreakpoint();
     }
 #endif
@@ -449,7 +449,7 @@
   int inst_idx = GetInstSet().GetLibFunctionIndex(actual_inst);
   
   // Mark the instruction as executed
-  IP().FlagExecuted() = true;
+  IP().SetFlagExecuted();
 	
 
 #ifdef INSTRUCTION_COUNT
@@ -981,7 +981,7 @@
   
     // Set instruction flags on the injected code
     for (int i = 0; i < inject_code.GetSize(); i++) {
-      memory_array[target_mem_space].FlagInjected(i) = true;
+      memory_array[target_mem_space].SetFlagInjected(i);
     }
     organism->GetPhenotype().IsModified() = true;
     
@@ -1013,8 +1013,8 @@
   assert(mut_point >= 0 && mut_point < GetMemory(0).GetSize());
 
   GetMemory(0)[mut_point] = GetRandomInst();
-  GetMemory(0).FlagMutated(mut_point) = true;
-  GetMemory(0).FlagPointMut(mut_point) = true;
+  GetMemory(0).SetFlagMutated(mut_point);
+  GetMemory(0).SetFlagPointMut(mut_point);
   //organism->GetPhenotype().IsMutated() = true;
   organism->CPUStats().mut_stats.point_mut_count++;
 }
@@ -1158,7 +1158,7 @@
   switch (type) {
   case nMutation::TYPE_POINT:
     target_memory[pos] = GetRandomInst();
-    target_memory.FlagMutated(pos) = true;
+    target_memory.SetFlagMutated(pos);
     break;
   case nMutation::TYPE_INSERT:
   case nMutation::TYPE_DELETE:
@@ -1212,7 +1212,7 @@
 
     // If this is the first line of the template, mark it executed.
     if (GetLabel().GetSize() <=	cConfig::GetMaxLabelExeSize()) {
-      inst_ptr->FlagExecuted() = true;
+      inst_ptr->SetFlagExecuted();
     }
   }
 }
@@ -1333,7 +1333,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_stack = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_stack;
 }
@@ -1346,7 +1346,7 @@
     IP().Advance();    
     int nop_head = GetInstSet().GetNopMod(IP().GetInst());
     if (nop_head < nHardware::NUM_HEADS) default_head = nop_head;
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_head;
 }
@@ -1521,12 +1521,12 @@
 
   // Count up mutated lines
   for(int i = 0; i < GetMemory(0).GetSize(); i++){
-    if (GetMemory(0).FlagPointMut(i) == true) {
+    if (GetMemory(0).FlagPointMut(i)) {
       cpu_stats.mut_stats.point_mut_line_count++;
     }
   }
   for(int i = 0; i < child_genome.GetSize(); i++){
-    if( child_genome.FlagCopyMut(i) == true) {
+    if( child_genome.FlagCopyMut(i)) {
       cpu_stats.mut_stats.copy_mut_line_count++;
     }
   }
@@ -1975,7 +1975,7 @@
   if (value < 0 || value >= GetNumInst()) value = 0;
 
   active_head.SetInst(cInstruction(value));
-  active_head.FlagCopied() = true;
+  active_head.SetFlagCopied();
 
   // Advance the head after write...
   active_head++;
@@ -2000,8 +2000,8 @@
   if (organism->TestCopyMut()) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.FlagMutated() = true;
-    write_head.FlagCopyMut() = true;
+    write_head.SetFlagMutated();
+    write_head.SetFlagCopyMut();
     //organism->GetPhenotype().IsMutated() = true;
   }
   ReadInst(read_inst.GetOp());
@@ -2009,7 +2009,7 @@
   cpu_stats.mut_stats.copies_exec++;
 
   write_head.SetInst(read_inst);
-  write_head.FlagCopied() = true;  // Set the copied flag...
+  write_head.SetFlagCopied();  // Set the copied flag...
 
   // TriggerMutations(nMutation::TRIGGER_WRITE, write_head);
 

Modified: trunk/source/cpu/cHardwareCPU.cc
===================================================================
--- trunk/source/cpu/cHardwareCPU.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHardwareCPU.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -461,7 +461,7 @@
     IP().Adjust();
 
 #ifdef BREAKPOINTS
-    if (IP().FlagBreakpoint() == true) {
+    if (IP().FlagBreakpoint()) {
       organism->DoBreakpoint();
     }
 #endif
@@ -551,7 +551,7 @@
   int inst_idx = GetInstSet().GetLibFunctionIndex(actual_inst);
   
   // Mark the instruction as executed
-  IP().FlagExecuted() = true;
+  IP().SetFlagExecuted();
 	
 
 #ifdef INSTRUCTION_COUNT
@@ -1010,7 +1010,7 @@
   
   // Set instruction flags on the injected code
   for (int i = line_num; i < line_num + inject_size; i++) {
-    memory.FlagInjected(i) = true;
+    memory.SetFlagInjected(i);
   }
   organism->GetPhenotype().IsModified() = true;
 
@@ -1037,7 +1037,7 @@
       
       // Set instruction flags on the injected code
       for (int i = line_num; i < line_num + inject_size; i++) {
-	memory.FlagInjected(i) = true;
+	memory.SetFlagInjected(i);
       }
       organism->GetPhenotype().IsModified() = true;
       organism->GetPhenotype().IsMultiThread() = true;
@@ -1071,8 +1071,8 @@
   assert(mut_point >= 0 && mut_point < GetMemory().GetSize());
 
   GetMemory()[mut_point] = GetRandomInst();
-  GetMemory().FlagMutated(mut_point) = true;
-  GetMemory().FlagPointMut(mut_point) = true;
+  GetMemory().SetFlagMutated(mut_point);
+  GetMemory().SetFlagPointMut(mut_point);
   //organism->GetPhenotype().IsMutated() = true;
   organism->CPUStats().mut_stats.point_mut_count++;
 }
@@ -1216,7 +1216,7 @@
   switch (type) {
   case nMutation::TYPE_POINT:
     target_memory[pos] = GetRandomInst();
-    target_memory.FlagMutated(pos) = true;
+    target_memory.SetFlagMutated(pos);
     break;
   case nMutation::TYPE_INSERT:
   case nMutation::TYPE_DELETE:
@@ -1270,7 +1270,7 @@
 
     // If this is the first line of the template, mark it executed.
     if (GetLabel().GetSize() <=	cConfig::GetMaxLabelExeSize()) {
-      inst_ptr->FlagExecuted() = true;
+      inst_ptr->SetFlagExecuted();
     }
   }
 }
@@ -1387,7 +1387,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_register = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_register;
 }
@@ -1400,7 +1400,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_head = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_head;
 }
@@ -1713,12 +1713,12 @@
 
   // Count up mutated lines
   for(int i = 0; i < GetMemory().GetSize(); i++){
-    if (GetMemory().FlagPointMut(i) == true) {
+    if (GetMemory().FlagPointMut(i)) {
       cpu_stats.mut_stats.point_mut_line_count++;
     }
   }
   for(int i = 0; i < child_genome.GetSize(); i++){
-    if( child_genome.FlagCopyMut(i) == true) {
+    if( child_genome.FlagCopyMut(i)) {
       cpu_stats.mut_stats.copy_mut_line_count++;
     }
   }
@@ -2430,17 +2430,17 @@
 
   if (organism->TestCopyMut()) {
     to.SetInst(GetRandomInst());
-    to.FlagMutated() = true;  // Mark this instruction as mutated...
-    to.FlagCopyMut() = true;  // Mark this instruction as copy mut...
+    to.SetFlagMutated();  // Mark this instruction as mutated...
+    to.SetFlagCopyMut();  // Mark this instruction as copy mut...
     //organism->GetPhenotype().IsMutated() = true;
     cpu_stats.mut_stats.copy_mut_count++;
   } else {
     to.SetInst(from.GetInst());
-    to.FlagMutated() = false;  // UnMark
-    to.FlagCopyMut() = false;  // UnMark
+    to.ClearFlagMutated();  // UnMark
+    to.ClearFlagCopyMut();  // UnMark
   }
 
-  to.FlagCopied() = true;  // Set the copied flag.
+  to.SetFlagCopied();  // Set the copied flag.
   cpu_stats.mut_stats.copies_exec++;
   return true;
 }
@@ -2466,17 +2466,17 @@
   // Change value on a mutation...
   if (organism->TestCopyMut()) {
     to.SetInst(GetRandomInst());
-    to.FlagMutated() = true;      // Mark this instruction as mutated...
-    to.FlagCopyMut() = true;      // Mark this instruction as copy mut...
+    to.SetFlagMutated();      // Mark this instruction as mutated...
+    to.SetFlagCopyMut();      // Mark this instruction as copy mut...
     //organism->GetPhenotype().IsMutated() = true;
     cpu_stats.mut_stats.copy_mut_count++;
   } else {
     to.SetInst(cInstruction(value));
-    to.FlagMutated() = false;     // UnMark
-    to.FlagCopyMut() = false;     // UnMark
+    to.ClearFlagMutated();     // UnMark
+    to.ClearFlagCopyMut();     // UnMark
   }
 
-  to.FlagCopied() = true;  // Set the copied flag.
+  to.SetFlagCopied();  // Set the copied flag.
   cpu_stats.mut_stats.copies_exec++;
   return true;
 }
@@ -2499,17 +2499,17 @@
   // Change value on a mutation...
   if (organism->TestCopyMut()) {
     to.SetInst(GetRandomInst());
-    to.FlagMutated() = true;      // Mark this instruction as mutated...
-    to.FlagCopyMut() = true;      // Mark this instruction as copy mut...
+    to.SetFlagMutated();      // Mark this instruction as mutated...
+    to.SetFlagCopyMut();      // Mark this instruction as copy mut...
     //organism->GetPhenotype().IsMutated() = true;
     cpu_stats.mut_stats.copy_mut_count++;
   } else {
     to.SetInst(cInstruction(value));
-    to.FlagMutated() = false;     // UnMark
-    to.FlagCopyMut() = false;     // UnMark
+    to.ClearFlagMutated();     // UnMark
+    to.ClearFlagCopyMut();     // UnMark
   }
 
-  to.FlagCopied() = true;  // Set the copied flag.
+  to.SetFlagCopied();  // Set the copied flag.
   cpu_stats.mut_stats.copies_exec++;
   return true;
 }
@@ -2523,8 +2523,8 @@
   // Compare is dangerous -- it can cause mutations!
   if (organism->TestCopyMut()) {
     to.SetInst(GetRandomInst());
-    to.FlagMutated() = true;      // Mark this instruction as mutated...
-    to.FlagCopyMut() = true;      // Mark this instruction as copy mut...
+    to.SetFlagMutated();      // Mark this instruction as mutated...
+    to.SetFlagCopyMut();      // Mark this instruction as copy mut...
     //organism->GetPhenotype().IsMutated() = true;
   }
 
@@ -2592,7 +2592,7 @@
 
   int lines_executed = 0;
   for ( int i = 0; i < GetMemory().GetSize(); i++ ) {
-    if ( GetMemory().FlagExecuted(i) == true ) lines_executed++;
+    if ( GetMemory().FlagExecuted(i)) lines_executed++;
   }
   organism->GetPhenotype().SetLinesExecuted(lines_executed);
 
@@ -3324,7 +3324,7 @@
   if (value < 0 || value >= GetNumInst()) value = 0;
 
   active_head.SetInst(cInstruction(value));
-  active_head.FlagCopied() = true;
+  active_head.SetFlagCopied();
 
   // Advance the head after write...
   active_head++;
@@ -3349,15 +3349,15 @@
   if (organism->TestCopyMut()) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.FlagMutated() = true;
-    write_head.FlagCopyMut() = true;
+    write_head.SetFlagMutated();
+    write_head.SetFlagCopyMut();
     //organism->GetPhenotype().IsMutated() = true;
   }
 
   cpu_stats.mut_stats.copies_exec++;
 
   write_head.SetInst(read_inst);
-  write_head.FlagCopied() = true;  // Set the copied flag...
+  write_head.SetFlagCopied();  // Set the copied flag...
 
   // TriggerMutations(nMutation::TRIGGER_WRITE, write_head);
 
@@ -3382,15 +3382,15 @@
   if ( g_random.P(organism->GetCopyMutProb() / reduction) ) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.FlagMutated() = true;
-    write_head.FlagCopyMut() = true;
+    write_head.SetFlagMutated();
+    write_head.SetFlagCopyMut();
     //organism->GetPhenotype().IsMutated() = true;
   }
 
   cpu_stats.mut_stats.copies_exec++;
 
   write_head.SetInst(read_inst);
-  write_head.FlagCopied() = true;  // Set the copied flag...
+  write_head.SetFlagCopied();  // Set the copied flag...
 
   read_head.Advance();
   write_head.Advance();

Modified: trunk/source/cpu/cHardwareSMT.cc
===================================================================
--- trunk/source/cpu/cHardwareSMT.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHardwareSMT.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -194,7 +194,7 @@
     IP().Adjust();
 		
 #ifdef BREAKPOINTS
-    if (IP().FlagBreakpoint() == true) {
+    if (IP().FlagBreakpoint()) {
       organism->DoBreakpoint();
     }
 #endif
@@ -280,7 +280,7 @@
   int inst_idx = GetInstSet().GetLibFunctionIndex(actual_inst);
   
   // Mark the instruction as executed
-  IP().FlagExecuted() = true;
+  IP().SetFlagExecuted();
 	
 	
 #ifdef INSTRUCTION_COUNT
@@ -791,7 +791,7 @@
 		
     // Set instruction flags on the injected code
     for (int i = 0; i < inject_code.GetSize(); i++) {
-      m_mem_array[target_mem_space].FlagInjected(i) = true;
+      m_mem_array[target_mem_space].SetFlagInjected(i);
     }
     organism->GetPhenotype().IsModified() = true;
     
@@ -823,8 +823,8 @@
   assert(mut_point >= 0 && mut_point < m_mem_array[0].GetSize());
 	
   m_mem_array[0][mut_point] = GetRandomInst();
-  m_mem_array[0].FlagMutated(mut_point) = true;
-  m_mem_array[0].FlagPointMut(mut_point) = true;
+  m_mem_array[0].SetFlagMutated(mut_point);
+  m_mem_array[0].SetFlagPointMut(mut_point);
   organism->CPUStats().mut_stats.point_mut_count++;
 }
 
@@ -966,7 +966,7 @@
   switch (type) {
 		case nMutation::TYPE_POINT:
 			target_memory[pos] = GetRandomInst();
-			target_memory.FlagMutated(pos) = true;
+			target_memory.SetFlagMutated(pos);
 			break;
 		case nMutation::TYPE_INSERT:
 		case nMutation::TYPE_DELETE:
@@ -1020,7 +1020,7 @@
 		
     // If this is the first line of the template, mark it executed.
     if (GetLabel().GetSize() <=	cConfig::GetMaxLabelExeSize()) {
-      inst_ptr->FlagExecuted() = true;
+      inst_ptr->SetFlagExecuted();
     }
   }
 }
@@ -1141,7 +1141,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_stack = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_stack;
 }
@@ -1153,7 +1153,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_stack = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   } else {
     default_stack = FindNextStack(default_stack);
   }
@@ -1167,7 +1167,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_stack = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   } else {
     default_stack = FindPreviousStack(default_stack);
   }
@@ -1181,7 +1181,7 @@
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_stack = GetInstSet().GetNopMod(IP().GetInst());
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   } else {
     default_stack = FindPreviousStack(default_stack);
   }
@@ -1196,7 +1196,7 @@
     IP().Advance();    
     int nop_head = GetInstSet().GetNopMod(IP().GetInst());
     if (nop_head < nHardware::NUM_HEADS) default_head = nop_head;
-    IP().FlagExecuted() = true;
+    IP().SetFlagExecuted();
   }
   return default_head;
 }
@@ -1380,12 +1380,12 @@
 	
   // Count up mutated lines
   for(int i = 0; i < m_mem_array[0].GetSize(); i++){
-    if (m_mem_array[0].FlagPointMut(i) == true) {
+    if (m_mem_array[0].FlagPointMut(i)) {
       cpu_stats.mut_stats.point_mut_line_count++;
     }
   }
   for(int i = 0; i < child_genome.GetSize(); i++){
-    if( child_genome.FlagCopyMut(i) == true) {
+    if( child_genome.FlagCopyMut(i)) {
       cpu_stats.mut_stats.copy_mut_line_count++;
     }
   }
@@ -1878,7 +1878,7 @@
   if (value < 0 || value >= GetNumInst()) value = nHardwareSMT::NOPX;
 	
   active_head.SetInst(cInstruction(value));
-  active_head.FlagCopied() = true;
+  active_head.SetFlagCopied();
 	
   // Advance the head after write...
   active_head++;
@@ -1903,8 +1903,8 @@
   if (organism->TestCopyMut()) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.FlagMutated() = true;
-    write_head.FlagCopyMut() = true;
+    write_head.SetFlagMutated();
+    write_head.SetFlagCopyMut();
     //organism->GetPhenotype().IsMutated() = true;
   }
   ReadInst(read_inst.GetOp());
@@ -1912,7 +1912,7 @@
   cpu_stats.mut_stats.copies_exec++;
 	
   write_head.SetInst(read_inst);
-  write_head.FlagCopied() = true;  // Set the copied flag...
+  write_head.SetFlagCopied();  // Set the copied flag...
 	
   // TriggerMutations(nMutation::TRIGGER_WRITE, write_head);
 	

Modified: trunk/source/cpu/cHeadCPU.cc
===================================================================
--- trunk/source/cpu/cHeadCPU.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHeadCPU.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -237,42 +237,54 @@
 
 
 
-bool & cHeadCPU::FlagCopied()
+void cHeadCPU::SetFlagCopied()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagCopied(position);     
+  return cur_hardware->GetMemory().SetFlagCopied(position);     
 }
 
-bool & cHeadCPU::FlagMutated()
+void cHeadCPU::SetFlagMutated()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagMutated(position);    
+  return cur_hardware->GetMemory().SetFlagMutated(position);    
 }
 
-bool & cHeadCPU::FlagExecuted()
+void cHeadCPU::SetFlagExecuted()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagExecuted(position);   
+  return cur_hardware->GetMemory().SetFlagExecuted(position);   
 }
 
-bool & cHeadCPU::FlagBreakpoint()
+void cHeadCPU::SetFlagBreakpoint()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagBreakpoint(position); 
+  return cur_hardware->GetMemory().SetFlagBreakpoint(position); 
 }
 
-bool & cHeadCPU::FlagPointMut()
+void cHeadCPU::SetFlagPointMut()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagPointMut(position);   
+  return cur_hardware->GetMemory().SetFlagPointMut(position);   
 }
 
-bool & cHeadCPU::FlagCopyMut()
+void cHeadCPU::SetFlagCopyMut()
 {
   assert(cur_hardware != NULL);
-  return cur_hardware->GetMemory().FlagCopyMut(position);    
+  return cur_hardware->GetMemory().SetFlagCopyMut(position);    
 }
 
+void cHeadCPU::ClearFlagMutated()
+{
+  assert(cur_hardware != NULL);
+  return cur_hardware->GetMemory().ClearFlagMutated(position);    
+}
+
+void cHeadCPU::ClearFlagCopyMut()
+{
+  assert(cur_hardware != NULL);
+  return cur_hardware->GetMemory().ClearFlagCopyMut(position);    
+}
+
 cHeadCPU & cHeadCPU::operator=(const cHeadCPU & in_cpu_head)
 {
   main_hardware = in_cpu_head.main_hardware;

Modified: trunk/source/cpu/cHeadCPU.h
===================================================================
--- trunk/source/cpu/cHeadCPU.h	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHeadCPU.h	2005-12-13 18:59:00 UTC (rev 422)
@@ -89,13 +89,16 @@
   virtual void RemoveInst();
   virtual const cInstruction & GetNextInst();
 
-  virtual bool & FlagCopied();
-  virtual bool & FlagMutated();
-  virtual bool & FlagExecuted();
-  virtual bool & FlagBreakpoint();
-  virtual bool & FlagPointMut();
-  virtual bool & FlagCopyMut();
+  virtual void SetFlagCopied();
+  virtual void SetFlagMutated();
+  virtual void SetFlagExecuted();
+  virtual void SetFlagBreakpoint();
+  virtual void SetFlagPointMut();
+  virtual void SetFlagCopyMut();
 
+  void ClearFlagMutated();
+  void ClearFlagCopyMut();
+
   // Operator Overloading...
   virtual cHeadCPU & operator=(const cHeadCPU & in_cpu_head);
   cHeadCPU & operator++();

Modified: trunk/source/cpu/cHeadMultiMem.cc
===================================================================
--- trunk/source/cpu/cHeadMultiMem.cc	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHeadMultiMem.cc	2005-12-13 18:59:00 UTC (rev 422)
@@ -160,40 +160,40 @@
   return (AtEnd()) ? cInstSet::GetInstError() : GetMemory()[position+1];
 }
 
-bool & cHeadMultiMem::FlagCopied()
+void cHeadMultiMem::SetFlagCopied()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagCopied(position);     
+  GetMemory().SetFlagCopied(position);     
 }
 
-bool & cHeadMultiMem::FlagMutated()
+void cHeadMultiMem::SetFlagMutated()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagMutated(position);    
+  GetMemory().SetFlagMutated(position);    
 }
 
-bool & cHeadMultiMem::FlagExecuted()
+void cHeadMultiMem::SetFlagExecuted()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagExecuted(position);   
+  GetMemory().SetFlagExecuted(position);   
 }
 
-bool & cHeadMultiMem::FlagBreakpoint()
+void cHeadMultiMem::SetFlagBreakpoint()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagBreakpoint(position); 
+  GetMemory().SetFlagBreakpoint(position); 
 }
 
-bool & cHeadMultiMem::FlagPointMut()
+void cHeadMultiMem::SetFlagPointMut()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagPointMut(position);   
+  GetMemory().SetFlagPointMut(position);   
 }
 
-bool & cHeadMultiMem::FlagCopyMut()
+void cHeadMultiMem::SetFlagCopyMut()
 {
   assert(cur_hardware != NULL);
-  return GetMemory().FlagCopyMut(position);    
+  GetMemory().SetFlagCopyMut(position);    
 }
 
 cHeadMultiMem & cHeadMultiMem::operator=(const cHeadMultiMem & in_cpu_head)

Modified: trunk/source/cpu/cHeadMultiMem.h
===================================================================
--- trunk/source/cpu/cHeadMultiMem.h	2005-12-11 21:15:51 UTC (rev 421)
+++ trunk/source/cpu/cHeadMultiMem.h	2005-12-13 18:59:00 UTC (rev 422)
@@ -48,12 +48,12 @@
   void RemoveInst();
   const cInstruction& GetNextInst();
 
-  bool & FlagCopied();
-  bool & FlagMutated();
-  bool & FlagExecuted();
-  bool & FlagBreakpoint();
-  bool & FlagPointMut();
-  bool & FlagCopyMut();
+  void SetFlagCopied();
+  void SetFlagMutated();
+  void SetFlagExecuted();
+  void SetFlagBreakpoint();
+  void SetFlagPointMut();
+  void SetFlagCopyMut();
 
   // Operator Overloading...
   cHeadMultiMem & operator=(const cHeadMultiMem & in_cpu_head);




More information about the Avida-cvs mailing list