[avida-cvs] avida CVS commits: /current/source/cpu cpu_defs.hh cpu_stack.hh hardware_4stack.cc hardware_4stack.hh hardware_cpu.cc hardware_cpu.hh hardware_util.cc label.cc label.hh

wisnelaw avida-cvs at alife.org
Wed May 28 02:08:19 PDT 2003


wisnelaw		Tue May 27 18:08:19 2003 EDT

  Modified files:              
    /avida/current/source/cpu	cpu_defs.hh cpu_stack.hh 
                             	hardware_4stack.cc hardware_4stack.hh 
                             	hardware_cpu.cc hardware_cpu.hh 
                             	hardware_util.cc label.cc label.hh 
  Log:
  This update introduces the new 4 Stack CPU model, defined in hardware_4stack.cc.  Many more changes will be made to this model before it is in its final form.  For right now, we have removed the 3 registers from the CPU and replaced them with 4 stacks.  All operations that used registers now use stacks.  Also, a fourth NOP has been introduced which allows use of all 4 stacks.   Note that the complement system for nops is also changed - A complements C, B complements D, C complements A, and D complements B.
  
  -law
  
  
  
-------------- next part --------------
Index: avida/current/source/cpu/cpu_defs.hh
diff -u avida/current/source/cpu/cpu_defs.hh:1.10 avida/current/source/cpu/cpu_defs.hh:1.11
--- avida/current/source/cpu/cpu_defs.hh:1.10	Sun May 18 13:49:27 2003
+++ avida/current/source/cpu/cpu_defs.hh	Tue May 27 18:08:18 2003
@@ -23,12 +23,15 @@
 // (especially the number of registers) could have effects in other parts
 // of the code!
 
-#define MAX_NOPS 3
+#define MAX_NOPS 4
 #define MAX_LABEL_SIZE 10 
 #define REG_AX 0
 #define REG_BX 1
 #define REG_CX 2
+#define REG_DX 3
 #define NUM_REGISTERS 3
+#define NUM_REG_4STACK 4
+
 
 #define HEAD_IP     0
 #define HEAD_READ   1
Index: avida/current/source/cpu/cpu_stack.hh
diff -u avida/current/source/cpu/cpu_stack.hh:1.3 avida/current/source/cpu/cpu_stack.hh:1.4
--- avida/current/source/cpu/cpu_stack.hh:1.3	Sat May 17 02:48:07 2003
+++ avida/current/source/cpu/cpu_stack.hh	Tue May 27 18:08:18 2003
@@ -35,6 +35,7 @@
   inline int Pop();
   inline int Get(int depth=0) const;
   inline void Clear();
+  inline int& Top();
   void Flip();
 
   bool OK();
@@ -73,6 +74,10 @@
   stack_pointer = 0;
 }
 
+inline int& cCPUStack::Top()
+{
+  return stack[stack_pointer];
+}
 
 
 #endif
Index: avida/current/source/cpu/hardware_4stack.cc
diff -u avida/current/source/cpu/hardware_4stack.cc:1.5 avida/current/source/cpu/hardware_4stack.cc:1.6
--- avida/current/source/cpu/hardware_4stack.cc:1.5	Sun May 25 09:46:29 2003
+++ avida/current/source/cpu/hardware_4stack.cc	Tue May 27 18:08:18 2003
@@ -1,3 +1,4 @@
+
 //////////////////////////////////////////////////////////////////////////////
 // Copyright (C) 1993 - 2003 California Institute of Technology             //
 //                                                                          //
