[Avida-cvs] [avida-svn] r841 - in development/source: cpu main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Jul 17 13:40:01 PDT 2006
Author: brysonda
Date: 2006-07-17 16:40:00 -0400 (Mon, 17 Jul 2006)
New Revision: 841
Modified:
development/source/cpu/cHardwareBase.cc
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cHardwareTransSMT.cc
development/source/cpu/cHardwareTransSMT.h
development/source/cpu/cHeadCPU.h
development/source/main/cInstSet.h
Log:
Comment out and remove old jump instructions that require cross-hardware head support. Fix and rename cHardwareCPU::FindFullLabel to cHardwareBase::FindLabelFull. Was broken such that it would *never* find the desired nop label. Fixed this and lowered into the base class, as it is hardware agnostic and does not need three identical private implementations.
Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareBase.cc 2006-07-17 20:40:00 UTC (rev 841)
@@ -453,6 +453,55 @@
}
+cHeadCPU cHardwareBase::FindLabelFull(const cCodeLabel& label)
+{
+ assert(label.GetSize() > 0); // Trying to find label of 0 size!
+
+ cHeadCPU temp_head(this);
+
+ while (temp_head.InMemory()) {
+ // If we are not in a label, jump to the next checkpoint...
+ if (!m_inst_set->IsNop(temp_head.GetInst())) {
+ temp_head.AbsJump(label.GetSize());
+ continue;
+ }
+
+ // Otherwise, rewind to the begining of this label...
+
+ while (!(temp_head.AtFront()) && m_inst_set->IsNop(temp_head.GetInst(-1)))
+ temp_head.AbsJump(-1);
+
+ // Calculate the size of the label being checked, and make sure they
+ // are equal.
+
+ int size = 0;
+ bool label_match = true;
+ do {
+ // Check if the nop matches
+ if (size < label.GetSize() && label[size] != m_inst_set->GetNopMod(temp_head.GetInst()))
+ label_match = false;
+
+ // Increment the current position and length calculation
+ temp_head.AbsJump(1);
+ size++;
+
+ // While still within memory and the instruction is a nop
+ } while (temp_head.InMemory() && m_inst_set->IsNop(temp_head.GetInst()));
+
+ if (size != label.GetSize()) continue;
+
+ // temp_head will point to the first non-nop instruction after the label, or the end of the memory space
+ // if this is a match, return this position
+ if (label_match) return temp_head;
+ }
+
+ // The label does not exist in this creature.
+
+ temp_head.AbsSet(-1);
+ return temp_head;
+}
+
+
bool cHardwareBase::Inst_Nop(cAvidaContext& ctx) // Do Nothing.
{
return true;
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareBase.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -101,7 +101,9 @@
virtual const cHeadCPU& IP(int thread) const = 0;
virtual cHeadCPU& IP(int thread) = 0;
+ cHeadCPU FindLabelFull(const cCodeLabel& label);
+
// -------- Label Manipulation -------
virtual const cCodeLabel& GetLabel() const = 0;
virtual cCodeLabel& GetLabel() = 0;
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareCPU.cc 2006-07-17 20:40:00 UTC (rev 841)
@@ -109,8 +109,6 @@
cInstEntryCPU("jump-f", &cHardwareCPU::Inst_JumpF),
cInstEntryCPU("jump-b", &cHardwareCPU::Inst_JumpB),
- cInstEntryCPU("jump-p", &cHardwareCPU::Inst_JumpP),
- cInstEntryCPU("jump-slf", &cHardwareCPU::Inst_JumpSelf),
cInstEntryCPU("call", &cHardwareCPU::Inst_Call),
cInstEntryCPU("return", &cHardwareCPU::Inst_Return),
@@ -872,69 +870,7 @@
return temp_head;
}
-// @CAO: direction is not currently used; should be used to indicate the
-// direction which the heads[nHardware::HEAD_IP] should progress through a creature.
-cHeadCPU cHardwareCPU::FindFullLabel(const cCodeLabel & in_label)
-{
- assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
-
- cHeadCPU temp_head(this);
-
- while (temp_head.InMemory()) {
- // If we are not in a label, jump to the next checkpoint...
- if (m_inst_set->IsNop(temp_head.GetInst())) {
- temp_head.AbsJump(in_label.GetSize());
- continue;
- }
-
- // Otherwise, rewind to the begining of this label...
-
- while (!(temp_head.AtFront()) && m_inst_set->IsNop(temp_head.GetInst(-1)))
- temp_head.AbsJump(-1);
-
- // Calculate the size of the label being checked, and make sure they
- // are equal.
-
- int checked_size = 0;
- while (m_inst_set->IsNop(temp_head.GetInst(checked_size))) {
- checked_size++;
- }
- if (checked_size != in_label.GetSize()) {
- temp_head.AbsJump(checked_size + 1);
- continue;
- }
-
- // ...and do the comparison...
-
- int j;
- bool label_match = true;
- for (j = 0; j < in_label.GetSize(); j++) {
- if (!m_inst_set->IsNop(temp_head.GetInst(j)) ||
- in_label[j] != m_inst_set->GetNopMod(temp_head.GetInst(j))) {
- temp_head.AbsJump(in_label.GetSize() + 1);
- label_match = false;
- break;
- }
- }
-
- if (label_match) {
- // If we have found the label, return the position after it.
- temp_head.AbsJump(j - 1);
- return temp_head;
- }
-
- // We have not found the label... increment i.
-
- temp_head.AbsJump(in_label.GetSize() + 1);
- }
-
- // The label does not exist in this creature.
-
- temp_head.AbsSet(-1);
- return temp_head;
-}
-
bool cHardwareCPU::InjectHost(const cCodeLabel & in_label, const cGenome & injection)
{
// Make sure the genome will be below max size after injection.
@@ -942,7 +878,7 @@
const int new_size = injection.GetSize() + GetMemory().GetSize();
if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
- const int inject_line = FindFullLabel(in_label).GetPosition();
+ const int inject_line = FindLabelFull(in_label).GetPosition();
// Abort if no compliment is found.
if (inject_line == -1) return false; // (inject fails)
@@ -1503,74 +1439,78 @@
return false;
}
-bool cHardwareCPU::Inst_JumpP(cAvidaContext& ctx)
-{
- cOrganism * other_organism = organism->GetNeighbor();
-
- // Make sure the other organism was found and that its hardware is of the
- // same type, or else we won't be able to be parasitic on it.
- if (other_organism == NULL ||
- other_organism->GetHardware().GetType() != GetType()) {
- // Without another organism, its hard to determine if we're dealing
- // with a parasite. For the moment, we'll assume it is and move on.
- // @CAO Do better!
- organism->GetPhenotype().IsParasite() = true;
- return true;
- }
-
- // Otherwise, grab the hardware from the neighbor, and use it!
- cHardwareCPU & other_hardware = (cHardwareCPU &) other_organism->GetHardware();
-
- ReadLabel();
- GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
-
- // If there is no label, jump to line BX in creature.
- if (GetLabel().GetSize() == 0) {
- const int new_pos = GetRegister(nHardwareCPU::REG_BX);
- IP().Set(new_pos);
- organism->GetPhenotype().IsParasite() = true;
- return true;
- }
-
- // otherwise jump to the complement label.
- const cHeadCPU jump_location(other_hardware.FindFullLabel(GetLabel()));
- if (jump_location.GetPosition() != -1) {
- IP().Set(jump_location);
- organism->GetPhenotype().IsParasite() = true;
- return true;
- }
-
- // If complement label was not found; record a warning (since the
- // actual neighbors are not under the organisms control, this is not
- // a full-scale error).
- organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_WARNING,
- "jump-p: No complement label");
- return false;
-}
+// @DMB - this will not function (as intended) without cross-hardware head support
+//
+//bool cHardwareCPU::Inst_JumpP(cAvidaContext& ctx)
+//{
+// cOrganism * other_organism = organism->GetNeighbor();
+//
+// // Make sure the other organism was found and that its hardware is of the
+// // same type, or else we won't be able to be parasitic on it.
+// if (other_organism == NULL ||
+// other_organism->GetHardware().GetType() != GetType()) {
+// // Without another organism, its hard to determine if we're dealing
+// // with a parasite. For the moment, we'll assume it is and move on.
+// // @CAO Do better!
+// organism->GetPhenotype().IsParasite() = true;
+// return true;
+// }
+//
+// // Otherwise, grab the hardware from the neighbor, and use it!
+// cHardwareCPU & other_hardware = (cHardwareCPU &) other_organism->GetHardware();
+//
+// ReadLabel();
+// GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
+//
+// // If there is no label, jump to line BX in creature.
+// if (GetLabel().GetSize() == 0) {
+// const int new_pos = GetRegister(nHardwareCPU::REG_BX);
+// IP().Set(new_pos);
+// organism->GetPhenotype().IsParasite() = true;
+// return true;
+// }
+//
+// // otherwise jump to the complement label.
+// const cHeadCPU jump_location(other_hardware.FindFullLabel(GetLabel()));
+// if (jump_location.GetPosition() != -1) {
+// IP().Set(jump_location);
+// organism->GetPhenotype().IsParasite() = true;
+// return true;
+// }
+//
+// // If complement label was not found; record a warning (since the
+// // actual neighbors are not under the organisms control, this is not
+// // a full-scale error).
+// organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_WARNING,
+// "jump-p: No complement label");
+// return false;
+//}
-bool cHardwareCPU::Inst_JumpSelf(cAvidaContext& ctx)
-{
- ReadLabel();
- GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
-
- // If there is no label, jump to line BX in creature.
- if (GetLabel().GetSize() == 0) {
- IP().Set(GetRegister(nHardwareCPU::REG_BX));
- return true;
- }
-
- // otherwise jump to the complement label.
- const cHeadCPU jump_location( FindFullLabel(GetLabel()) );
- if ( jump_location.GetPosition() != -1 ) {
- IP().Set(jump_location);
- return true;
- }
-
- // If complement label was not found; record an error.
- organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
- "jump-slf: no complement label");
- return false;
-}
+// @DMB - this is unnecessary without Inst_JumpP
+//
+//bool cHardwareCPU::Inst_JumpSelf(cAvidaContext& ctx)
+//{
+// ReadLabel();
+// GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
+//
+// // If there is no label, jump to line BX in creature.
+// if (GetLabel().GetSize() == 0) {
+// IP().Set(GetRegister(nHardwareCPU::REG_BX));
+// return true;
+// }
+//
+// // otherwise jump to the complement label.
+// const cHeadCPU jump_location( FindFullLabel(GetLabel()) );
+// if ( jump_location.GetPosition() != -1 ) {
+// IP().Set(jump_location);
+// return true;
+// }
+//
+// // If complement label was not found; record an error.
+// organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
+// "jump-slf: no complement label");
+// return false;
+//}
bool cHardwareCPU::Inst_Call(cAvidaContext& ctx)
{
@@ -2589,18 +2529,9 @@
// Rotate until a complement label is found (or all have been checked).
GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
for (int i = 1; i < num_neighbors; i++) {
- cOrganism * neighbor = organism->GetNeighbor();
+ cOrganism* neighbor = organism->GetNeighbor();
- // Assuming we have a neighbor and it is of the same hardware type,
- // search for the label in it.
- if (neighbor != NULL &&
- neighbor->GetHardware().GetType() == GetType()) {
-
- // If this facing has the full label, stop here.
- // @DMB - Warning: this is assuming homogenous hardware within the population
- cHardwareCPU & cur_hardware = static_cast<cHardwareCPU&>(neighbor->GetHardware());
- if (cur_hardware.FindFullLabel( GetLabel() ).InMemory()) return true;
- }
+ if (neighbor != NULL && neighbor->FindLabelFull(GetLabel()).InMemory()) return true;
// Otherwise keep rotating...
organism->Rotate(-1);
@@ -2626,17 +2557,9 @@
// Rotate until a complement label is found (or all have been checked).
GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
for (int i = 1; i < num_neighbors; i++) {
- cOrganism * neighbor = organism->GetNeighbor();
+ cOrganism* neighbor = organism->GetNeighbor();
- // Assuming we have a neighbor and it is of the same hardware type,
- // search for the label in it.
- if (neighbor != NULL &&
- neighbor->GetHardware().GetType() == GetType()) {
-
- // If this facing has the full label, stop here.
- cHardwareCPU & cur_hardware = (cHardwareCPU &) neighbor->GetHardware();
- if (cur_hardware.FindFullLabel( GetLabel() ).InMemory()) return true;
- }
+ if (neighbor != NULL && neighbor->FindLabelFull(GetLabel()).InMemory()) return true;
// Otherwise keep rotating...
organism->Rotate(1);
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareCPU.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -118,7 +118,6 @@
int FindLabel_Forward(const cCodeLabel & search_label, const cGenome& search_genome, int pos);
int FindLabel_Backward(const cCodeLabel & search_label, const cGenome& search_genome, int pos);
cHeadCPU FindLabel(const cCodeLabel & in_label, int direction);
- cHeadCPU FindFullLabel(const cCodeLabel & in_label);
const cCodeLabel& GetReadLabel() const { return threads[cur_thread].read_label; }
cCodeLabel& GetReadLabel() { return threads[cur_thread].read_label; }
@@ -254,8 +253,6 @@
bool Inst_JumpF(cAvidaContext& ctx);
bool Inst_JumpB(cAvidaContext& ctx);
- bool Inst_JumpP(cAvidaContext& ctx);
- bool Inst_JumpSelf(cAvidaContext& ctx);
bool Inst_Call(cAvidaContext& ctx);
bool Inst_Return(cAvidaContext& ctx);
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareSMT.cc 2006-07-17 20:40:00 UTC (rev 841)
@@ -400,14 +400,9 @@
}
-/////////////////////////////////////////////////////////////////////////
-// Method: cHardwareSMT::FindLabel(direction)
-//
// Search in 'direction' (+ or - 1) from the instruction pointer for the
// compliment of the label in 'next_label' and return a pointer to the
// results. If direction is 0, search from the beginning of the genome.
-//
-/////////////////////////////////////////////////////////////////////////
cHeadCPU cHardwareSMT::FindLabel(int direction)
{
cHeadCPU& inst_ptr = IP();
@@ -641,65 +636,6 @@
return temp_head;
}
-// @CAO: direction is not currently used; should be used to indicate the
-// direction which the heads[nHardware::HEAD_IP] should progress through a creature.
-cHeadCPU cHardwareSMT::FindFullLabel(const cCodeLabel & in_label)
-{
- assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
-
- cHeadCPU temp_head(this);
-
- while (temp_head.InMemory()) {
- // If we are not in a label, jump to the next checkpoint...
- if (m_inst_set->IsNop(temp_head.GetInst())) {
- temp_head.AbsJump(in_label.GetSize());
- continue;
- }
-
- // Otherwise, rewind to the begining of this label...
- while (!(temp_head.AtFront()) && m_inst_set->IsNop(temp_head.GetInst(-1)))
- temp_head.AbsJump(-1);
-
- // Calculate the size of the label being checked, and make sure they
- // are equal.
- int checked_size = 0;
- while (m_inst_set->IsNop(temp_head.GetInst(checked_size))) {
- checked_size++;
- }
- if (checked_size != in_label.GetSize()) {
- temp_head.AbsJump(checked_size + 1);
- continue;
- }
-
- // ...and do the comparison...
- int j;
- bool label_match = true;
- for (j = 0; j < in_label.GetSize(); j++) {
- if (!m_inst_set->IsNop(temp_head.GetInst(j)) ||
- in_label[j] != m_inst_set->GetNopMod(temp_head.GetInst(j))) {
- temp_head.AbsJump(in_label.GetSize() + 1);
- label_match = false;
- break;
- }
- }
-
- if (label_match) {
- // If we have found the label, return the position after it.
- temp_head.AbsJump(j - 1);
- return temp_head;
- }
-
- // We have not found the label... increment i.
-
- temp_head.AbsJump(in_label.GetSize() + 1);
- }
-
- // The label does not exist in this creature.
-
- temp_head.AbsSet(-1);
- return temp_head;
-}
-
// This is the code run by the INFECTED organism. Its function is to SPREAD infection.
bool cHardwareSMT::InjectParasite(cAvidaContext& ctx, double mut_multiplier)
{
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareSMT.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -148,7 +148,6 @@
int FindLabel_Forward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
int FindLabel_Backward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
cHeadCPU FindLabel(const cCodeLabel& in_label, int direction);
- cHeadCPU FindFullLabel(const cCodeLabel& in_label);
const cCodeLabel& GetReadLabel() const { return m_threads[m_cur_thread].read_label; }
cCodeLabel& GetReadLabel() { return m_threads[m_cur_thread].read_label; }
Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareTransSMT.cc 2006-07-17 20:40:00 UTC (rev 841)
@@ -638,65 +638,7 @@
return temp_head;
}
-// @CAO: direction is not currently used; should be used to indicate the
-// direction which the heads[nHardware::HEAD_IP] should progress through a creature.
-cHeadCPU cHardwareTransSMT::FindFullLabel(const cCodeLabel & in_label)
-{
- assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
-
- cHeadCPU temp_head(this);
-
- while (temp_head.InMemory()) {
- // If we are not in a label, jump to the next checkpoint...
- if (m_inst_set->IsNop(temp_head.GetInst())) {
- temp_head.AbsJump(in_label.GetSize());
- continue;
- }
-
- // Otherwise, rewind to the begining of this label...
- while (!(temp_head.AtFront()) && m_inst_set->IsNop(temp_head.GetInst(-1)))
- temp_head.AbsJump(-1);
-
- // Calculate the size of the label being checked, and make sure they
- // are equal.
- int checked_size = 0;
- while (m_inst_set->IsNop(temp_head.GetInst(checked_size))) {
- checked_size++;
- }
- if (checked_size != in_label.GetSize()) {
- temp_head.AbsJump(checked_size + 1);
- continue;
- }
- // ...and do the comparison...
- int j;
- bool label_match = true;
- for (j = 0; j < in_label.GetSize(); j++) {
- if (!m_inst_set->IsNop(temp_head.GetInst(j)) ||
- in_label[j] != m_inst_set->GetNopMod(temp_head.GetInst(j))) {
- temp_head.AbsJump(in_label.GetSize() + 1);
- label_match = false;
- break;
- }
- }
-
- if (label_match) {
- // If we have found the label, return the position after it.
- temp_head.AbsJump(j - 1);
- return temp_head;
- }
-
- // We have not found the label... increment i.
-
- temp_head.AbsJump(in_label.GetSize() + 1);
- }
-
- // The label does not exist in this creature.
-
- temp_head.AbsSet(-1);
- return temp_head;
-}
-
// This is the code run by the INFECTED organism. Its function is to SPREAD infection.
bool cHardwareTransSMT::InjectParasite(cAvidaContext& ctx, double mut_multiplier)
{
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHardwareTransSMT.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -147,7 +147,6 @@
int FindLabel_Forward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
int FindLabel_Backward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
cHeadCPU FindLabel(const cCodeLabel& in_label, int direction);
- cHeadCPU FindFullLabel(const cCodeLabel& in_label);
const cCodeLabel& GetReadLabel() const { return m_threads[m_cur_thread].read_label; }
cCodeLabel& GetReadLabel() { return m_threads[m_cur_thread].read_label; }
Modified: development/source/cpu/cHeadCPU.h
===================================================================
--- development/source/cpu/cHeadCPU.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/cpu/cHeadCPU.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -112,7 +112,7 @@
inline cHeadCPU::cHeadCPU(cHardwareBase* hw, int pos, int ms) : m_hardware(hw), m_position(pos), m_mem_space(ms)
{
- if (pos) Adjust();
+ if (pos || ms) Adjust();
}
inline cHeadCPU::cHeadCPU(const cHeadCPU& in_cpu_head)
Modified: development/source/main/cInstSet.h
===================================================================
--- development/source/main/cInstSet.h 2006-07-17 20:39:15 UTC (rev 840)
+++ development/source/main/cInstSet.h 2006-07-17 20:40:00 UTC (rev 841)
@@ -82,7 +82,7 @@
int GetRedundancy(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].redundancy; }
int GetLibFunctionIndex(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].lib_fun_id; }
- int GetNopMod(const cInstruction & inst) const
+ int GetNopMod(const cInstruction& inst) const
{
int nopmod = m_lib_nopmod_map[inst.GetOp()];
return m_inst_lib->GetNopMod(nopmod);
More information about the Avida-cvs
mailing list