[Avida-SVN] r2144 - branches/dkdev/source/cpu

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Thu Oct 18 17:35:23 PDT 2007


Author: dknoester
Date: 2007-10-18 20:35:22 -0400 (Thu, 18 Oct 2007)
New Revision: 2144

Modified:
   branches/dkdev/source/cpu/cHardwareCPU.cc
   branches/dkdev/source/cpu/cHardwareCPU.h
Log:
New conditional instructions; playing around with multi-instruction ifs.

Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc	2007-10-18 22:40:21 UTC (rev 2143)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc	2007-10-19 00:35:22 UTC (rev 2144)
@@ -389,8 +389,13 @@
     cInstEntryCPU("self.y", &cHardwareCPU::Inst_SelfY),
     cInstEntryCPU("env.x", &cHardwareCPU::Inst_EnvX),
     cInstEntryCPU("env.y", &cHardwareCPU::Inst_EnvY),
-    cInstEntryCPU("sorted?", &cHardwareCPU::Inst_Sorted)
-//    cInstEntryCPU("", &cHardwareCPU::Inst_),
+    cInstEntryCPU("sorted?", &cHardwareCPU::Inst_Sorted),
+    cInstEntryCPU("if-less.end", &cHardwareCPU::Inst_IfLessEnd),
+    cInstEntryCPU("if-n-equ.end", &cHardwareCPU::Inst_IfNotEqualEnd),
+//    cInstEntryCPU("if-less.else", &cHardwareCPU::Inst_IfLessElse),
+//    cInstEntryCPU("else", &cHardwareCPU::Inst_Else),
+    cInstEntryCPU("end-if", &cHardwareCPU::Inst_EndIf),
+    //    cInstEntryCPU("", &cHardwareCPU::Inst_),
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -3934,3 +3939,64 @@
 
   return true;
 }
+
+
+/*! Advance the IP to the first end-if, or just one instruction if it's not present
+in the genome.  Note that this is O(n), n==genome size.  If this is a problem, we
+can preload the location of all end-if instructions at construction time.
+
+Not sure if this is going to be a problem, but we do loop around the genome searching
+for the end-if.  In that case, there's a good probability that replication can be
+royally screwed up.  Be warned...
+*/
+void cHardwareCPU::Advance_EndIf() {
+  cHeadCPU ptr(IP());
+  const int current = ptr.GetPosition();
+  ptr.Advance();
+  while(ptr.GetPosition() != current) {
+    ptr.Advance();
+    if(m_inst_set->GetName(ptr.GetInst())=="end-if") {
+      IP().Set(ptr);
+      break;
+    }
+  }
+  // Advance the IP one instruction - If we found an end-if, this advances to
+  // the following instruction.  If not, this skips over the instruction following
+  // the if-less-end, behaving just like a standard Avida conditional.
+  IP().Advance();  
+}
+
+
+bool cHardwareCPU::Inst_IfLessEnd(cAvidaContext& ctx) {
+  const int x = FindModifiedRegister(REG_BX);
+  const int y = FindNextRegister(x);
+  
+  if(GetRegister(x) >= GetRegister(y)) { Advance_EndIf(); }
+  return true;
+}
+
+
+bool cHardwareCPU::Inst_IfNotEqualEnd(cAvidaContext& ctx) {
+  const int x = FindModifiedRegister(REG_BX);
+  const int y = FindNextRegister(x);
+  
+  if(GetRegister(x) == GetRegister(y)) { Advance_EndIf(); }
+  return true;  
+}
+
+
+bool cHardwareCPU::Inst_IfLessElse(cAvidaContext& ctx) {
+  // Not yet implemented...
+  return true;
+}
+
+
+bool cHardwareCPU::Inst_Else(cAvidaContext& ctx) { 
+  return true; 
+}
+
+
+bool cHardwareCPU::Inst_EndIf(cAvidaContext& ctx) { 
+  // Flag only, for right now.
+  return true; 
+}

Modified: branches/dkdev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.h	2007-10-18 22:40:21 UTC (rev 2143)
+++ branches/dkdev/source/cpu/cHardwareCPU.h	2007-10-19 00:35:22 UTC (rev 2144)
@@ -507,6 +507,14 @@
   bool Inst_EnvX(cAvidaContext& ctx);
   bool Inst_EnvY(cAvidaContext& ctx);
   bool Inst_Sorted(cAvidaContext& ctx);
+  
+  // If-less-else-if, else, endif
+  void Advance_EndIf();
+  bool Inst_IfLessEnd(cAvidaContext& ctx);
+  bool Inst_IfNotEqualEnd(cAvidaContext& ctx);
+  bool Inst_IfLessElse(cAvidaContext& ctx);
+  bool Inst_Else(cAvidaContext& ctx);
+  bool Inst_EndIf(cAvidaContext& ctx);
 };
 
 




More information about the Avida-cvs mailing list