@@ -42,7 +43,7 @@
 {
    id = _id;
    if (id == -1) id = in_thread.id;
-   for (int i = 0; i < NUM_REGISTERS; i++) {
+   for (int i = 0; i < NUM_REG_4STACK; i++) {
      reg[i] = in_thread.reg[i];
    }
    for (int i = 0; i < NUM_HEADS; i++) {
@@ -57,7 +58,7 @@
 void cHardware4Stack_Thread::operator=(const cHardware4Stack_Thread & in_thread)
 {
   id = in_thread.id;
-  for (int i = 0; i < NUM_REGISTERS; i++) {
+  for (int i = 0; i < NUM_REG_4STACK; i++) {
     reg[i] = in_thread.reg[i];
   }
   for (int i = 0; i < NUM_HEADS; i++) {
@@ -73,7 +74,7 @@
 {
   id = _id;
 
-  for (int i = 0; i < NUM_REGISTERS; i++) reg[i] = 0;
+  for (int i = 0; i < NUM_REG_4STACK; i++) reg[i] = 0;
   for (int i = 0; i < NUM_HEADS; i++) heads[i].Reset(in_hardware);
 
   stack.Clear();
@@ -94,7 +95,7 @@
   fp << "cHardware4Stack_Thread" << endl;
 
   // registers
-  for( int i=0; i<NUM_REGISTERS; ++i ){
+  for( int i=0; i<NUM_REG_4STACK; ++i ){
     fp<<reg[i]<<endl;
   }
 
@@ -129,7 +130,7 @@
   assert( foo == "cHardware4Stack_Thread");
 
   // registers
-  for( int i=0; i<NUM_REGISTERS; ++i ){
+  for( int i=0; i<NUM_REG_4STACK; ++i ){
     fp>>reg[i];
   }
 
@@ -243,9 +244,10 @@
     int nop_mod;
   };
   static const cNOPEntry4Stack s_n_array[] = {
-    cNOPEntry4Stack("nop-A", REG_AX),
-    cNOPEntry4Stack("nop-B", REG_BX),
-    cNOPEntry4Stack("nop-C", REG_CX)
+    cNOPEntry4Stack("Nop-A", REG_AX),
+    cNOPEntry4Stack("Nop-B", REG_BX),
+    cNOPEntry4Stack("Nop-C", REG_CX),
+    cNOPEntry4Stack("Nop-D", REG_DX),
   };
 
   struct cInstEntry4Stack {
@@ -254,11 +256,88 @@
     tHardware4StackMethod function;
   };
   static const cInstEntry4Stack s_f_array[] = {
-    /*
+    //<<<<<<< hardware_4stack.cc
+    //1 
+    cInstEntry4Stack("Nop-A",     &cHardware4Stack::Inst_Nop), 
+    //2
+    cInstEntry4Stack("Nop-B",     &cHardware4Stack::Inst_Nop), 
+    //3
+    cInstEntry4Stack("Nop-C",     &cHardware4Stack::Inst_Nop),   
+    //4 - not implemented yet...
+    cInstEntry4Stack("Nop-D",     &cHardware4Stack::Inst_Nop), 
+    //5
+    cInstEntry4Stack("Nop-X",     &cHardware4Stack::Inst_Nop),
+    //6 
+    cInstEntry4Stack("Val-Shift-R",   &cHardware4Stack::Inst_ShiftR),
+    //7
+    cInstEntry4Stack("Val-Shift-L",   &cHardware4Stack::Inst_ShiftL),
+    //8
+    cInstEntry4Stack("Val-Nand",      &cHardware4Stack::Inst_Nand),
+    //9
+    cInstEntry4Stack("Val-Add",       &cHardware4Stack::Inst_Add),
+    //10
+    cInstEntry4Stack("Val-Sub",       &cHardware4Stack::Inst_Sub),
+    //11
+    cInstEntry4Stack("Val-Mult",      &cHardware4Stack::Inst_Mult),
+    //12
+    cInstEntry4Stack("Val-Div",       &cHardware4Stack::Inst_Div),
+    //13
+    cInstEntry4Stack("SetMemory",   &cHardware4Stack::Inst_MaxAlloc),
+    //14
+    cInstEntry4Stack("Divide",  &cHardware4Stack::Inst_HeadDivide),
+    //15
+    cInstEntry4Stack("Inst-Read",    &cHardware4Stack::Inst_HeadRead),
+    //16
+    cInstEntry4Stack("Inst-Write",   &cHardware4Stack::Inst_HeadWrite),
+    //keeping this one for the transition period
+    cInstEntry4Stack("Inst-Copy",    &cHardware4Stack::Inst_HeadCopy),
+    //17
+    cInstEntry4Stack("If-Equal",    &cHardware4Stack::Inst_IfEqu),
+    //18
+    cInstEntry4Stack("If-Not-Equal",  &cHardware4Stack::Inst_IfNEqu),
+    //19
+    cInstEntry4Stack("If-Less",   &cHardware4Stack::Inst_IfLess),
+    //20
+    cInstEntry4Stack("If-Greater",    &cHardware4Stack::Inst_IfGr),
+    //21
+    cInstEntry4Stack("Head-Push",    &cHardware4Stack::Inst_HeadPush),
+    //22
+    cInstEntry4Stack("Head-Pop",     &cHardware4Stack::Inst_HeadPop),
+    //23
+    cInstEntry4Stack("Head-Move",  &cHardware4Stack::Inst_MoveHead),
+    //24
+    cInstEntry4Stack("Search",  &cHardware4Stack::Inst_HeadSearch),
+    //25
+    cInstEntry4Stack("Push-Next",    &cHardware4Stack::Inst_PushA),
+    //26
+    cInstEntry4Stack("Push-Prev",    &cHardware4Stack::Inst_PushB),
+    //27
+    cInstEntry4Stack("Push-Comp",    &cHardware4Stack::Inst_PushC),
+    //28 - Not implemented yet...
+    //cInstEntry4Stack("Val-Delete", &cHardware4Stack::Inst_ValDelete
+    //29
+    cInstEntry4Stack("Val-Copy",  &cHardware4Stack::Inst_CopyStack),
+    //30
+    cInstEntry4Stack("ThreadFork",   &cHardware4Stack::Inst_ForkThread),
+    //31
+    cInstEntry4Stack("if-label",  &cHardware4Stack::Inst_IfLabel),
+    //32
+    cInstEntry4Stack("Val-Inc",       &cHardware4Stack::Inst_Inc),
+    //33
+    cInstEntry4Stack("Val-Dec",       &cHardware4Stack::Inst_Dec),
+    //34
+    cInstEntry4Stack("Val-Mod",       &cHardware4Stack::Inst_Mod),
+    //35
+    cInstEntry4Stack("ThreadKill",   &cHardware4Stack::Inst_KillThread),
+    
+    /*=======
+    
     Note: all entries of cNOPEntryCPU s_n_array must have corresponding
     in the same order in cInstEntryCPU s_f_array, and these entries must
     be the first elements of s_f_array.
-    */
+   
+    >>>>>>> 1.4
+    
     cInstEntry4Stack("nop-A",     &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("nop-B",     &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("nop-C",     &cHardware4Stack::Inst_Nop),
@@ -348,7 +427,7 @@
 
     // Placebo instructions
     // nop-x (included with nops)
-    cInstEntry4Stack("skip",      &cHardware4Stack::Inst_Skip)
+    cInstEntry4Stack("skip",      &cHardware4Stack::Inst_Skip)*/
   };
 
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry4Stack);
@@ -622,6 +701,9 @@
      << "CX:" << Register(REG_CX) << " "
      << setbase(16) << "[0x" << Register(REG_CX) << "]" << setbase(10)
 
+     << "DX:" << Register(REG_DX) << " "
+     << setbase(16) << "[0x" << Register(REG_DX) << "]" << setbase(10)
+
      << endl;
 
   fp << "  R-Head:" << GetHead(HEAD_READ).GetPosition() << " "
@@ -1386,7 +1468,7 @@
 
 inline int cHardware4Stack::FindModifiedRegister(int default_register)
 {
-  assert(default_register < NUM_REGISTERS);  // Reg ID too high.
+  assert(default_register < NUM_REG_4STACK);  // Reg ID too high.
 
   if (GetInstSet().IsNop(IP().GetNextInst())) {
     IP().Advance();
@@ -1396,6 +1478,18 @@
   return default_register;
 }
 
+inline int cHardware4Stack::FindModifiedStack(int default_stack)
+{
+  assert(default_stack < NUM_STACKS);  // Stack ID too high.
+
+  if (GetInstSet().IsNop(IP().GetNextInst())) {
+    IP().Advance();
+    default_stack = GetInstSet().GetNopMod(IP().GetInst());
+    IP().FlagExecuted() = true;
+  }
+  return default_stack;
+}
+
 
 inline int cHardware4Stack::FindModifiedHead(int default_head)
 {
@@ -1412,10 +1506,15 @@
 
 inline int cHardware4Stack::FindComplementRegister(int base_reg)
 {
-  const int comp_reg = base_reg + 1;
-  return (comp_reg  == NUM_REGISTERS) ? 0 : comp_reg;
+  const int comp_reg = base_reg + 2;
+  return comp_reg%NUM_REG_4STACK;
 }
 
+inline int cHardware4Stack::FindComplementStack(int base_stack)
+{
+  const int comp_stack = base_stack + 2;
+  return comp_stack%NUM_STACKS;
+}
 
 inline void cHardware4Stack::Fault(int fault_loc, int fault_type, cString fault_desc)
 {
@@ -1800,167 +1899,460 @@
 // And the instructions...
 //////////////////////////
 
-bool cHardware4Stack::Inst_If0()          // Execute next if ?bx? ==0.
+//6
+bool cHardware4Stack::Inst_ShiftR()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) != 0)  IP().Advance();
-  return true; 
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() >>= 1;
+  return true;
 }
 
-bool cHardware4Stack::Inst_IfNot0()       // Execute next if ?bx? != 0.
-{ 
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) == 0)  IP().Advance();
+//7
+bool cHardware4Stack::Inst_ShiftL()
+{
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() <<= 1;
   return true;
 }
 
-bool cHardware4Stack::Inst_IfEqu()      // Execute next if bx == ?cx?
+//8
+bool cHardware4Stack::Inst_Nand()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) != Register(reg_used2))  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() = ~(Stack(STACK_BX).Top() & Stack(STACK_CX).Top());
   return true;
 }
 
-bool cHardware4Stack::Inst_IfNEqu()     // Execute next if bx != ?cx?
+//9
+bool cHardware4Stack::Inst_Add()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) == Register(reg_used2))  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() = Stack(STACK_BX).Top() + Stack(STACK_CX).Top();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfGr0()       // Execute next if ?bx? ! < 0.
+//10
+bool cHardware4Stack::Inst_Sub()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) <= 0)  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() = Stack(STACK_BX).Top() - Stack(STACK_CX).Top();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfGr()       // Execute next if bx > ?cx?
+//11
+bool cHardware4Stack::Inst_Mult()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) <= Register(reg_used2))  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() = Stack(STACK_BX).Top() * Stack(STACK_CX).Top();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfGrEqu0()       // Execute next if ?bx? != 0.
+//12
+bool cHardware4Stack::Inst_Div()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) < 0)  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  if (Stack(STACK_CX).Top() != 0) {
+    if (0-INT_MAX > Stack(STACK_BX).Top() && Stack(STACK_CX).Top() == -1)
+      Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: Float exception");
+    else
+      Stack(stack_used).Top() = Stack(STACK_BX).Top() / Stack(STACK_CX).Top();
+  } else {
+    Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: dividing by 0");
+    return false;
+  }
   return true;
 }
 
