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

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sat Dec 13 13:47:38 PST 2008


Author: brysonda
Date: 2008-12-13 16:47:37 -0500 (Sat, 13 Dec 2008)
New Revision: 3035

Modified:
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cHardwareExperimental.h
Log:
Implement if-grt-0, if-stk-gtr, and swap-stk-top in cHardwareExperimental.

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2008-12-13 21:20:44 UTC (rev 3034)
+++ development/source/cpu/cHardwareExperimental.cc	2008-12-13 21:47:37 UTC (rev 3035)
@@ -99,16 +99,20 @@
     // Standard Conditionals
     tInstLibEntry<tMethod>("if-n-equ", &cHardwareExperimental::Inst_IfNEqu, nInstFlag::DEFAULT, "Execute next instruction if ?BX?!=?CX?, else skip it"),
     tInstLibEntry<tMethod>("if-less", &cHardwareExperimental::Inst_IfLess, nInstFlag::DEFAULT, "Execute next instruction if ?BX? < ?CX?, else skip it"),
+    tInstLibEntry<tMethod>("if-gtr-0", &cHardwareExperimental::Inst_IfGreaterThanZero, nInstFlag::DEFAULT, "Execute next instruction if ?BX? > 0, else skip it"),
 
     tInstLibEntry<tMethod>("if-cons", &cHardwareExperimental::Inst_IfConsensus, 0, "Execute next instruction if ?BX? in consensus, else skip it"),
     tInstLibEntry<tMethod>("if-cons-24", &cHardwareExperimental::Inst_IfConsensus24, 0, "Execute next instruction if ?BX[0:23]? in consensus , else skip it"),
     tInstLibEntry<tMethod>("if-less-cons", &cHardwareExperimental::Inst_IfLessConsensus, 0, "Execute next instruction if Count(?BX?) < Count(?CX?), else skip it"),
     tInstLibEntry<tMethod>("if-less-cons-24", &cHardwareExperimental::Inst_IfLessConsensus24, 0, "Execute next instruction if Count(?BX[0:23]?) < Count(?CX[0:23]?), else skip it"),
 
+    tInstLibEntry<tMethod>("if-stk-gtr", &cHardwareExperimental::Inst_IfStackGreater, nInstFlag::DEFAULT, "Execute next instruction if the top of the current stack > inactive stack, else skip it"),
+
     // Core ALU Operations
     tInstLibEntry<tMethod>("pop", &cHardwareExperimental::Inst_Pop, nInstFlag::DEFAULT, "Remove top number from stack and place into ?BX?"),
     tInstLibEntry<tMethod>("push", &cHardwareExperimental::Inst_Push, nInstFlag::DEFAULT, "Copy number from ?BX? and place it into the stack"),
     tInstLibEntry<tMethod>("swap-stk", &cHardwareExperimental::Inst_SwitchStack, nInstFlag::DEFAULT, "Toggle which stack is currently being used"),
+    tInstLibEntry<tMethod>("swap-stk-top", &cHardwareExperimental::Inst_SwapStackTop, nInstFlag::DEFAULT, "Swap the values at the top of both stacks"),
     tInstLibEntry<tMethod>("swap", &cHardwareExperimental::Inst_Swap, nInstFlag::DEFAULT, "Swap the contents of ?BX? with ?CX?"),
     
     tInstLibEntry<tMethod>("shift-r", &cHardwareExperimental::Inst_ShiftR, nInstFlag::DEFAULT, "Shift bits in ?BX? right by one (divide by two)"),
@@ -985,7 +989,7 @@
 // And the instructions...
 //////////////////////////
 
-bool cHardwareExperimental::Inst_IfNEqu(cAvidaContext& ctx)     // Execute next if bx != ?cx?
+bool cHardwareExperimental::Inst_IfNEqu(cAvidaContext& ctx) // Execute next if bx != ?cx?
 {
   const int op1 = FindModifiedRegister(REG_BX);
   const int op2 = FindModifiedNextRegister(op1);
@@ -993,7 +997,7 @@
   return true;
 }
 
-bool cHardwareExperimental::Inst_IfLess(cAvidaContext& ctx)       // Execute next if ?bx? < ?cx?
+bool cHardwareExperimental::Inst_IfLess(cAvidaContext& ctx) // Execute next if ?bx? < ?cx?
 {
   const int op1 = FindModifiedRegister(REG_BX);
   const int op2 = FindModifiedNextRegister(op1);
@@ -1001,6 +1005,13 @@
   return true;
 }
 
