[Avida-SVN] r3516 - development/source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Oct 30 09:51:54 PDT 2009
Author: brysonda
Date: 2009-10-30 12:51:53 -0400 (Fri, 30 Oct 2009)
New Revision: 3516
Modified:
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
Log:
Update cHardwareExperimental for phase 2 tests.
New/Renamed Instructions:
search-s
search-f
search-b
search-s-direct
search-f-direct
search-b-direct
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2009-10-30 15:15:04 UTC (rev 3515)
+++ development/source/cpu/cHardwareExperimental.cc 2009-10-30 16:51:53 UTC (rev 3516)
@@ -144,10 +144,12 @@
// Flow Control Instructions
tInstLibEntry<tMethod>("label", &cHardwareExperimental::Inst_Label, (nInstFlag::DEFAULT | nInstFlag::LABEL)),
- tInstLibEntry<tMethod>("h-search", &cHardwareExperimental::Inst_HeadSearch, nInstFlag::DEFAULT, "Find complement template and make with flow head"),
- tInstLibEntry<tMethod>("h-search-nolabel", &cHardwareExperimental::Inst_HeadSearch_NoLabel, 0, "Find complement template and make with flow head"),
- tInstLibEntry<tMethod>("h-search-noreg", &cHardwareExperimental::Inst_HeadSearch_NoReg, 0, "Find complement template and make with flow head"),
- tInstLibEntry<tMethod>("h-search-direct", &cHardwareExperimental::Inst_HeadSearch_Direct, 0, "Find direct template and move the flow head"),
+ tInstLibEntry<tMethod>("search-s", &cHardwareExperimental::Inst_SearchS, nInstFlag::DEFAULT, "Find complement template from genome start and move the flow head"),
+ tInstLibEntry<tMethod>("search-f", &cHardwareExperimental::Inst_SearchF, 0, "Find complement template forward and move the flow head"),
+ tInstLibEntry<tMethod>("search-b", &cHardwareExperimental::Inst_SearchB, 0, "Find complement template backward and move the flow head"),
+ tInstLibEntry<tMethod>("search-s-direct", &cHardwareExperimental::Inst_SearchS_Direct, 0, "Find direct template from genome start and move the flow head"),
+ tInstLibEntry<tMethod>("search-s-direct", &cHardwareExperimental::Inst_SearchF_Direct, 0, "Find direct template forward and move the flow head"),
+ tInstLibEntry<tMethod>("search-s-direct", &cHardwareExperimental::Inst_SearchB_Direct, 0, "Find direct template backward and move the flow head"),
tInstLibEntry<tMethod>("mov-head", &cHardwareExperimental::Inst_MoveHead, nInstFlag::DEFAULT, "Move head ?IP? to the flow head"),
@@ -697,6 +699,57 @@
return ip;
}
+cHeadCPU cHardwareExperimental::FindLabelBackward(bool mark_executed)
+{
+ cHeadCPU& ip = getIP();
+ const cCodeLabel& search_label = GetLabel();
+
+ // Make sure the label is of size > 0.
+ if (search_label.GetSize() == 0) return ip;
+
+ cHeadCPU lpos(ip);
+ cHeadCPU pos(ip);
+ lpos--;
+
+ while (pos.GetPosition() != ip.GetPosition()) {
+ if (m_inst_set->IsLabel(lpos.GetInst())) { // starting label found
+ pos.Set(lpos.GetPosition());
+ pos++;
+
+ // Check for direct matched label pattern, can be substring of 'label'ed target
+ // - must match all NOPs in search_label
+ // - extra NOPs in 'label'ed target are ignored
+ int size_matched = 0;
+ while (size_matched < search_label.GetSize() && pos.GetPosition() != ip.GetPosition()) {
+ if (!m_inst_set->IsNop(pos.GetInst()) || search_label[size_matched] != m_inst_set->GetNopMod(pos.GetInst())) break;
+ size_matched++;
+ pos++;
+ }
+
+ // Check that the label matches and has examined the full sequence of nops following the 'label' instruction
+ if (size_matched == search_label.GetSize()) {
+ pos--;
+ const int found_pos = pos.GetPosition();
+
+ if (mark_executed) {
+ const int max = m_world->GetConfig().MAX_LABEL_EXE_SIZE.Get() + 1; // Max label + 1 for the label instruction itself
+ for (int i = 0; i < size_matched && i < max; i++, lpos++) lpos.SetFlagExecuted();
+ }
+
+ // Return Head pointed at last NOP of label sequence
+ return cHeadCPU(this, found_pos, ip.GetMemSpace());
+ }
+ }
+ lpos--;
+ }
+
+ // Return start point if not found
+ return ip;
+}
+
+
+
+
cHeadCPU cHardwareExperimental::FindNopSequenceForward(bool mark_executed)
{
cHeadCPU& ip = getIP();
@@ -1627,56 +1680,66 @@
return true;
}
-bool cHardwareExperimental::Inst_HeadSearch(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchS(cAvidaContext& ctx)
{
ReadLabel();
GetLabel().Rotate(1, NUM_NOPS);
cHeadCPU found_pos = FindLabelStart(true);
- const int search_size = found_pos.GetPosition() - getIP().GetPosition();
- setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
- setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
getHead(nHardware::HEAD_FLOW).Set(found_pos);
getHead(nHardware::HEAD_FLOW).Advance();
return true;
}
-bool cHardwareExperimental::Inst_HeadSearch_NoLabel(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchS_Direct(cAvidaContext& ctx)
{
ReadLabel();
- GetLabel().Rotate(1, NUM_NOPS);
- cHeadCPU found_pos = FindNopSequenceStart(true);
- const int search_size = found_pos.GetPosition() - getIP().GetPosition();
- setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
- setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
+ cHeadCPU found_pos = FindLabelStart(true);
getHead(nHardware::HEAD_FLOW).Set(found_pos);
getHead(nHardware::HEAD_FLOW).Advance();
return true;
}
-bool cHardwareExperimental::Inst_HeadSearch_NoReg(cAvidaContext& ctx)
+
+bool cHardwareExperimental::Inst_SearchF(cAvidaContext& ctx)
{
ReadLabel();
GetLabel().Rotate(1, NUM_NOPS);
- cHeadCPU found_pos = FindLabelStart(true);
+ cHeadCPU found_pos = FindLabelForward(true);
getHead(nHardware::HEAD_FLOW).Set(found_pos);
getHead(nHardware::HEAD_FLOW).Advance();
return true;
}
-bool cHardwareExperimental::Inst_HeadSearch_Direct(cAvidaContext& ctx)
+bool cHardwareExperimental::Inst_SearchF_Direct(cAvidaContext& ctx)
{
ReadLabel();
cHeadCPU found_pos = FindLabelForward(true);
- const int search_size = found_pos.GetPosition() - getIP().GetPosition();
- setInternalValue(m_threads[m_cur_thread].reg[REG_BX], search_size);
- setInternalValue(m_threads[m_cur_thread].reg[REG_CX], GetLabel().GetSize());
getHead(nHardware::HEAD_FLOW).Set(found_pos);
getHead(nHardware::HEAD_FLOW).Advance();
return true;
}
+bool cHardwareExperimental::Inst_SearchB(cAvidaContext& ctx)
+{
+ ReadLabel();
+ GetLabel().Rotate(1, NUM_NOPS);
+ cHeadCPU found_pos = FindLabelBackward(true);
+ getHead(nHardware::HEAD_FLOW).Set(found_pos);
+ getHead(nHardware::HEAD_FLOW).Advance();
+ return true;
+}
+bool cHardwareExperimental::Inst_SearchB_Direct(cAvidaContext& ctx)
+{
+ ReadLabel();
+ cHeadCPU found_pos = FindLabelBackward(true);
+ getHead(nHardware::HEAD_FLOW).Set(found_pos);
+ getHead(nHardware::HEAD_FLOW).Advance();
+ return true;
+}
+
+
bool cHardwareExperimental::Inst_SetFlow(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_CX);
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2009-10-30 15:15:04 UTC (rev 3515)
+++ development/source/cpu/cHardwareExperimental.h 2009-10-30 16:51:53 UTC (rev 3516)
@@ -329,6 +329,7 @@
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabelStart(bool mark_executed);
cHeadCPU FindLabelForward(bool mark_executed);
+ cHeadCPU FindLabelBackward(bool mark_executed);
cHeadCPU FindNopSequenceStart(bool mark_executed);
cHeadCPU FindNopSequenceForward(bool mark_executed);
bool& ReadingLabel() { return m_threads[m_cur_thread].reading; }
@@ -444,10 +445,12 @@
bool Inst_HeadWrite(cAvidaContext& ctx);
bool Inst_HeadCopy(cAvidaContext& ctx);
bool Inst_HeadCopy_NoLabel(cAvidaContext& ctx);
- bool Inst_HeadSearch(cAvidaContext& ctx);
- bool Inst_HeadSearch_NoLabel(cAvidaContext& ctx);
- bool Inst_HeadSearch_NoReg(cAvidaContext& ctx);
- bool Inst_HeadSearch_Direct(cAvidaContext& ctx);
+ bool Inst_SearchS(cAvidaContext& ctx);
+ bool Inst_SearchS_Direct(cAvidaContext& ctx);
+ bool Inst_SearchF(cAvidaContext& ctx);
+ bool Inst_SearchF_Direct(cAvidaContext& ctx);
+ bool Inst_SearchB(cAvidaContext& ctx);
+ bool Inst_SearchB_Direct(cAvidaContext& ctx);
bool Inst_SetFlow(cAvidaContext& ctx);
// Goto Variants
More information about the Avida-cvs
mailing list