-bool cHardware4Stack::Inst_IfGrEqu()       // Execute next if bx > ?cx?
+//13 
+bool cHardware4Stack::Inst_MaxAlloc()   // Allocate maximal more
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) < Register(reg_used2)) IP().Advance();
+  const int cur_size = GetMemory().GetSize();
+  const int alloc_size = Min((int) (cConfig::GetChildSizeRange() * cur_size),
+			     MAX_CREATURE_SIZE - cur_size);
+  if( Allocate_Main(alloc_size) ) {
+    Stack(STACK_AX).Top() = cur_size;
+    return true;
+  } else return false;
+}
+
+//14
+bool cHardware4Stack::Inst_HeadDivide()
+{
+  return Inst_HeadDivideMut(1);
+}
+
+bool cHardware4Stack::Inst_HeadDivideMut(double mut_multiplier)
+{
+  AdjustHeads();
+  const int divide_pos = GetHead(HEAD_READ).GetPosition();
+  int child_end =  GetHead(HEAD_WRITE).GetPosition();
+  if (child_end == 0) child_end = GetMemory().GetSize();
+  const int extra_lines = GetMemory().GetSize() - child_end;
+  bool ret_val = Divide_Main(divide_pos, extra_lines, mut_multiplier);
+  // Re-adjust heads.
+  AdjustHeads();
+  return ret_val; 
+}
+
+//15
+bool cHardware4Stack::Inst_HeadRead()
+{
+  const int head_id = FindModifiedHead(HEAD_READ);
+  GetHead(head_id).Adjust();
+  sCPUStats & cpu_stats = organism->CPUStats();
+
+  // Mutations only occur on the read, for the moment.
+  int read_inst = 0;
+  if (organism->TestCopyMut()) {
+    read_inst = GetRandomInst().GetOp();
+    cpu_stats.mut_stats.copy_mut_count++;  // @CAO, hope this is good!
+  } else {
+    read_inst = GetHead(head_id).GetInst().GetOp();
+  }
+  Stack(STACK_BX).Top() = read_inst;
+  ReadInst(read_inst);
+
+  cpu_stats.mut_stats.copies_exec++;  // @CAO, this too..
+  GetHead(head_id).Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfLess0()       // Execute next if ?bx? != 0.
+//16
+bool cHardware4Stack::Inst_HeadWrite()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) >= 0)  IP().Advance();
+  const int head_id = FindModifiedHead(HEAD_WRITE);
+  cCPUHead & active_head = GetHead(head_id);
+
+  active_head.Adjust();
+
+  int value = Stack(STACK_BX).Top();
+  if (value < 0 || value >= GetNumInst()) value = 0;
+
+  active_head.SetInst(cInstruction(value));
+  active_head.FlagCopied() = true;
+
+  // Advance the head after write...
+  active_head++;
   return true;
 }
 
-bool cHardware4Stack::Inst_IfLess()       // Execute next if ?bx? < ?cx?
+//??
+bool cHardware4Stack::Inst_HeadCopy()
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) >=  Register(reg_used2))  IP().Advance();
+  // For the moment, this cannot be nop-modified.
+  cCPUHead & read_head = GetHead(HEAD_READ);
+  cCPUHead & write_head = GetHead(HEAD_WRITE);
+  sCPUStats & cpu_stats = organism->CPUStats();
+
+  read_head.Adjust();
+  write_head.Adjust();
+
+  // TriggerMutations(MUTATION_TRIGGER_READ, read_head);
+  
+  // Do mutations.
+  cInstruction read_inst = read_head.GetInst();
+  if (organism->TestCopyMut()) {
+    read_inst = GetRandomInst();
+    cpu_stats.mut_stats.copy_mut_count++; 
+    write_head.FlagMutated() = true;
+    write_head.FlagCopyMut() = true;
+    //organism->GetPhenotype().IsMutated() = true;
+  }
+  ReadInst(read_inst.GetOp());
+
+  cpu_stats.mut_stats.copies_exec++;
+
+  write_head.SetInst(read_inst);
+  write_head.FlagCopied() = true;  // Set the copied flag...
+
+  // TriggerMutations(MUTATION_TRIGGER_WRITE, write_head);
+
+  read_head.Advance();
+  write_head.Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfLsEqu0()       // Execute next if ?bx? != 0.
+//17
+bool cHardware4Stack::Inst_IfEqu()      // Execute next if bx == ?cx?
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(reg_used) > 0) IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  const int stack_used2 = FindComplementStack(stack_used);
+  if (Stack(stack_used).Top() != Stack(stack_used2).Top())  IP().Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfLsEqu()       // Execute next if bx > ?cx?
+//18
+bool cHardware4Stack::Inst_IfNEqu()     // Execute next if bx != ?cx?
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int reg_used2 = FindComplementRegister(reg_used);
-  if (Register(reg_used) >  Register(reg_used2))  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  const int stack_used2 = FindComplementStack(stack_used);
+  if (Stack(stack_used).Top() == Stack(stack_used2).Top())  IP().Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfBit1()
+//19
+bool cHardware4Stack::Inst_IfLess()       // Execute next if ?bx? < ?cx?
 {
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if ((Register(reg_used) & 1) == 0)  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  const int stack_used2 = FindComplementStack(stack_used);
+  if (Stack(stack_used).Top() >=  Stack(stack_used2).Top())  IP().Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfANotEqB()     // Execute next if AX != BX
+//20
+bool cHardware4Stack::Inst_IfGr()       // Execute next if bx > ?cx?
 {
-  if (Register(REG_AX) == Register(REG_BX) )  IP().Advance();
+  const int stack_used = FindModifiedStack(STACK_BX);
+  const int stack_used2 = FindComplementStack(stack_used);
+  if (Stack(stack_used).Top() <= Stack(stack_used2).Top())  IP().Advance();
   return true;
 }
 
-bool cHardware4Stack::Inst_IfBNotEqC()     // Execute next if BX != CX
+//21
+bool cHardware4Stack::Inst_HeadPush()
 {
-  if (Register(REG_BX) == Register(REG_CX) )  IP().Advance();
+  const int head_used = FindModifiedHead(HEAD_IP);
+  StackPush(GetHead(head_used).GetPosition());
+  if (head_used == HEAD_IP) {
+    GetHead(head_used).Set(GetHead(HEAD_FLOW));
+    advance_ip = false;
+  }
   return true;
 }
 
-bool cHardware4Stack::Inst_IfANotEqC()     // Execute next if AX != BX
+//22
+bool cHardware4Stack::Inst_HeadPop()
 {
-  if (Register(REG_AX) == Register(REG_CX) )  IP().Advance();
+  const int head_used = FindModifiedHead(HEAD_IP);
+  GetHead(head_used).Set(StackPop(), this);
   return true;
 }
 
-bool cHardware4Stack::Inst_JumpF()
+//23 
+bool cHardware4Stack::Inst_MoveHead()
+{
+  const int head_used = FindModifiedHead(HEAD_IP);
+  GetHead(head_used).Set(GetHead(HEAD_FLOW));
+  if (head_used == HEAD_IP) advance_ip = false;
+  return true;
+}
+
+//24
+bool cHardware4Stack::Inst_HeadSearch()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
+  cCPUHead found_pos = FindLabel(0);
+  const int search_size = found_pos.GetPosition() - IP().GetPosition();
+  Stack(STACK_BX).Top() = search_size;
+  Stack(STACK_CX).Top() = GetLabel().GetSize();
+  GetHead(HEAD_FLOW).Set(found_pos);
+  GetHead(HEAD_FLOW).Advance();
+  return true; 
+}
 
-  // If there is no label, jump BX steps.
-  if (GetLabel().GetSize() == 0) {
-    GetActiveHead().Jump(Register(REG_BX));
-    return true;
-  }
+//25
+bool cHardware4Stack::Inst_PushA() { StackPush(Stack(STACK_AX).Top()); return true;}
 