+bool cHardwareExperimental::Inst_IfGreaterThanZero(cAvidaContext& ctx)  // Execute next if ?bx? > 0
+{
+  const int op1 = FindModifiedRegister(REG_BX);
+  if (GetRegister(op1) <= 0)  IP().Advance();
+  return true;
+}
+
 bool cHardwareExperimental::Inst_IfConsensus(cAvidaContext& ctx)
 {
   const int op1 = FindModifiedRegister(REG_BX);
@@ -1031,6 +1042,13 @@
   return true;
 }
 
+bool cHardwareExperimental::Inst_IfStackGreater(cAvidaContext& ctx)
+{
+  int cur_stack = m_threads[m_cur_thread].cur_stack;
+  if (getStack(cur_stack).Peek().value <=  getStack(!cur_stack).Peek().value)  IP().Advance();
+  return true;
+}
+
 bool cHardwareExperimental::Inst_Label(cAvidaContext& ctx)
 {
   ReadLabel();
@@ -1049,17 +1067,22 @@
 bool cHardwareExperimental::Inst_Push(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);
-  if (m_threads[m_cur_thread].cur_stack == 0) {
-    m_threads[m_cur_thread].stack.Push(m_threads[m_cur_thread].reg[reg_used]);
-  } else {
-    m_global_stack.Push(m_threads[m_cur_thread].reg[reg_used]);
-  }
+  getStack(m_threads[m_cur_thread].cur_stack).Push(m_threads[m_cur_thread].reg[reg_used]);
   return true;
 }
 
 
 bool cHardwareExperimental::Inst_SwitchStack(cAvidaContext& ctx) { switchStack(); return true;}
 
+bool cHardwareExperimental::Inst_SwapStackTop(cAvidaContext& ctx)
+{
+  sInternalValue v0 = getStack(0).Pop();
+  sInternalValue v1 = getStack(1).Pop();
+  getStack(0).Push(v1);
+  getStack(1).Push(v0);
+  return true;
+}
+
 bool cHardwareExperimental::Inst_Swap(cAvidaContext& ctx)
 {
   const int op1 = FindModifiedRegister(REG_BX);

Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h	2008-12-13 21:20:44 UTC (rev 3034)
+++ development/source/cpu/cHardwareExperimental.h	2008-12-13 21:47:37 UTC (rev 3035)
@@ -312,6 +312,7 @@
   
   // --------  Stack Manipulation  --------
   inline sInternalValue stackPop();
+  inline cLocalStack& getStack(int stack_id);
   inline void switchStack();
   
   
@@ -380,16 +381,19 @@
   // Flow Control
   bool Inst_IfNEqu(cAvidaContext& ctx);
   bool Inst_IfLess(cAvidaContext& ctx);
+  bool Inst_IfGreaterThanZero(cAvidaContext& ctx);
   bool Inst_IfConsensus(cAvidaContext& ctx);
   bool Inst_IfConsensus24(cAvidaContext& ctx);
   bool Inst_IfLessConsensus(cAvidaContext& ctx);
   bool Inst_IfLessConsensus24(cAvidaContext& ctx);
+  bool Inst_IfStackGreater(cAvidaContext& ctx);
   bool Inst_Label(cAvidaContext& ctx);
     
   // Stack and Register Operations
   bool Inst_Pop(cAvidaContext& ctx);
   bool Inst_Push(cAvidaContext& ctx);
   bool Inst_SwitchStack(cAvidaContext& ctx);
+  bool Inst_SwapStackTop(cAvidaContext& ctx);
   bool Inst_Swap(cAvidaContext& ctx);
 
   // Single-Argument Math
@@ -497,6 +501,23 @@
 }
 
 
+inline cHardwareExperimental::cLocalStack& cHardwareExperimental::getStack(int stack_id)
+{
+  if (stack_id == 0) {
+    return m_threads[m_cur_thread].stack;
+  } else {
+    return m_global_stack;
+  }
+}
+
+
+inline void cHardwareExperimental::switchStack()
+{
+  m_threads[m_cur_thread].cur_stack++;
+  if (m_threads[m_cur_thread].cur_stack > 1) m_threads[m_cur_thread].cur_stack = 0;
+}
+
+
 inline int cHardwareExperimental::GetStack(int depth, int stack_id, int in_thread) const
 {
   sInternalValue value;
@@ -511,13 +532,6 @@
   return value.value;
 }
 
-inline void cHardwareExperimental::switchStack()
-{
-  m_threads[m_cur_thread].cur_stack++;
-  if (m_threads[m_cur_thread].cur_stack > 1) m_threads[m_cur_thread].cur_stack = 0;
-}
-
-
 inline void cHardwareExperimental::setInternalValue(sInternalValue& dest, int value, bool from_env)
 {
   dest.value = value;




More information about the Avida-cvs mailing list