[Avida-SVN] r1200 - development/source/cpu

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sat Jan 27 06:15:13 PST 2007


Author: brysonda
Date: 2007-01-27 09:15:13 -0500 (Sat, 27 Jan 2007)
New Revision: 1200

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
Log:
Adjust usage of NUM_HEADS in cHardwareCPU so that it properly handles adjusted register/head/nop counts.

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-01-23 17:14:20 UTC (rev 1199)
+++ development/source/cpu/cHardwareCPU.cc	2007-01-27 14:15:13 UTC (rev 1200)
@@ -450,7 +450,7 @@
 {
   m_id = in_thread.m_id;
   for (int i = 0; i < NUM_REGISTERS; i++) reg[i] = in_thread.reg[i];
-  for (int i = 0; i < nHardware::NUM_HEADS; i++) heads[i] = in_thread.heads[i];
+  for (int i = 0; i < NUM_HEADS; i++) heads[i] = in_thread.heads[i];
   stack = in_thread.stack;
 }
 
@@ -459,7 +459,7 @@
   m_id = in_id;
   
   for (int i = 0; i < NUM_REGISTERS; i++) reg[i] = 0;
-  for (int i = 0; i < nHardware::NUM_HEADS; i++) heads[i].Reset(in_hardware);
+  for (int i = 0; i < NUM_HEADS; i++) heads[i].Reset(in_hardware);
   
   stack.Clear();
   cur_stack = 0;
@@ -953,7 +953,7 @@
   organism->GetPhenotype().IsModified() = true;
   
   // Adjust all of the heads to take into account the new mem size.  
-  for (int i = 0; i < nHardware::NUM_HEADS; i++) {    
+  for (int i = 0; i < NUM_HEADS; i++) {    
     if (GetHead(i).GetPosition() > line_num) GetHead(i).Jump(inject_size);
   }
 }
@@ -972,7 +972,7 @@
 void cHardwareCPU::AdjustHeads()
 {
   for (int i = 0; i < GetNumThreads(); i++) {
-    for (int j = 0; j < nHardware::NUM_HEADS; j++) {
+    for (int j = 0; j < NUM_HEADS; j++) {
       m_threads[i].heads[j].Adjust();
     }
   }
@@ -1100,7 +1100,7 @@
 
 inline int cHardwareCPU::FindModifiedHead(int default_head)
 {
-  assert(default_head < nHardware::NUM_HEADS); // Head ID too high.
+  assert(default_head < NUM_HEADS); // Head ID too high.
   
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-01-23 17:14:20 UTC (rev 1199)
+++ development/source/cpu/cHardwareCPU.h	2007-01-27 14:15:13 UTC (rev 1200)
@@ -67,6 +67,7 @@
 protected:
   // --------  Structure Constants  --------
   static const int NUM_REGISTERS = 3;
+  static const int NUM_HEADS = nHardware::NUM_HEADS >= NUM_REGISTERS ? nHardware::NUM_HEADS : NUM_REGISTERS;
   enum tRegisters { REG_AX = 0, REG_BX, REG_CX, REG_DX, REG_EX, REG_FX };
   static const int NUM_NOPS = 3;
   
@@ -78,7 +79,7 @@
     
   public:
     int reg[NUM_REGISTERS];
-    cHeadCPU heads[nHardware::NUM_HEADS >= NUM_REGISTERS ? nHardware::NUM_HEADS : NUM_REGISTERS];
+    cHeadCPU heads[NUM_HEADS];
     cCPUStack stack;
     unsigned char cur_stack;              // 0 = local stack, 1 = global stack.
     unsigned char cur_head;
@@ -215,7 +216,7 @@
   cHeadCPU& GetHead(int head_id) { return m_threads[m_cur_thread].heads[head_id];}
   const cHeadCPU& GetHead(int head_id, int thread) const { return m_threads[thread].heads[head_id]; }
   cHeadCPU& GetHead(int head_id, int thread) { return m_threads[thread].heads[head_id];}
-  int GetNumHeads() const { return nHardware::NUM_HEADS; }
+  int GetNumHeads() const { return NUM_HEADS; }
   
   const cHeadCPU& IP() const { return m_threads[m_cur_thread].heads[nHardware::HEAD_IP]; }
   cHeadCPU& IP() { return m_threads[m_cur_thread].heads[nHardware::HEAD_IP]; }




More information about the Avida-cvs mailing list