-  // Otherwise, try to jump to the complement label.
-  const cCPUHead jump_location(FindLabel(1));
-  if ( jump_location.GetPosition() != -1 ) {
-    GetActiveHead().Set(jump_location);
-    return true;
-  }
+//26
+bool cHardware4Stack::Inst_PushB() { StackPush(Stack(STACK_AX).Top()); return true;}
 
-  // If complement label was not found; record an error.
-  organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
-		  "jump-f: No complement label");
-  return false;
+//27
+bool cHardware4Stack::Inst_PushC() { StackPush(Stack(STACK_AX).Top()); return true;}
+
+//INSTRUCTION 28 - "ValDelete" GOES HERE - law
+
+//29
+bool cHardware4Stack::Inst_CopyStack()
+{
+  const int stack_used = FindModifiedStack(STACK_BX);
+  const int other_stack = FindComplementStack(stack_used);
+  Stack(other_stack).Top() = Stack(stack_used).Top();
+  return true;
 }
 
+//30
+bool cHardware4Stack::Inst_ForkThread()
+{
+  IP().Advance();
+  if (!ForkThread()) Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
+  return true;
+}
 
-bool cHardware4Stack::Inst_JumpB()
+//31
+bool cHardware4Stack::Inst_IfLabel()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
+  if (GetLabel() != GetReadLabel())  IP().Advance();
+  return true;
+}
 
-  // If there is no label, jump BX steps.
-  if (GetLabel().GetSize() == 0) {
-    GetActiveHead().Jump(-Register(REG_BX));
-    return true;
-  }
+//32
+bool cHardware4Stack::Inst_Inc()
+{
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() += 1;
+  return true;
+}
 
-  // otherwise jump to the complement label.
-  const cCPUHead jump_location(FindLabel(-1));
-  if ( jump_location.GetPosition() != -1 ) {
-    GetActiveHead().Set(jump_location);
-    return true;
-  }
+//33
+bool cHardware4Stack::Inst_Dec()
+{
+  const int stack_used = FindModifiedStack(STACK_BX);
+  Stack(stack_used).Top() -= 1;
+  return true;
+}
 
