[Avida-SVN] r1357 - in development: source/cpu support/config
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Feb 20 16:37:47 PST 2007
Author: brysonda
Date: 2007-02-20 19:37:47 -0500 (Tue, 20 Feb 2007)
New Revision: 1357
Modified:
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
development/source/cpu/cInstSet.h
development/support/config/experimental.org
development/support/config/instset-experimental.cfg
Log:
Adjust ReadLabel behavior of cHardwareExperimental to honor only 'label'ed targets. Adjust default org and instset for experimental to match new behavior.
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2007-02-20 19:36:50 UTC (rev 1356)
+++ development/source/cpu/cHardwareExperimental.cc 2007-02-21 00:37:47 UTC (rev 1357)
@@ -89,7 +89,7 @@
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>("label", &cHardwareExperimental::Inst_Label),
+ tInstLibEntry<tMethod>("label", &cHardwareExperimental::Inst_Label, (nInstFlag::DEFAULT | nInstFlag::LABEL)),
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"),
@@ -450,25 +450,21 @@
int pos = 0;
while (pos < memory.GetSize()) {
- if (pos == start) { // skip past initiating instruction and label argument
- pos += search_label.GetSize() + 1;
- continue;
- }
-
if (m_inst_set->IsLabel(memory[pos])) { // starting label found
- int label = pos;
pos++;
- // Check for direct matched label pattern
+ // 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 < memory.GetSize()) {
- if (!m_inst_set->IsNop(memory[pos]) || !search_label[size_matched] != m_inst_set->GetNopMod(memory[pos])) break;
+ if (!m_inst_set->IsNop(memory[pos]) || search_label[size_matched] != m_inst_set->GetNopMod(memory[pos])) 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 == memory.GetSize() || !m_inst_set->IsNop(memory[pos]))) {
+ if (size_matched == search_label.GetSize()) {
// Return Head pointed at last NOP of label sequence
return cHeadCPU(this, pos - 1, ip.GetMemSpace());
}
@@ -526,10 +522,14 @@
void cHardwareExperimental::ReadInst(const int in_inst)
{
- if (m_inst_set->IsNop( cInstruction(in_inst) )) {
+ if (m_inst_set->IsLabel(cInstruction(in_inst))) {
+ GetReadLabel().Clear();
+ ReadingLabel() = true;
+ } else if (ReadingLabel() && m_inst_set->IsNop(cInstruction(in_inst))) {
GetReadLabel().AddNop(in_inst);
} else {
GetReadLabel().Clear();
+ ReadingLabel() = false;
}
}
@@ -846,6 +846,13 @@
return true;
}
+bool cHardwareExperimental::Inst_Label(cAvidaContext& ctx)
+{
+ ReadLabel();
+ return true;
+};
+
+
bool cHardwareExperimental::Inst_Pop(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_BX);
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2007-02-20 19:36:50 UTC (rev 1356)
+++ development/source/cpu/cHardwareExperimental.h 2007-02-21 00:37:47 UTC (rev 1357)
@@ -101,10 +101,10 @@
unsigned char cur_stack; // 0 = local stack, 1 = global stack.
unsigned char cur_head;
+ bool reading;
cCodeLabel read_label;
- cCodeLabel next_label;
+ cCodeLabel next_label;
-
cLocalThread(cHardwareBase* in_hardware = NULL, int in_id = -1) { Reset(in_hardware, in_id); }
~cLocalThread() { ; }
@@ -164,6 +164,7 @@
cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabelStart();
+ bool& ReadingLabel() { return m_threads[m_cur_thread].reading; }
const cCodeLabel& GetReadLabel() const { return m_threads[m_cur_thread].read_label; }
cCodeLabel& GetReadLabel() { return m_threads[m_cur_thread].read_label; }
@@ -276,7 +277,7 @@
// Flow Control
bool Inst_IfNEqu(cAvidaContext& ctx);
bool Inst_IfLess(cAvidaContext& ctx);
- bool Inst_Label(cAvidaContext& ctx) { ReadLabel(); return true; };
+ bool Inst_Label(cAvidaContext& ctx);
// Stack and Register Operations
bool Inst_Pop(cAvidaContext& ctx);
Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h 2007-02-20 19:36:50 UTC (rev 1356)
+++ development/source/cpu/cInstSet.h 2007-02-21 00:37:47 UTC (rev 1357)
@@ -112,7 +112,7 @@
// Instruction Analysis.
int IsNop(const cInstruction& inst) const { return (inst.GetOp() < m_lib_nopmod_map.GetSize()); }
- int IsLabel(const cInstruction& inst) const { return m_inst_lib->Get(inst.GetOp()).IsLabel(); }
+ int IsLabel(const cInstruction& inst) const { return m_inst_lib->Get(GetLibFunctionIndex(inst)).IsLabel(); }
// Insertion of new instructions...
int AddInst(int lib_fun_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
Modified: development/support/config/experimental.org
===================================================================
--- development/support/config/experimental.org 2007-02-20 19:36:50 UTC (rev 1356)
+++ development/support/config/experimental.org 2007-02-21 00:37:47 UTC (rev 1357)
@@ -86,7 +86,6 @@
nop-C #
nop-C #
nop-C #
-nop-C #
h-search # Mark the beginning of the copy loop
h-copy # Do the copy
if-label # If we're done copying....
@@ -96,5 +95,6 @@
mov-head # Otherwise, loop back to the beginning of the copy loop.
nop-A #
add # neutral separator (terminates mov-head)
+label
nop-A # End Label
nop-B #
Modified: development/support/config/instset-experimental.cfg
===================================================================
--- development/support/config/instset-experimental.cfg 2007-02-20 19:36:50 UTC (rev 1356)
+++ development/support/config/instset-experimental.cfg 2007-02-21 00:37:47 UTC (rev 1357)
@@ -1,31 +1,32 @@
nop-A 1 # a
nop-B 1 # b
nop-C 1 # c
-nop-D 1 # c
-if-n-equ 1 # d
-if-less 1 # e
-pop 1 # f
-push 1 # g
-swap-stk 1 # h
-swap 1 # i
-shift-r 1 # j
-shift-l 1 # k
-inc 1 # l
-dec 1 # m
-add 1 # n
-sub 1 # o
-nand 1 # p
-IO 1 # q Puts current contents of register and gets new.
-h-alloc 1 # r Allocate as much memory as organism can use.
-h-divide 1 # s Cuts off everything between the read and write heads
-h-copy 1 # t Combine h-read and h-write
-h-search 1 # u Search for matching template, set flow head & return info
+nop-D 1 # d
+if-n-equ 1 # e
+if-less 1 # f
+pop 1 # g
+push 1 # h
+swap-stk 1 # i
+swap 1 # j
+shift-r 1 # k
+shift-l 1 # l
+inc 1 # m
+dec 1 # n
+add 1 # o
+sub 1 # p
+nand 1 # q
+IO 1 # r Puts current contents of register and gets new.
+h-alloc 1 # s Allocate as much memory as organism can use.
+h-divide 1 # t Cuts off everything between the read and write heads
+h-copy 1 # u Combine h-read and h-write
+h-search 1 # v Search for matching template, set flow head & return info
# # if no template, move flow-head here, set size&offset=0.
-mov-head 1 # v Move ?IP? head to flow control.
-jmp-head 1 # w Move ?IP? head by fixed amount in CX. Set old pos in CX.
-get-head 1 # x Get position of specified head in CX.
-if-label 1 # y
-set-flow 1 # z Move flow-head to address in ?CX?
+mov-head 1 # w Move ?IP? head to flow control.
+jmp-head 1 # x Move ?IP? head by fixed amount in CX. Set old pos in CX.
+get-head 1 # y Get position of specified head in CX.
+if-label 1 # z
+set-flow 1 # A Move flow-head to address in ?CX?
+label 1 # B delineate labeled regions of the genome
#adv-head 1
#jump-f 1
More information about the Avida-cvs
mailing list