-  // If complement label was not found; record an error.
-  organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
-		  "jump-b: No complement label");
+//34
+bool cHardware4Stack::Inst_Mod()
+{
+  const int stack_used = FindModifiedStack(STACK_BX);
+  if (Stack(STACK_CX).Top() != 0) {
+    Stack(stack_used).Top() = Stack(STACK_BX).Top() % Stack(STACK_CX).Top();
+  } else {
+    Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
+  return false;
+  }
+  return true;
+}
+
+//35
+bool cHardware4Stack::Inst_KillThread()
+{
+  if (!KillThread()) Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
+  else advance_ip = false;
+  return true;
+}
+
+/*bool cHardware4Stack::Inst_If0()          // Execute next if ?bx? ==0.
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) != 0)  IP().Advance();
+  return true; 
+}
+
+bool cHardware4Stack::Inst_IfNot0()       // Execute next if ?bx? != 0.
+{ 
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) == 0)  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfGr0()       // Execute next if ?bx? ! < 0.
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) <= 0)  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfGrEqu0()       // Execute next if ?bx? != 0.
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) < 0)  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfGrEqu()       // Execute next if bx > ?cx?
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  const int reg_used2 = FindComplementRegister(reg_used);
+  if (Register(reg_used) < Register(reg_used2)) IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfLess0()       // Execute next if ?bx? != 0.
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) >= 0)  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfLsEqu0()       // Execute next if ?bx? != 0.
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if (Register(reg_used) > 0) IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfLsEqu()       // Execute next if bx > ?cx?
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  const int reg_used2 = FindComplementRegister(reg_used);
+  if (Register(reg_used) >  Register(reg_used2))  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfBit1()
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  if ((Register(reg_used) & 1) == 0)  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfANotEqB()     // Execute next if AX != BX
+{
+  if (Register(REG_AX) == Register(REG_BX) )  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfBNotEqC()     // Execute next if BX != CX
+{
+  if (Register(REG_BX) == Register(REG_CX) )  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_IfANotEqC()     // Execute next if AX != BX
+{
+  if (Register(REG_AX) == Register(REG_CX) )  IP().Advance();
+  return true;
+}
+
+bool cHardware4Stack::Inst_JumpF()
+{
+  ReadLabel();
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
+
+  // If there is no label, jump BX steps.
+  if (GetLabel().GetSize() == 0) {
+    GetActiveHead().Jump(Register(REG_BX));
+    return true;
+  }
+
+  // Otherwise, try to jump to the complement label.
+  const cCPUHead jump_location(FindLabel(1));
+  if ( jump_location.GetPosition() != -1 ) {
+    GetActiveHead().Set(jump_location);
+    return true;
+  }
+
+  // If complement label was not found; record an error.
+  organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
+		  "jump-f: No complement label");
+  return false;
+}
+
+bool cHardware4Stack::Inst_JumpB()
+{
+  ReadLabel();
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
+
+  // If there is no label, jump BX steps.
+  if (GetLabel().GetSize() == 0) {
+    GetActiveHead().Jump(-Register(REG_BX));
+    return true;
+  }
+
+  // otherwise jump to the complement label.
+  const cCPUHead jump_location(FindLabel(-1));
+  if ( jump_location.GetPosition() != -1 ) {
+    GetActiveHead().Set(jump_location);
+    return true;
+  }
+
+  // If complement label was not found; record an error.
+  organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
+		  "jump-b: No complement label");
   return false;
 }
 
@@ -1983,7 +2375,7 @@
   cHardware4Stack & other_hardware = (cHardware4Stack &) other_organism->GetHardware();
 
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
 
   // If there is no label, jump to line BX in creature.
   if (GetLabel().GetSize() == 0) {
@@ -2012,7 +2404,7 @@
 bool cHardware4Stack::Inst_JumpSelf()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
 
   // If there is no label, jump to line BX in creature.
   if (GetLabel().GetSize() == 0) {
@@ -2041,7 +2433,7 @@
 
   // Jump to the compliment label (or by the ammount in the bx register)
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
 
   if (GetLabel().GetSize() == 0) {
     IP().Jump(Register(REG_BX));
@@ -2080,33 +2472,10 @@
   return true;
 }
 
-bool cHardware4Stack::Inst_HeadPop()
-{
-  const int head_used = FindModifiedHead(HEAD_IP);
-  GetHead(head_used).Set(StackPop(), this);
-  return true;
-}
-
-bool cHardware4Stack::Inst_HeadPush()
-{
-  const int head_used = FindModifiedHead(HEAD_IP);
-  StackPush(GetHead(head_used).GetPosition());
-  if (head_used == HEAD_IP) {
-    GetHead(head_used).Set(GetHead(HEAD_FLOW));
-    advance_ip = false;
-  }
-  return true;
-}
-
-
 bool cHardware4Stack::Inst_PopA() { Register(REG_AX) = StackPop(); return true;}
 bool cHardware4Stack::Inst_PopB() { Register(REG_BX) = StackPop(); return true;}
 bool cHardware4Stack::Inst_PopC() { Register(REG_CX) = StackPop(); return true;}
 
-bool cHardware4Stack::Inst_PushA() { StackPush(Register(REG_AX)); return true;}
-bool cHardware4Stack::Inst_PushB() { StackPush(Register(REG_AX)); return true;}
-bool cHardware4Stack::Inst_PushC() { StackPush(Register(REG_AX)); return true;}
-
 bool cHardware4Stack::Inst_SwitchStack() { SwitchStack(); return true;}
 bool cHardware4Stack::Inst_FlipStack()   { StackFlip(); return true;}
 
@@ -2122,14 +2491,6 @@
 bool cHardware4Stack::Inst_SwapBC() { Swap(Register(REG_BX), Register(REG_CX)); return true; }
 bool cHardware4Stack::Inst_SwapAC() { Swap(Register(REG_AX), Register(REG_CX)); return true; }
 
-bool cHardware4Stack::Inst_CopyReg()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  const int other_reg = FindComplementRegister(reg_used);
-  Register(other_reg) = Register(reg_used);
-  return true;
-}
-
 bool cHardware4Stack::Inst_CopyRegAB() { Register(REG_AX) = Register(REG_BX);   return true;
 }
 bool cHardware4Stack::Inst_CopyRegAC() { Register(REG_AX) = Register(REG_CX);   return true;
@@ -2152,20 +2513,6 @@
   return true;
 }
 
-bool cHardware4Stack::Inst_ShiftR()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) >>= 1;
-  return true;
-}
-
-bool cHardware4Stack::Inst_ShiftL()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) <<= 1;
-  return true;
-}
-
 bool cHardware4Stack::Inst_Bit1()
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -2180,20 +2527,6 @@
   return true;
 }
 
-bool cHardware4Stack::Inst_Inc()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) += 1;
-  return true;
-}
-
-bool cHardware4Stack::Inst_Dec()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) -= 1;
-  return true;
-}
-
 bool cHardware4Stack::Inst_Zero()
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -2258,62 +2591,6 @@
   return true;
 }
 
-bool cHardware4Stack::Inst_Add()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) = Register(REG_BX) + Register(REG_CX);
-  return true;
-}
-
-bool cHardware4Stack::Inst_Sub()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) = Register(REG_BX) - Register(REG_CX);
-  return true;
-}
-
-bool cHardware4Stack::Inst_Mult()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) = Register(REG_BX) * Register(REG_CX);
-  return true;
-}
-
-bool cHardware4Stack::Inst_Div()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(REG_CX) != 0) {
-    if (0-INT_MAX > Register(REG_BX) && Register(REG_CX) == -1)
-      Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: Float exception");
-    else
-      Register(reg_used) = Register(REG_BX) / Register(REG_CX);
-  } else {
-    Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: dividing by 0");
-    return false;
-  }
-  return true;
-}
-
-bool cHardware4Stack::Inst_Mod()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  if (Register(REG_CX) != 0) {
-    Register(reg_used) = Register(REG_BX) % Register(REG_CX);
-  } else {
-    Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
-  return false;
-  }
-  return true;
-}
-
-
-bool cHardware4Stack::Inst_Nand()
-{
-  const int reg_used = FindModifiedRegister(REG_BX);
-  Register(reg_used) = ~(Register(REG_BX) & Register(REG_CX));
-  return true;
-}
-
 bool cHardware4Stack::Inst_Nor()
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -2499,18 +2776,6 @@
   return Allocate_Main(GetMemory().GetSize());   
 }
 
-bool cHardware4Stack::Inst_MaxAlloc()   // Allocate maximal more
-{
-  const int cur_size = GetMemory().GetSize();
-  const int alloc_size = Min((int) (cConfig::GetChildSizeRange() * cur_size),
-			     MAX_CREATURE_SIZE - cur_size);
-  if( Allocate_Main(alloc_size) ) {
-    Register(REG_AX) = cur_size;
-    return true;
-  } else return false;
-}
-
-
 bool cHardware4Stack::Inst_Repro()
 {
   // Setup child
@@ -2597,7 +2862,7 @@
   }
 
   // Search for the label in the host...
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
 
   const int inject_signal =
     host_organism->GetHardware().Inject(GetLabel(), inject_code);
@@ -2616,7 +2881,6 @@
   return true;
 }
 
-
 bool cHardware4Stack::Inst_InjectRand()
 {
   // Rotate to a random facing and then run the normal inject instruction
@@ -2669,7 +2933,7 @@
   }
 
   // Search for the label in the host...
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
 
   const int inject_signal =
     host_organism->GetHardware().InjectThread(GetLabel(), inject_code);
@@ -2738,7 +3002,7 @@
 bool cHardware4Stack::Inst_SearchF()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
   const int search_size = FindLabel(1).GetPosition() - IP().GetPosition();
   Register(REG_BX) = search_size;
   Register(REG_CX) = GetLabel().GetSize();
@@ -2748,7 +3012,7 @@
 bool cHardware4Stack::Inst_SearchB()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
   const int search_size = IP().GetPosition() - FindLabel(-1).GetPosition();
   Register(REG_BX) = search_size;
   Register(REG_CX) = GetLabel().GetSize();
@@ -2778,7 +3042,7 @@
   if (!GetLabel().GetSize()) return true;
 
   // Rotate until a complement label is found (or all have been checked).
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK);
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism * neighbor = organism->GetNeighbor();
 
@@ -2814,7 +3078,7 @@
   if (!GetLabel().GetSize()) return true;
 
   // Rotate until a complement label is found (or all have been checked).
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(2, NUM_NOPS_4STACK)S;
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism * neighbor = organism->GetNeighbor();
 
@@ -2850,24 +3114,8 @@
   if (new_mut_rate > 0.0) organism->SetCopyMutProb(new_mut_rate);
   return true;
 }
-
-
 // Multi-threading.
 
-bool cHardware4Stack::Inst_ForkThread()
-{
-  IP().Advance();
-  if (!ForkThread()) Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
-  return true;
-}
-
-bool cHardware4Stack::Inst_KillThread()
-{
-  if (!KillThread()) Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
-  else advance_ip = false;
-  return true;
-}
-
 bool cHardware4Stack::Inst_ThreadID()
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -2877,7 +3125,6 @@
 
 
 // Head-based instructions
-
 bool cHardware4Stack::Inst_SetHead()
 {
   const int head_used = FindModifiedHead(HEAD_IP);
@@ -2891,14 +3138,6 @@
   GetHead(head_used).Advance();
   return true;
 }
- 
-bool cHardware4Stack::Inst_MoveHead()
-{
-  const int head_used = FindModifiedHead(HEAD_IP);
-  GetHead(head_used).Set(GetHead(HEAD_FLOW));
-  if (head_used == HEAD_IP) advance_ip = false;
-  return true;
-}
 
 bool cHardware4Stack::Inst_JumpHead()
 {
@@ -2914,32 +3153,6 @@
   return true;
 }
 
-bool cHardware4Stack::Inst_IfLabel()
-{
-  ReadLabel();
-  GetLabel().Rotate(1);
-  if (GetLabel() != GetReadLabel())  IP().Advance();
-  return true;
-}
-
-bool cHardware4Stack::Inst_HeadDivideMut(double mut_multiplier)
-{
-  AdjustHeads();
-  const int divide_pos = GetHead(HEAD_READ).GetPosition();
-  int child_end =  GetHead(HEAD_WRITE).GetPosition();
-  if (child_end == 0) child_end = GetMemory().GetSize();
-  const int extra_lines = GetMemory().GetSize() - child_end;
-  bool ret_val = Divide_Main(divide_pos, extra_lines, mut_multiplier);
-  // Re-adjust heads.
-  AdjustHeads();
-  return ret_val; 
-}
-
-bool cHardware4Stack::Inst_HeadDivide()
-{
-  return Inst_HeadDivideMut(1);
-}
-
 bool cHardware4Stack::Inst_HeadDivideSex()  
 { 
   organism->GetPhenotype().SetDivideSex(true);
@@ -2977,81 +3190,6 @@
 bool cHardware4Stack::Inst_HeadDivide0_01()  { return Inst_HeadDivideMut(0.01); }
 bool cHardware4Stack::Inst_HeadDivide0_001()  { return Inst_HeadDivideMut(0.001); }
 
-bool cHardware4Stack::Inst_HeadRead()
-{
-  const int head_id = FindModifiedHead(HEAD_READ);
-  GetHead(head_id).Adjust();
-  sCPUStats & cpu_stats = organism->CPUStats();
-
-  // Mutations only occur on the read, for the moment.
-  int read_inst = 0;
-  if (organism->TestCopyMut()) {
-    read_inst = GetRandomInst().GetOp();
-    cpu_stats.mut_stats.copy_mut_count++;  // @CAO, hope this is good!
-  } else {
-    read_inst = GetHead(head_id).GetInst().GetOp();
-  }
-  Register(REG_BX) = read_inst;
-  ReadInst(read_inst);
-
-  cpu_stats.mut_stats.copies_exec++;  // @CAO, this too..
-  GetHead(head_id).Advance();
-  return true;
-}
-
-bool cHardware4Stack::Inst_HeadWrite()
-{
-  const int head_id = FindModifiedHead(HEAD_WRITE);
-  cCPUHead & active_head = GetHead(head_id);
-
-  active_head.Adjust();
-
-  int value = Register(REG_BX);
-  if (value < 0 || value >= GetNumInst()) value = 0;
-
-  active_head.SetInst(cInstruction(value));
-  active_head.FlagCopied() = true;
-
-  // Advance the head after write...
-  active_head++;
-  return true;
-}
-
-bool cHardware4Stack::Inst_HeadCopy()
-{
-  // For the moment, this cannot be nop-modified.
-  cCPUHead & read_head = GetHead(HEAD_READ);
-  cCPUHead & write_head = GetHead(HEAD_WRITE);
-  sCPUStats & cpu_stats = organism->CPUStats();
-
-  read_head.Adjust();
-  write_head.Adjust();
-
-  // TriggerMutations(MUTATION_TRIGGER_READ, read_head);
-  
-  // Do mutations.
-  cInstruction read_inst = read_head.GetInst();
-  if (organism->TestCopyMut()) {
-    read_inst = GetRandomInst();
-    cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.FlagMutated() = true;
-    write_head.FlagCopyMut() = true;
-    //organism->GetPhenotype().IsMutated() = true;
-  }
-  ReadInst(read_inst.GetOp());
-
-  cpu_stats.mut_stats.copies_exec++;
-
-  write_head.SetInst(read_inst);
-  write_head.FlagCopied() = true;  // Set the copied flag...
-
-  // TriggerMutations(MUTATION_TRIGGER_WRITE, write_head);
-
-  read_head.Advance();
-  write_head.Advance();
-  return true;
-}
-
 bool cHardware4Stack::HeadCopy_ErrorCorrect(double reduction)
 {
   // For the moment, this cannot be nop-modified.
@@ -3093,19 +3231,6 @@
 bool cHardware4Stack::Inst_HeadCopy9()  { return HeadCopy_ErrorCorrect(9); }
 bool cHardware4Stack::Inst_HeadCopy10() { return HeadCopy_ErrorCorrect(10); }
 
-bool cHardware4Stack::Inst_HeadSearch()
-{
-  ReadLabel();
-  GetLabel().Rotate(1);
-  cCPUHead found_pos = FindLabel(0);
-  const int search_size = found_pos.GetPosition() - IP().GetPosition();
-  Register(REG_BX) = search_size;
-  Register(REG_CX) = GetLabel().GetSize();
-  GetHead(HEAD_FLOW).Set(found_pos);
-  GetHead(HEAD_FLOW).Advance();
-  return true; 
-}
-
 bool cHardware4Stack::Inst_SetFlow()
 {
   const int reg_used = FindModifiedRegister(REG_CX);
@@ -3138,12 +3263,11 @@
   return false;
 }
 
-
 //// Placebo insts ////
 bool cHardware4Stack::Inst_Skip()
 {
   IP().Advance();
   return true;
 }
-
+*/
 
Index: avida/current/source/cpu/hardware_4stack.hh
diff -u avida/current/source/cpu/hardware_4stack.hh:1.3 avida/current/source/cpu/hardware_4stack.hh:1.4
--- avida/current/source/cpu/hardware_4stack.hh:1.3	Sun May 25 09:46:30 2003
+++ avida/current/source/cpu/hardware_4stack.hh	Tue May 27 18:08:18 2003
@@ -26,6 +26,16 @@
 class cOrganism;
 class cMutation;
 
+//new-style constant declarations - law 
+static const int NUM_LOCAL_STACKS = 2;
+static const int NUM_GLOBAL_STACKS = 2;
+static const int NUM_STACKS = NUM_LOCAL_STACKS + NUM_GLOBAL_STACKS;
+static const int STACK_AX = 0;
+static const int STACK_BX = 1;
+static const int STACK_CX = 2;
+static const int STACK_DX = 3;
+static const int NUM_NOPS_4STACK = 4;
+
 /**
  * This class is needed to run several threads on a single genome.
  *
@@ -36,11 +46,12 @@
 private:
   int id;
 public:
-  int reg[NUM_REGISTERS];
+  int reg[NUM_REG_4STACK];
   cCPUHead heads[NUM_HEADS];
   cCPUStack stack;
   UCHAR cur_stack;              // 0 = local stack, 1 = global stack.
   UCHAR cur_head;
+  cCPUStack local_stacks[NUM_LOCAL_STACKS];
 
   UCHAR input_pointer;
   tBuffer<int> input_buf;
@@ -86,6 +97,7 @@
 private:
   cCPUMemory memory;          // Memory...
   cCPUStack global_stack;     // A stack that all threads share.
+  cCPUStack global_stacks[NUM_GLOBAL_STACKS];
   int thread_time_used;
 
   tArray<cHardware4Stack_Thread> threads;
@@ -132,6 +144,8 @@
   inline void StackClear();
   inline void SwitchStack();
   int GetActiveStackID() const { return threads[cur_thread].cur_stack; }
+  //NEW STUFF
+  inline cCPUStack & Stack(int stack_id); //retrieves appropriate stack
 
   // --------  Tasks & IO  --------
   tBuffer<int> & GetInputBuffer() { return threads[cur_thread].input_buf; }
@@ -243,11 +257,12 @@
  /////////---------- Instruction Helpers ------------//////////
 
   int FindModifiedRegister(int default_register);
+  int FindModifiedStack(int default_stack);
   int FindModifiedHead(int default_head);
   int FindComplementRegister(int base_reg);
+  int FindComplementStack(int base_stack);
 
-  void Fault(int fault_loc, int fault_type, cString fault_desc="");
-
+  void Fault(int fault_loc, int fault_type, cString fault_desc=""); 
   bool Allocate_Necro(const int new_size);
   bool Allocate_Random(const int old_size, const int new_size);
   bool Allocate_Default(const int new_size);
@@ -309,7 +324,7 @@
   bool Inst_SwapAB();
   bool Inst_SwapBC();
   bool Inst_SwapAC();
-  bool Inst_CopyReg();
+  bool Inst_CopyStack();
   bool Inst_CopyRegAB();
   bool Inst_CopyRegAC();
   bool Inst_CopyRegBA();
@@ -564,6 +579,18 @@
 {
   threads[cur_thread].cur_stack++;
   if (threads[cur_thread].cur_stack > 1) threads[cur_thread].cur_stack = 0;
+}
+
+inline cCPUStack& cHardware4Stack::Stack(int stack_id)
+{
+  if(stack_id >= NUM_STACKS)
+    {
+      stack_id=0;
+    }
+  if(stack_id < NUM_LOCAL_STACKS)
+    return threads[cur_thread].local_stacks[stack_id];
+  else
+    return global_stacks[stack_id % NUM_LOCAL_STACKS];
 }
 
 #endif
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.48 avida/current/source/cpu/hardware_cpu.cc:1.49
--- avida/current/source/cpu/hardware_cpu.cc:1.48	Sun May 25 09:46:30 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Tue May 27 18:08:18 2003
@@ -2070,7 +2070,7 @@
 bool cHardwareCPU::Inst_JumpF()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   // If there is no label, jump BX steps.
   if (GetLabel().GetSize() == 0) {
@@ -2095,7 +2095,7 @@
 bool cHardwareCPU::Inst_JumpB()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   // If there is no label, jump BX steps.
   if (GetLabel().GetSize() == 0) {
@@ -2135,7 +2135,7 @@
   cHardwareCPU & other_hardware = (cHardwareCPU &) other_organism->GetHardware();
 
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   // If there is no label, jump to line BX in creature.
   if (GetLabel().GetSize() == 0) {
@@ -2164,7 +2164,7 @@
 bool cHardwareCPU::Inst_JumpSelf()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   // If there is no label, jump to line BX in creature.
   if (GetLabel().GetSize() == 0) {
@@ -2193,7 +2193,7 @@
 
   // Jump to the compliment label (or by the ammount in the bx register)
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   if (GetLabel().GetSize() == 0) {
     IP().Jump(Register(REG_BX));
@@ -2328,7 +2328,7 @@
 bool cHardwareCPU::Inst_SetNum()
 {
   ReadLabel();
-  Register(REG_BX) = GetLabel().AsInt();
+  Register(REG_BX) = GetLabel().AsInt(NUM_NOPS);
   return true;
 }
 
@@ -2749,7 +2749,7 @@
   }
 
   // Search for the label in the host...
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   const int inject_signal =
     host_organism->GetHardware().Inject(GetLabel(), inject_code);
@@ -2821,7 +2821,7 @@
   }
 
   // Search for the label in the host...
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
 
   const int inject_signal =
     host_organism->GetHardware().InjectThread(GetLabel(), inject_code);
@@ -2890,7 +2890,7 @@
 bool cHardwareCPU::Inst_SearchF()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   const int search_size = FindLabel(1).GetPosition() - IP().GetPosition();
   Register(REG_BX) = search_size;
   Register(REG_CX) = GetLabel().GetSize();
@@ -2900,7 +2900,7 @@
 bool cHardwareCPU::Inst_SearchB()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   const int search_size = IP().GetPosition() - FindLabel(-1).GetPosition();
   Register(REG_BX) = search_size;
   Register(REG_CX) = GetLabel().GetSize();
@@ -2930,7 +2930,7 @@
   if (!GetLabel().GetSize()) return true;
 
   // Rotate until a complement label is found (or all have been checked).
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism * neighbor = organism->GetNeighbor();
 
@@ -2966,7 +2966,7 @@
   if (!GetLabel().GetSize()) return true;
 
   // Rotate until a complement label is found (or all have been checked).
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism * neighbor = organism->GetNeighbor();
 
@@ -3069,7 +3069,7 @@
 bool cHardwareCPU::Inst_IfLabel()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   if (GetLabel() != GetReadLabel())  IP().Advance();
   return true;
 }
@@ -3248,7 +3248,7 @@
 bool cHardwareCPU::Inst_HeadSearch()
 {
   ReadLabel();
-  GetLabel().Rotate(1);
+  GetLabel().Rotate(1, NUM_NOPS);
   cCPUHead found_pos = FindLabel(0);
   const int search_size = found_pos.GetPosition() - IP().GetPosition();
   Register(REG_BX) = search_size;
Index: avida/current/source/cpu/hardware_cpu.hh
diff -u avida/current/source/cpu/hardware_cpu.hh:1.29 avida/current/source/cpu/hardware_cpu.hh:1.30
--- avida/current/source/cpu/hardware_cpu.hh:1.29	Sun May 25 09:46:30 2003
+++ avida/current/source/cpu/hardware_cpu.hh	Tue May 27 18:08:18 2003
@@ -26,6 +26,8 @@
 class cOrganism;
 class cMutation;
 
+static const int NUM_NOPS = 3;
+
 /**
  * This class is needed to run several threads on a single genome.
  *
Index: avida/current/source/cpu/hardware_util.cc
diff -u avida/current/source/cpu/hardware_util.cc:1.27 avida/current/source/cpu/hardware_util.cc:1.28
--- avida/current/source/cpu/hardware_util.cc:1.27	Mon May 26 00:53:37 2003
+++ avida/current/source/cpu/hardware_util.cc	Tue May 27 18:08:18 2003
@@ -383,15 +383,95 @@
   //  first instructions added to the set.
 #ifndef USE_INST_SET_CODE
   tDictionary< int > nop_dict;
-  nop_dict.Add("nop-A", REG_AX);
-  nop_dict.Add("nop-B", REG_BX);
-  nop_dict.Add("nop-C", REG_CX);
+  //<<<<<<< hardware_util.cc
+  nop_dict.Add("Nop-A", REG_AX);
+  nop_dict.Add("Nop-B", REG_BX);
+  nop_dict.Add("Nop-C", REG_CX);
+  nop_dict.Add("Nop-D", REG_DX);
+  //=======
+  //nop_dict.Add("nop-A", REG_AX);
+  //nop_dict.Add("nop-B", REG_BX);
+  //nop_dict.Add("nop-C", REG_CX);
 #endif /* !USE_INST_SET_CODE */
+  //>>>>>>> 1.25
 
   // Build a dictionary of instructions and their corresponding methods...
 #ifndef USE_INST_SET_CODE
   tDictionary< tHardwareMethod > inst_dict;
-
+  
+  // Remaining instructions.
+  //1
+  //inst_dict.Add("nop-A",     &cHardware4Stack::Inst_Nop), 
+  //2
+  //inst_dict.Add("nop-B",     &cHardware4Stack::Inst_Nop), 
+  //3
+  //inst_dict.Add("nop-C",     &cHardware4Stack::Inst_Nop),   
+  //4 - not implemented yet...
+  //inst_dict.Add("nop-D",     &cHardware4Stack::Inst_Nop), 
+  //5
+  inst_dict.Add("Nop-X", (tHardwareMethod) &cHardware4Stack::Inst_Nop);
+  //6 
+  inst_dict.Add("Val-Shift-R", (tHardwareMethod) &cHardware4Stack::Inst_ShiftR);
+  //7
+  inst_dict.Add("Val-Shift-L", (tHardwareMethod) &cHardware4Stack::Inst_ShiftL);
+  //8
+  inst_dict.Add("Val-Nand",  (tHardwareMethod) &cHardware4Stack::Inst_Nand);
+  //9
+  inst_dict.Add("Val-Add",  (tHardwareMethod) &cHardware4Stack::Inst_Add);
+  //10
+  inst_dict.Add("Val-Sub",  (tHardwareMethod)  &cHardware4Stack::Inst_Sub);
+  //11
+  inst_dict.Add("Val-Mult",  (tHardwareMethod) &cHardware4Stack::Inst_Mult);
+  //12
+  inst_dict.Add("Val-Div",   (tHardwareMethod) &cHardware4Stack::Inst_Div);
+  //13
+  inst_dict.Add("SetMemory", (tHardwareMethod) &cHardware4Stack::Inst_MaxAlloc);
+  //14
+  inst_dict.Add("Divide", (tHardwareMethod) &cHardware4Stack::Inst_HeadDivide);
+  //15
+  inst_dict.Add("Inst-Read", (tHardwareMethod) &cHardware4Stack::Inst_HeadRead);
+  //16
+  inst_dict.Add("Inst-Write", (tHardwareMethod) &cHardware4Stack::Inst_HeadWrite);
+  //keeping this one for the transition period
+  inst_dict.Add("Inst-Copy", (tHardwareMethod) &cHardware4Stack::Inst_HeadCopy);
+  //17
+  inst_dict.Add("If-Equal", (tHardwareMethod) &cHardware4Stack::Inst_IfEqu);
+  //18
+  inst_dict.Add("If-Not-Equal", (tHardwareMethod) &cHardware4Stack::Inst_IfNEqu);
+  //19
+  inst_dict.Add("If-Less", (tHardwareMethod) &cHardware4Stack::Inst_IfLess);
+  //20
+  inst_dict.Add("If-Greater", (tHardwareMethod) &cHardware4Stack::Inst_IfGr);
+  //21
+  inst_dict.Add("Head-Push",  (tHardwareMethod) &cHardware4Stack::Inst_HeadPush);
+  //22
+  inst_dict.Add("Head-Pop",  (tHardwareMethod) &cHardware4Stack::Inst_HeadPop);
+  //23
+  inst_dict.Add("Head-Move", (tHardwareMethod) &cHardware4Stack::Inst_MoveHead);
+  //24
+  inst_dict.Add("Search", (tHardwareMethod) &cHardware4Stack::Inst_HeadSearch);
+  //25
+  inst_dict.Add("Push-Next", (tHardwareMethod) &cHardware4Stack::Inst_PushA);
+  //26
+  inst_dict.Add("Push-Prev", (tHardwareMethod) &cHardware4Stack::Inst_PushB);
+  //27
+  inst_dict.Add("Push-Comp", (tHardwareMethod) &cHardware4Stack::Inst_PushC);
+  //28 - Not implemented yet...
+  //inst_dict.Add("Val-Delete", &cHardware4Stack::Inst_ValDelete
+  //29
+  inst_dict.Add("Val-Copy", (tHardwareMethod) &cHardware4Stack::Inst_CopyReg);
+  //30
+  inst_dict.Add("ThreadFork", (tHardwareMethod) &cHardware4Stack::Inst_ForkThread);
+  //31
+  inst_dict.Add("if-label", (tHardwareMethod) &cHardware4Stack::Inst_IfLabel);
+  //32
+  inst_dict.Add("Val-Inc", (tHardwareMethod) &cHardware4Stack::Inst_Inc);
+  //33
+  inst_dict.Add("Val-Dec", (tHardwareMethod) &cHardware4Stack::Inst_Dec);
+  //34
+  inst_dict.Add("Val-Mod",  (tHardwareMethod) &cHardware4Stack::Inst_Mod);
+  //35
+  inst_dict.Add("ThreadKill", (tHardwareMethod) &cHardware4Stack::Inst_KillThread);/*
   // Remaining instructions.
   inst_dict.Add("nop-X",    (tHardwareMethod) &cHardware4Stack::Inst_Nop);
   inst_dict.Add("if-equ-0", (tHardwareMethod) &cHardware4Stack::Inst_If0);
@@ -592,9 +672,16 @@
   // Placebo instructions
   // nop-x (included with nops)
   inst_dict.Add("skip", (tHardwareMethod) &cHardware4Stack::Inst_Skip);
+<<<<<<< hardware_util.cc
+										*/
+  cout << "BLEE! Instruction Library in util has " << inst_dict.GetSize()
+       << " instructions + " << nop_dict.GetSize() << " nops." << endl;
+
+  //=======
 #endif /* !USE_INST_SET_CODE */
   
 #ifdef USE_INST_SET_CODE
+  //>>>>>>> 1.25
   /* XXX start -- kgn */
   tDictionary<int> nop_dict;
   for(int i=0; i<inst_set.GetInstLib()->GetNumNops(); i++)
@@ -607,7 +694,7 @@
 #endif /* USE_INST_SET_CODE */
 
   cout << "Instruction Library in util has " << inst_dict.GetSize()
-       << " instructions." << endl;
+       << " instructions and " << nop_dict.GetSize() <<  " nops." << endl;
 
 
   // And load it on up!
Index: avida/current/source/cpu/label.cc
diff -u avida/current/source/cpu/label.cc:1.10 avida/current/source/cpu/label.cc:1.11
--- avida/current/source/cpu/label.cc:1.10	Sat May 17 02:48:08 2003
+++ avida/current/source/cpu/label.cc	Tue May 27 18:08:18 2003
@@ -19,16 +19,14 @@
 // cCodeLabel stuff...
 ////////////////////////////////
 
-cCodeLabel::cCodeLabel(int in_base)
+cCodeLabel::cCodeLabel()
   : size(0)
-  , base(in_base)
 {
 }
 
 cCodeLabel::cCodeLabel(const cCodeLabel &in_label)
   : nop_sequence(in_label.nop_sequence)
   , size(in_label.size)
-  , base(in_label.base)
 {
 }
 
@@ -43,7 +41,7 @@
   assert (size <= MAX_LABEL_SIZE);
   assert (size <= nop_sequence.GetSize());
   for (int i = 0; i < size; i++) {
-    assert (nop_sequence[i] < base);
+    assert (nop_sequence[i] < MAX_NOPS);
   }
 
   return result;
Index: avida/current/source/cpu/label.hh
diff -u avida/current/source/cpu/label.hh:1.11 avida/current/source/cpu/label.hh:1.12
--- avida/current/source/cpu/label.hh:1.11	Sat May 17 02:48:08 2003
+++ avida/current/source/cpu/label.hh	Tue May 27 18:08:18 2003
@@ -24,9 +24,9 @@
 private:
   tArray<char> nop_sequence;
   int size;
-  const int base;
+  //const int base;
 public:
-  cCodeLabel(int in_base=MAX_NOPS);
+  cCodeLabel();//int in_base=MAX_NOPS);
   cCodeLabel(const cCodeLabel &in_label);
   ~cCodeLabel();
 
@@ -39,19 +39,19 @@
 
   void Clear() { size = 0; }
   inline void AddNop(int nop_num);
-  inline void Rotate(const int rot);
+  inline void Rotate(const int rot, const int base);
 
   int GetSize() const { return size; }
-  int GetBase() const { return base; }
+  //int GetBase() const { return base; }
   inline cString AsString() const;
-  inline int AsInt() const;
+  inline int AsInt(const int base) const;
 
   void SaveState(std::ostream & fp);
   void LoadState(std::istream & fp);
 };
 
 void cCodeLabel::AddNop(int nop_num) {
-  assert (nop_num < base);
+  assert (nop_num < MAX_NOPS);
 
   if (size < MAX_LABEL_SIZE) {
     if (size == nop_sequence.GetSize()) {
@@ -61,10 +61,16 @@
   }
 }
 
-void cCodeLabel::Rotate(const int rot)
+void cCodeLabel::Rotate(const int rot, const int base)
 {
+  //for (int i = 0; i < size; i++) {
+  //  nop_sequence[i] += rot;
+  //  if (nop_sequence[i] == 3) nop_sequence[i]++; //IGNORING NOP-D FOR NOW!
+  //  if (nop_sequence[i] >= base) nop_sequence[i] -= base;
+  //}
   for (int i = 0; i < size; i++) {
     nop_sequence[i] += rot;
+    //if (nop_sequence[i] == 3) nop_sequence[i]++; //IGNORING NOP-D FOR NOW!
     if (nop_sequence[i] >= base) nop_sequence[i] -= base;
   }
 }
@@ -80,7 +86,7 @@
   return out_string;
 }
 
-int cCodeLabel::AsInt() const
+int cCodeLabel::AsInt(const int base) const
 {
   int value = 0;
 


More information about the Avida-cvs mailing list