[Avida-cvs] [avida-svn] r838 - in development/source: cpu main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sat Jul 15 14:37:38 PDT 2006
Author: brysonda
Date: 2006-07-15 17:37:38 -0400 (Sat, 15 Jul 2006)
New Revision: 838
Modified:
development/source/cpu/cCPUStack.h
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cHardwareTransSMT.h
development/source/cpu/cHeadCPU.cc
development/source/cpu/cHeadCPU.h
development/source/main/cInstSet.cc
development/source/main/cInstSet.h
Log:
Update the core SMT instruction behaviors. Stub in various new instructions.
Modified: development/source/cpu/cCPUStack.h
===================================================================
--- development/source/cpu/cCPUStack.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cCPUStack.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -83,7 +83,7 @@
inline void cCPUStack::Clear()
{
- for (int i =0; i < nHardware::STACK_SIZE; i++) { stack[i] = 0; }
+ for (int i = 0; i < nHardware::STACK_SIZE; i++) stack[i] = 0;
stack_pointer = 0;
}
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHardwareBase.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -112,6 +112,7 @@
virtual cCPUMemory& GetMemory() = 0;
virtual const cCPUMemory& GetMemory(int value) const = 0;
virtual cCPUMemory& GetMemory(int value) = 0;
+ virtual int GetNumMemSpaces() const = 0;
// -------- Register Manipulation --------
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHardwareCPU.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -200,6 +200,7 @@
cCPUMemory& GetMemory() { return memory; }
const cCPUMemory& GetMemory(int value) const { return memory; }
cCPUMemory& GetMemory(int value) { return memory; }
+ int GetNumMemSpaces() const { return 1; }
// -------- Register Manipulation --------
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHardwareSMT.cc 2006-07-15 21:37:38 UTC (rev 838)
@@ -51,54 +51,55 @@
tMethod function;
};
static const cInstEntry s_f_array[] = {
- cInstEntry("Nop-A", &cHardwareSMT::Inst_Nop), // 1
- cInstEntry("Nop-B", &cHardwareSMT::Inst_Nop), // 2
- cInstEntry("Nop-C", &cHardwareSMT::Inst_Nop), // 3
- cInstEntry("Nop-D", &cHardwareSMT::Inst_Nop), // 4
- cInstEntry("Nop-X", &cHardwareSMT::Inst_Nop), // 5
- cInstEntry("Val-Shift-R", &cHardwareSMT::Inst_ShiftR), // 6
- cInstEntry("Val-Shift-L", &cHardwareSMT::Inst_ShiftL), // 7
- cInstEntry("Val-Nand", &cHardwareSMT::Inst_Val_Nand), // 8
- cInstEntry("Val-Add", &cHardwareSMT::Inst_Val_Add), // 9
- cInstEntry("Val-Sub", &cHardwareSMT::Inst_Val_Sub), // 10
- cInstEntry("Val-Mult", &cHardwareSMT::Inst_Val_Mult), // 11
- cInstEntry("Val-Div", &cHardwareSMT::Inst_Val_Div), // 12
- cInstEntry("Val-Mod", &cHardwareSMT::Inst_Val_Mod), // 13
- cInstEntry("Val-Inc", &cHardwareSMT::Inst_Val_Inc), // 14
- cInstEntry("Val-Dec", &cHardwareSMT::Inst_Val_Dec), // 15
- cInstEntry("SetMemory", &cHardwareSMT::Inst_SetMemory), // 16
- cInstEntry("Divide", &cHardwareSMT::Inst_Divide), // 17
- cInstEntry("Inst-Read", &cHardwareSMT::Inst_HeadRead), // 18
- cInstEntry("Inst-Write", &cHardwareSMT::Inst_HeadWrite), // 19
- cInstEntry("If-Equal", &cHardwareSMT::Inst_IfEqual), // 20
- cInstEntry("If-Not-Equal", &cHardwareSMT::Inst_IfNotEqual), // 21
- cInstEntry("If-Less", &cHardwareSMT::Inst_IfLess), // 22
- cInstEntry("If-Greater", &cHardwareSMT::Inst_IfGreater), // 23
- cInstEntry("Head-Push", &cHardwareSMT::Inst_HeadPush), // 24
- cInstEntry("Head-Pop", &cHardwareSMT::Inst_HeadPop), // 25
- cInstEntry("Head-Move", &cHardwareSMT::Inst_HeadMove), // 26
- cInstEntry("Search", &cHardwareSMT::Inst_Search), // 27
- cInstEntry("Push-Next", &cHardwareSMT::Inst_PushNext), // 28
- cInstEntry("Push-Prev", &cHardwareSMT::Inst_PushPrevious), // 29
- cInstEntry("Push-Comp", &cHardwareSMT::Inst_PushComplement), // 30
- cInstEntry("Val-Delete", &cHardwareSMT::Inst_ValDelete), // 31
- cInstEntry("Val-Copy", &cHardwareSMT::Inst_ValCopy), // 32
- cInstEntry("IO", &cHardwareSMT::Inst_IO), // 33
- cInstEntry("Thread-Create", &cHardwareSMT::Inst_ThreadCreate), // 34
- cInstEntry("Thread-Cancel", &cHardwareSMT::Inst_ThreadCancel), // 35
- cInstEntry("Thread-Kill", &cHardwareSMT::Inst_ThreadKill), // 36
- cInstEntry("Inject", &cHardwareSMT::Inst_Inject), // 37
- cInstEntry("Apoptosis", &cHardwareSMT::Inst_Apoptosis), // 38
- cInstEntry("Net-Get", &cHardwareSMT::Inst_NetGet), // 39
- cInstEntry("Net-Send", &cHardwareSMT::Inst_NetSend), // 40
- cInstEntry("Net-Receive", &cHardwareSMT::Inst_NetReceive), // 41
- cInstEntry("Net-Last", &cHardwareSMT::Inst_NetLast), // 42
- cInstEntry("Rotate-Left", &cHardwareSMT::Inst_RotateLeft), // 43
- cInstEntry("Rotate-Right", &cHardwareSMT::Inst_RotateRight), // 44
- cInstEntry("Call-Flow", &cHardwareSMT::Inst_CallFlow), // 44
- cInstEntry("Call-Label", &cHardwareSMT::Inst_CallLabel), // 44
- cInstEntry("Return", &cHardwareSMT::Inst_Return), // 44
+ cInstEntry("Nop-A", &cHardwareSMT::Inst_Nop),
+ cInstEntry("Nop-B", &cHardwareSMT::Inst_Nop),
+ cInstEntry("Nop-C", &cHardwareSMT::Inst_Nop),
+ cInstEntry("Nop-D", &cHardwareSMT::Inst_Nop),
+ cInstEntry("Alt", &cHardwareSMT::Inst_Alt),
+ cInstEntry("Val-Shift", &cHardwareSMT::Inst_ValShift),
+ cInstEntry("Val-Nand", &cHardwareSMT::Inst_ValNand),
+ cInstEntry("Val-Add", &cHardwareSMT::Inst_ValAdd),
+ cInstEntry("Val-Sub", &cHardwareSMT::Inst_ValSub),
+ cInstEntry("Val-Negate", &cHardwareSMT::Inst_ValNegate),
+ cInstEntry("Val-Mult", &cHardwareSMT::Inst_ValMult),
+ cInstEntry("Val-Div", &cHardwareSMT::Inst_ValDiv),
+ cInstEntry("Val-Mod", &cHardwareSMT::Inst_ValMod),
+ cInstEntry("Val-Inc", &cHardwareSMT::Inst_ValInc),
+ cInstEntry("Val-Dec", &cHardwareSMT::Inst_ValDec),
+ cInstEntry("Val-Copy", &cHardwareSMT::Inst_ValCopy),
+ cInstEntry("Val-Delete", &cHardwareSMT::Inst_ValDelete),
+ cInstEntry("Stack-Delete", &cHardwareSMT::Inst_StackDelete),
+ cInstEntry("Push-Next", &cHardwareSMT::Inst_PushNext),
+ cInstEntry("Push-Prev", &cHardwareSMT::Inst_PushPrev),
+ cInstEntry("Push-Comp", &cHardwareSMT::Inst_PushComp),
+ cInstEntry("Mem-Set", &cHardwareSMT::Inst_MemSet),
+ cInstEntry("Mem-Mark", &cHardwareSMT::Inst_MemMark),
+ cInstEntry("Mem-Split", &cHardwareSMT::Inst_MemSplit),
+ cInstEntry("Mem-Merge", &cHardwareSMT::Inst_MemMerge),
+ cInstEntry("Divide", &cHardwareSMT::Inst_Divide),
+ cInstEntry("Inject", &cHardwareSMT::Inst_Inject),
+ cInstEntry("Inst-Read", &cHardwareSMT::Inst_InstRead),
+ cInstEntry("Inst-Write", &cHardwareSMT::Inst_InstWrite),
+ cInstEntry("Block-Read", &cHardwareSMT::Inst_BlockRead),
+ cInstEntry("Block-Write", &cHardwareSMT::Inst_BlockWrite),
+ cInstEntry("If-Equal", &cHardwareSMT::Inst_IfEqual),
+ cInstEntry("If-Not-Equal", &cHardwareSMT::Inst_IfNotEqual),
+ cInstEntry("If-Less", &cHardwareSMT::Inst_IfLess),
+ cInstEntry("If-Greater", &cHardwareSMT::Inst_IfGreater),
+ cInstEntry("Head-Push", &cHardwareSMT::Inst_HeadPush),
+ cInstEntry("Head-Pop", &cHardwareSMT::Inst_HeadPop),
+ cInstEntry("Head-Move", &cHardwareSMT::Inst_HeadMove),
+ cInstEntry("Head-Set", &cHardwareSMT::Inst_HeadSet),
+ cInstEntry("Call", &cHardwareSMT::Inst_Call),
+ cInstEntry("Return", &cHardwareSMT::Inst_Return),
+ cInstEntry("Search", &cHardwareSMT::Inst_Search),
+ cInstEntry("Search-Mem", &cHardwareSMT::Inst_SearchMem),
+ cInstEntry("IO", &cHardwareSMT::Inst_IO),
+ cInstEntry("Thread-Set", &cHardwareSMT::Inst_ThreadSet),
+ cInstEntry("Thread-Get", &cHardwareSMT::Inst_ThreadGet),
+ cInstEntry("Apoptosis", &cHardwareSMT::Inst_Apoptosis),
+
cInstEntry("NULL", &cHardwareSMT::Inst_Nop) // Last Instruction Always NULL
};
@@ -725,7 +726,7 @@
// reset the memory space that was injected
m_mem_array[mem_space_used] = cGenome("a");
- for (int x = 0; x < nHardware::NUM_HEADS; x++) GetHead(x).Reset(this, IP().GetMemSpace());
+ for (int x = 0; x < NUM_EXTENDED_HEADS; x++) GetHead(x).Reset(this, IP().GetMemSpace());
for (int x = 0; x < NUM_LOCAL_STACKS; x++) Stack(x).Clear();
AdvanceIP() = false;
@@ -789,16 +790,16 @@
int thread_id = m_threads.GetSize();
// Check for thread cap, base thread label (i.e. no label)
- if (thread_id == m_world->GetConfig().MAX_CPU_THREADS.Get() || label.GetSize() == 0) return -1;
+ if (thread_id == m_world->GetConfig().MAX_CPU_THREADS.Get() || label.GetSize() == 0) return 0;
// Check for existing thread
int hash_key = label.AsInt(NUM_NOPS);
if (m_thread_lbls.Find(hash_key, thread_id)) {
if (m_threads[thread_id].running) {
- return -1; // Thread exists, and is running... call fails
+ return 0; // Thread exists, and is running... call fails
} else {
m_threads[thread_id].Reset(this, mem_space);
- return thread_id;
+ return (thread_id + 1);
}
}
@@ -809,13 +810,16 @@
// Setup this thread into the current selected memory space (Flow Head)
m_threads[thread_id].Reset(this, mem_space);
- return thread_id;
+ return (thread_id + 1);
}
-bool cHardwareSMT::ThreadKill(const int thread_id)
+bool cHardwareSMT::ThreadKill(int thread_id)
{
- if (thread_id < 1 || thread_id >= m_threads.GetSize()) return false;
+ if (thread_id < 1 || thread_id > m_threads.GetSize()) return false;
+ // Adjust thread id to thread array index
+ thread_id--;
+
// Increment thread, if killing current thread
if (m_cur_thread == thread_id) ThreadNext();
@@ -887,12 +891,12 @@
inline int cHardwareSMT::FindModifiedHead(int default_head)
{
- assert(default_head < nHardware::NUM_HEADS); // Head ID too high.
+ assert(default_head < NUM_EXTENDED_HEADS); // Head ID too high.
if (m_inst_set->IsNop(IP().GetNextInst())) {
IP().Advance();
int nop_head = m_inst_set->GetNopMod(IP().GetInst());
- if (nop_head < nHardware::NUM_HEADS) default_head = nop_head;
+ if (nop_head < NUM_EXTENDED_HEADS) default_head = nop_head;
IP().SetFlagExecuted();
}
return default_head;
@@ -1048,11 +1052,11 @@
else if (div_method == DIVIDE_METHOD_BIRTH)
{
if((!organism->GetPhenotype().IsModified() && GetNumThreads() > 1) || GetNumThreads() > 2) {
- ThreadKill(m_cur_thread);
+ ThreadKill(m_cur_thread + 1);
} else {
//this will reset the current thread's heads and stacks. It will
//not touch any other threads or memory spaces (ie: parasites)
- for(int x = 0; x < nHardware::NUM_HEADS; x++) {
+ for(int x = 0; x < NUM_EXTENDED_HEADS; x++) {
GetHead(x).Reset(this, 0);
}
for(int x = 0; x < NUM_LOCAL_STACKS; x++) {
@@ -1069,39 +1073,52 @@
// -------- Begin Core Instruction Set --------
+bool cHardwareSMT::Inst_Alt(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
-//6
-bool cHardwareSMT::Inst_ShiftR(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValShift(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
- const int src = FindModifiedStack(dst);
+ const int op1 = FindModifiedStack(dst);
+ const int op2 = FindModifiedNextStack(op1);
#else
- const int src = dst;
+ const int op1 = dst;
+ const int op2 = FindNextStack(dst);
#endif
- int value = Stack(src).Pop();
- value >>= 1;
+ int value = Stack(op1).Top();
+ int shift = Stack(op2).Top();
+
+ const int bits = sizeof(int) * 8;
+ if (shift >= 0 && shift < bits) { // Positive shift == right shift
+ value >>= shift;
+ } else if (shift < 0 && (-shift) < bits) { // Negative shift == left shift
+ value <<= -shift;
+ } else { // if shift > num_bits then flush to 0
+ value = 0;
+ }
Stack(dst).Push(value);
return true;
}
-//7
-bool cHardwareSMT::Inst_ShiftL(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValNand(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
- const int src = FindModifiedStack(dst);
+ const int op1 = FindModifiedStack(STACK_BX);
+ const int op2 = FindModifiedNextStack(op1);
#else
- const int src = dst;
+ const int op1 = STACK_BX;
+ const int op2 = STACK_CX;
#endif
- int value = Stack(src).Pop();
- value <<= 1;
- Stack(dst).Push(value);
+ Stack(dst).Push(~(Stack(op1).Top() & Stack(op2).Top()));
return true;
}
-//8
-bool cHardwareSMT::Inst_Val_Nand(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValAdd(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1111,27 +1128,23 @@
const int op1 = STACK_BX;
const int op2 = STACK_CX;
#endif
- Stack(dst).Push(~(Stack(op1).Top() & Stack(op2).Top()));
+ Stack(dst).Push(Stack(op1).Top() + Stack(op2).Top());
return true;
}
-//9
-bool cHardwareSMT::Inst_Val_Add(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValNegate(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
const int op1 = FindModifiedStack(STACK_BX);
- const int op2 = FindModifiedNextStack(op1);
#else
const int op1 = STACK_BX;
- const int op2 = STACK_CX;
#endif
- Stack(dst).Push(Stack(op1).Top() + Stack(op2).Top());
+ Stack(dst).Push(-Stack(op1).Top());
return true;
}
-//10
-bool cHardwareSMT::Inst_Val_Sub(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValSub(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1145,8 +1158,7 @@
return true;
}
-//11
-bool cHardwareSMT::Inst_Val_Mult(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValMult(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1160,8 +1172,7 @@
return true;
}
-//12
-bool cHardwareSMT::Inst_Val_Div(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValDiv(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1172,10 +1183,12 @@
const int op2 = STACK_CX;
#endif
if (Stack(op2).Top() != 0) {
- if (0-INT_MAX > Stack(op1).Top() && Stack(op2).Top() == -1)
- organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: Float exception");
- else
+ if (-INT_MAX > Stack(op1).Top() && Stack(op2).Top() == -1) {
+ organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: overflow exception");
+ return false;
+ } else {
Stack(dst).Push(Stack(op1).Top() / Stack(op2).Top());
+ }
} else {
organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: dividing by 0");
return false;
@@ -1183,8 +1196,7 @@
return true;
}
-//13
-bool cHardwareSMT::Inst_Val_Mod(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValMod(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1195,10 +1207,7 @@
const int op2 = STACK_CX;
#endif
if (Stack(op2).Top() != 0) {
- if(Stack(op2).Top() == -1)
- Stack(dst).Push(0);
- else
- Stack(dst).Push(Stack(op1).Top() % Stack(op2).Top());
+ Stack(dst).Push(Stack(op1).Top() % Stack(op2).Top());
} else {
organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
return false;
@@ -1206,8 +1215,7 @@
return true;
}
-//14
-bool cHardwareSMT::Inst_Val_Inc(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValInc(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1215,13 +1223,12 @@
#else
const int src = dst;
#endif
- int value = Stack(src).Pop();
+ int value = Stack(src).Top();
Stack(dst).Push(++value);
return true;
}
-//15
-bool cHardwareSMT::Inst_Val_Dec(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValDec(cAvidaContext& ctx)
{
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1229,14 +1236,76 @@
#else
const int src = dst;
#endif
- int value = Stack(src).Pop();
+ int value = Stack(src).Top();
Stack(dst).Push(--value);
return true;
}
-//16
-bool cHardwareSMT::Inst_SetMemory(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ValCopy(cAvidaContext& ctx)
{
+ const int dst = FindModifiedStack(STACK_BX);
+#if SMT_FULLY_ASSOCIATIVE
+ const int src = FindModifiedStack(dst);
+#else
+ const int src = dst;
+#endif
+ Stack(dst).Push(Stack(src).Top());
+ return true;
+}
+
+bool cHardwareSMT::Inst_ValDelete(cAvidaContext& ctx)
+{
+ int stack_used = FindModifiedStack(STACK_BX);
+ Stack(stack_used).Pop();
+ return true;
+}
+
+bool cHardwareSMT::Inst_StackDelete(cAvidaContext& ctx)
+{
+ int stack_used = FindModifiedStack(STACK_BX);
+ Stack(stack_used).Clear();
+ return true;
+}
+
+
+bool cHardwareSMT::Inst_PushNext(cAvidaContext& ctx)
+{
+ const int src = FindModifiedStack(STACK_AX);
+#if SMT_FULLY_ASSOCIATIVE
+ const int dst = FindModifiedNextStack(src);
+#else
+ const int dst = FindNextStack(src);
+#endif
+ Stack(dst).Push(Stack(src).Pop());
+ return true;
+}
+
+bool cHardwareSMT::Inst_PushPrev(cAvidaContext& ctx)
+{
+ const int src = FindModifiedStack(STACK_BX);
+#if SMT_FULLY_ASSOCIATIVE
+ const int dst = FindModifiedPreviousStack(src);
+#else
+ const int dst = FindPreviousStack(src);
+#endif
+ Stack(dst).Push(Stack(src).Pop());
+ return true;
+}
+
+bool cHardwareSMT::Inst_PushComp(cAvidaContext& ctx)
+{
+ int src = FindModifiedStack(STACK_BX);
+#if SMT_FULLY_ASSOCIATIVE
+ const int dst = FindModifiedComplementStack(src);
+#else
+ const int dst = FindComplementStack(src);
+#endif
+ Stack(dst).Push(Stack(src).Pop());
+ return true;
+}
+
+bool cHardwareSMT::Inst_MemSet(cAvidaContext& ctx)
+{
ReadLabel(MAX_MEMSPACE_LABEL);
if (GetLabel().GetSize() == 0) {
@@ -1250,15 +1319,39 @@
return true;
}
-//17
+bool cHardwareSMT::Inst_MemMark(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
+
+bool cHardwareSMT::Inst_MemSplit(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
+
+bool cHardwareSMT::Inst_MemMerge(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
+
bool cHardwareSMT::Inst_Divide(cAvidaContext& ctx)
{
return Divide_Main(ctx);
}
-//18
-bool cHardwareSMT::Inst_HeadRead(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_Inject(cAvidaContext& ctx)
{
+ ReadLabel(MAX_MEMSPACE_LABEL);
+
+ double mut_multiplier = 1.0;
+ return InjectParasite(ctx, mut_multiplier);
+}
+
+bool cHardwareSMT::Inst_InstRead(cAvidaContext& ctx)
+{
const int head_id = FindModifiedHead(nHardware::HEAD_READ);
#if SMT_FULLY_ASSOCIATIVE
const int dst = FindModifiedStack(STACK_AX);
@@ -1267,7 +1360,7 @@
#endif
GetHead(head_id).Adjust();
- sCPUStats & cpu_stats = organism->CPUStats();
+ sCPUStats& cpu_stats = organism->CPUStats();
// Mutations only occur on the read, for the moment.
int read_inst = 0;
@@ -1285,8 +1378,7 @@
return true;
}
-//19
-bool cHardwareSMT::Inst_HeadWrite(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_InstWrite(cAvidaContext& ctx)
{
const int head_id = FindModifiedHead(nHardware::HEAD_WRITE);
#if SMT_FULLY_ASSOCIATIVE
@@ -1317,21 +1409,31 @@
return true;
}
-//20
-bool cHardwareSMT::Inst_IfEqual(cAvidaContext& ctx) // Execute next if bx == ?cx?
+bool cHardwareSMT::Inst_BlockRead(cAvidaContext& ctx)
{
+ // @DMB - todo
+ return true;
+}
+
+bool cHardwareSMT::Inst_BlockWrite(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
+
+bool cHardwareSMT::Inst_IfEqual(cAvidaContext& ctx) // Execute next if op1 == op2
+{
const int op1 = FindModifiedStack(STACK_AX);
#if SMT_FULLY_ASSOCIATIVE
const int op2 = FindModifiedNextStack(op1);
#else
const int op2 = FindNextStack(op1);
#endif
- if (Stack(op1).Top() != Stack(op2).Top()) IP().Advance();
+ if (Stack(op1).Top() != Stack(op2).Top()) IP().Advance();
return true;
}
-//21
-bool cHardwareSMT::Inst_IfNotEqual(cAvidaContext& ctx) // Execute next if bx != ?cx?
+bool cHardwareSMT::Inst_IfNotEqual(cAvidaContext& ctx) // Execute next if op1 != op2
{
const int op1 = FindModifiedStack(STACK_AX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1339,12 +1441,11 @@
#else
const int op2 = FindNextStack(op1);
#endif
- if (Stack(op1).Top() == Stack(op2).Top()) IP().Advance();
+ if (Stack(op1).Top() == Stack(op2).Top()) IP().Advance();
return true;
}
-//22
-bool cHardwareSMT::Inst_IfLess(cAvidaContext& ctx) // Execute next if ?bx? < ?cx?
+bool cHardwareSMT::Inst_IfLess(cAvidaContext& ctx) // Execute next if op1 < op2
{
const int op1 = FindModifiedStack(STACK_AX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1352,12 +1453,11 @@
#else
const int op2 = FindNextStack(op1);
#endif
- if (Stack(op1).Top() >= Stack(op2).Top()) IP().Advance();
+ if (Stack(op1).Top() >= Stack(op2).Top()) IP().Advance();
return true;
}
-//23
-bool cHardwareSMT::Inst_IfGreater(cAvidaContext& ctx) // Execute next if bx > ?cx?
+bool cHardwareSMT::Inst_IfGreater(cAvidaContext& ctx) // Execute next if op1 > op2
{
const int op1 = FindModifiedStack(STACK_AX);
#if SMT_FULLY_ASSOCIATIVE
@@ -1365,11 +1465,10 @@
#else
const int op2 = FindNextStack(op1);
#endif
- if (Stack(op1).Top() <= Stack(op2).Top()) IP().Advance();
+ if (Stack(op1).Top() <= Stack(op2).Top()) IP().Advance();
return true;
}
-//24
bool cHardwareSMT::Inst_HeadPush(cAvidaContext& ctx)
{
const int head_used = FindModifiedHead(nHardware::HEAD_IP);
@@ -1378,11 +1477,10 @@
#else
const int dst = STACK_BX;
#endif
- Stack(dst).Push(GetHead(head_used).GetPosition());
+ Stack(dst).Push(GetHead(head_used).GetFullLocation());
return true;
}
-//25
bool cHardwareSMT::Inst_HeadPop(cAvidaContext& ctx)
{
const int head_used = FindModifiedHead(nHardware::HEAD_IP);
@@ -1391,11 +1489,10 @@
#else
const int src = STACK_BX;
#endif
- GetHead(head_used).Set(Stack(src).Pop(), GetHead(head_used).GetMemSpace());
+ GetHead(head_used).SetFullLocation(Stack(src).Pop());
return true;
}
-//26
bool cHardwareSMT::Inst_HeadMove(cAvidaContext& ctx)
{
const int head_used = FindModifiedHead(nHardware::HEAD_IP);
@@ -1411,7 +1508,44 @@
return true;
}
-//27
+bool cHardwareSMT::Inst_HeadSet(cAvidaContext& ctx)
+{
+ // @DMB - todo
+ return true;
+}
+
+bool cHardwareSMT::Inst_Call(cAvidaContext& ctx)
+{
+ const int dst = FindModifiedStack(STACK_AX);
+
+ Stack(dst).Push(IP().GetFullLocation());
+
+ ReadLabel(MAX_MEMSPACE_LABEL);
+
+ // If a label was specified, call target label
+ if (GetLabel().GetSize() != 0) {
+ int mem_space_used = FindMemorySpaceLabel(GetLabel(), -1);
+ if (mem_space_used > -1) {
+ // Jump to beginning of memory space
+ IP().Set(0, mem_space_used);
+ return true;
+ }
+ return false;
+ }
+
+ // Default to calling the flow head
+ IP().Set(GetHead(nHardware::HEAD_FLOW));
+
+ return true;
+}
+
+bool cHardwareSMT::Inst_Return(cAvidaContext& ctx)
+{
+ const int src = FindModifiedStack(STACK_AX);
+ IP().SetFullLocation(Stack(src).Pop());
+ return true;
+}
+
bool cHardwareSMT::Inst_Search(cAvidaContext& ctx)
{
ReadLabel();
@@ -1435,69 +1569,17 @@
return true;
}
-//28
-bool cHardwareSMT::Inst_PushNext(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_SearchMem(cAvidaContext& ctx)
{
- const int src = FindModifiedStack(STACK_AX);
-#if SMT_FULLY_ASSOCIATIVE
- const int dst = FindModifiedNextStack(src);
-#else
- const int dst = FindNextStack(src);
-#endif
- Stack(dst).Push(Stack(src).Pop());
- return true;
+ // @DMB - todo
+ return true;
}
-//29
-bool cHardwareSMT::Inst_PushPrevious(cAvidaContext& ctx)
-{
- const int src = FindModifiedStack(STACK_BX);
-#if SMT_FULLY_ASSOCIATIVE
- const int dst = FindModifiedPreviousStack(src);
-#else
- const int dst = FindPreviousStack(src);
-#endif
- Stack(dst).Push(Stack(src).Pop());
- return true;
-}
-
-//30
-bool cHardwareSMT::Inst_PushComplement(cAvidaContext& ctx)
-{
- int src = FindModifiedStack(STACK_BX);
-#if SMT_FULLY_ASSOCIATIVE
- const int dst = FindModifiedComplementStack(src);
-#else
- const int dst = FindComplementStack(src);
-#endif
- Stack(dst).Push(Stack(src).Pop());
- return true;
-}
-
-//31
-bool cHardwareSMT::Inst_ValDelete(cAvidaContext& ctx)
-{
- int stack_used = FindModifiedStack(STACK_BX);
- Stack(stack_used).Pop();
- return true;
-}
-
-//32
-bool cHardwareSMT::Inst_ValCopy(cAvidaContext& ctx)
-{
- const int dst = FindModifiedStack(STACK_BX);
-#if SMT_FULLY_ASSOCIATIVE
- const int src = FindModifiedStack(dst);
-#else
- const int src = dst;
-#endif
- Stack(dst).Push(Stack(src).Top());
- return true;
-}
-
-//33
bool cHardwareSMT::Inst_IO(cAvidaContext& ctx)
{
+ // @DMB - todo : exchange full stack...
+
+
const int dst = FindModifiedStack(STACK_BX);
#if SMT_FULLY_ASSOCIATIVE
const int src = FindModifiedStack(dst);
@@ -1516,195 +1598,77 @@
return true;
}
-
-// -------- End Core Instruction Set --------
-
-
-// -------- Additional Instructions --------
-
-
-//34
-bool cHardwareSMT::Inst_ThreadCreate(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ThreadSet(cAvidaContext& ctx)
{
+ // @DMB - todo : add actual thread priority handling
+
ReadLabel(MAX_THREAD_LABEL);
- bool success = ThreadCreate(GetLabel(), GetHead(nHardware::HEAD_FLOW).GetMemSpace());
- if (!success) organism->Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
- return success;
-}
-
-//35
-bool cHardwareSMT::Inst_ThreadCancel(cAvidaContext& ctx)
-{
- bool success = ThreadKill(m_cur_thread);
- if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
- return success;
-}
-
-//36
-bool cHardwareSMT::Inst_ThreadKill(cAvidaContext& ctx)
-{
- ReadLabel(MAX_THREAD_LABEL);
- bool success = ThreadKill(GetLabel());
- if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
- return success;
-}
-
-
-
-//37
-//
-// The inject instruction can be used instead of a divide command, paired
-// with an allocate. Note that for an inject to work, one needs to have a
-// broad range for sizes allowed to be allocated.
-//
-// This command will cut out from read-head to write-head.
-// It will then look at the template that follows the command and inject it
-// into the complement template found in a neighboring organism.
-bool cHardwareSMT::Inst_Inject(cAvidaContext& ctx)
-{
- ReadLabel(MAX_MEMSPACE_LABEL);
+ bool success = false;
- double mut_multiplier = 1.0;
- return InjectParasite(ctx, mut_multiplier);
-}
-
-//38
-bool cHardwareSMT::Inst_Apoptosis(cAvidaContext& ctx)
-{
- organism->Die();
+ const int priority = Stack(STACK_BX).Top();
- return true;
-}
+ if (GetLabel().GetSize()) { // working with a labeled thread
+ if (priority) {
+ int thread_id = ThreadCreate(GetLabel(), GetHead(nHardware::HEAD_FLOW).GetMemSpace());
+ Stack(STACK_CX).Push(thread_id);
+ if (!thread_id) {
+ success = false;
+ organism->Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
+ }
+ } else {
+ success = ThreadKill(GetLabel());
+ if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
+ }
+ } else { // working with an absolute thread ID
+ int thread_id = Stack(STACK_CX).Top();
+ if (!thread_id) thread_id = m_cur_thread + 1;
+
+ if (!priority) {
+ success = ThreadKill(thread_id);
+ if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
+ }
+ }
-//39
-bool cHardwareSMT::Inst_NetGet(cAvidaContext& ctx)
-{
- const int dst = FindModifiedStack(STACK_BX);
-#if SMT_FULLY_ASSOCIATIVE
- const int seq_dst = FindModifiedNextStack(dst);
-#else
- const int seq_dst = FindNextStack(dst);
-#endif
- int val, seq;
- organism->NetGet(ctx, val, seq);
- Stack(dst).Push(val);
- Stack(seq_dst).Push(seq);
-
- return true;
-}
-
-//40
-bool cHardwareSMT::Inst_NetSend(cAvidaContext& ctx)
-{
- const int src = FindModifiedStack(STACK_BX);
- organism->NetSend(ctx, Stack(src).Pop());
- return true;
-}
-
-//41
-bool cHardwareSMT::Inst_NetReceive(cAvidaContext& ctx)
-{
- const int dst = FindModifiedStack(STACK_BX);
- int val;
- bool success = organism->NetReceive(val);
- Stack(dst).Push(val);
return success;
}
-//42
-bool cHardwareSMT::Inst_NetLast(cAvidaContext& ctx)
+bool cHardwareSMT::Inst_ThreadGet(cAvidaContext& ctx)
{
- const int dst = FindModifiedStack(STACK_CX);
- Stack(dst).Push(organism->NetLast());
- return true;
-}
+ // @DMB - todo : add actual thread priority handling
-//43
-bool cHardwareSMT::Inst_RotateLeft(cAvidaContext& ctx)
-{
- const int num_neighbors = organism->GetNeighborhoodSize();
-
- // If this organism has no neighbors, ignore rotate.
- if (num_neighbors == 0) return false;
-
- // Always rotate at least once.
- organism->Rotate(-1);
-
- return true;
-}
+ ReadLabel(MAX_THREAD_LABEL);
+ int thread_id = 0;
-//44
-bool cHardwareSMT::Inst_RotateRight(cAvidaContext& ctx)
-{
- const int num_neighbors = organism->GetNeighborhoodSize();
- // If this organism has no neighbors, ignore rotate.
- if (num_neighbors == 0) return false;
-
- // Always rotate at least once.
- organism->Rotate(1);
-
- return true;
-}
-
-//45
-bool cHardwareSMT::Inst_CallFlow(cAvidaContext& ctx)
-{
- const int dst = FindModifiedStack(STACK_AX);
-
- const int location = IP().GetPosition() & 0xFFFF;
- const int mem_space = IP().GetMemSpace() << 8;
- const int ra = location | mem_space;
-
- Stack(dst).Push(ra);
-
- cHeadCPU& flow = GetHead(nHardware::HEAD_FLOW);
- IP().Set(flow.GetPosition(), flow.GetMemSpace());
-
- return true;
-}
-
-//46
-bool cHardwareSMT::Inst_CallLabel(cAvidaContext& ctx)
-{
- const int dst = FindModifiedStack(STACK_AX);
-
- const unsigned int location = IP().GetPosition() & 0xFFFF;
- const unsigned int mem_space = IP().GetMemSpace() << 8;
- const unsigned int ra = location | mem_space;
-
- Stack(dst).Push(ra);
-
- ReadLabel(MAX_MEMSPACE_LABEL);
-
- // If a label was specified, call target label
- if (GetLabel().GetSize() != 0) {
- int mem_space_used = FindMemorySpaceLabel(GetLabel(), -1);
- if (mem_space_used > -1) {
- // Jump to beginning of memory space
- IP().Set(0, mem_space_used);
- return true;
+ if (GetLabel().GetSize()) {
+ int hash_key = GetLabel().AsInt(NUM_NOPS);
+ if (m_thread_lbls.Find(hash_key, thread_id)) {
+ Stack(STACK_BX).Push(m_threads[thread_id].running);
+ Stack(STACK_CX).Push(thread_id + 1);
+ } else {
+ Stack(STACK_BX).Push(0);
+ Stack(STACK_CX).Push(0);
}
- return false;
+ } else {
+ thread_id = Stack(STACK_CX).Top();
+ if (thread_id == 0) { // Current Thread
+ Stack(STACK_BX).Push(1); // should be priority
+ Stack(STACK_CX).Push(m_cur_thread + 1);
+ } else if (thread_id < 1 || thread_id > m_threads.GetSize()) { // Thread out of range
+ Stack(STACK_BX).Push(0);
+ Stack(STACK_CX).Push(0);
+ } else { // Lookup valid thread
+ Stack(STACK_BX).Push(m_threads[thread_id - 1].running);
+ Stack(STACK_CX).Push(thread_id);
+ }
}
- // Default to calling the flow head
- cHeadCPU& flow = GetHead(nHardware::HEAD_FLOW);
- IP().Set(flow.GetPosition(), flow.GetMemSpace());
-
return true;
}
-//47
-bool cHardwareSMT::Inst_Return(cAvidaContext& ctx)
+
+bool cHardwareSMT::Inst_Apoptosis(cAvidaContext& ctx)
{
- const int src = FindModifiedStack(STACK_AX);
- const unsigned int ra = Stack(src).Pop();
-
- const int location = ra & 0xFFFF;
- const int mem_space = NormalizeMemSpace(ra >> 8);
-
- IP().Set(location, mem_space);
-
+ organism->Die();
return true;
}
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHardwareSMT.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -231,6 +231,7 @@
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
cCPUMemory& GetMemory(int mem_space) { return m_mem_array[NormalizeMemSpace(mem_space)]; }
const cCPUMemory& GetMemory(int mem_space) const { return m_mem_array[NormalizeMemSpace(mem_space)]; }
+ int GetNumMemSpaces() const { return m_mem_array.GetSize(); }
// -------- Register Manipulation --------
@@ -260,51 +261,50 @@
// ---------- Instruction Library -----------
// Core Instuction Set
- bool Inst_ShiftR(cAvidaContext& ctx); // 6
- bool Inst_ShiftL(cAvidaContext& ctx); // 7
- bool Inst_Val_Nand(cAvidaContext& ctx); // 8
- bool Inst_Val_Add(cAvidaContext& ctx); // 9
- bool Inst_Val_Sub(cAvidaContext& ctx); // 10
- bool Inst_Val_Mult(cAvidaContext& ctx); // 11
- bool Inst_Val_Div(cAvidaContext& ctx); // 12
- bool Inst_Val_Mod(cAvidaContext& ctx); // 13
- bool Inst_Val_Inc(cAvidaContext& ctx); // 14
- bool Inst_Val_Dec(cAvidaContext& ctx); // 15
- bool Inst_SetMemory(cAvidaContext& ctx); // 16
- bool Inst_Divide(cAvidaContext& ctx); // 17
- bool Inst_HeadRead(cAvidaContext& ctx); // 18
- bool Inst_HeadWrite(cAvidaContext& ctx); // 19
- bool Inst_IfEqual(cAvidaContext& ctx); // 20
- bool Inst_IfNotEqual(cAvidaContext& ctx); // 21
- bool Inst_IfLess(cAvidaContext& ctx); // 22
- bool Inst_IfGreater(cAvidaContext& ctx); // 23
- bool Inst_HeadPush(cAvidaContext& ctx); // 24
- bool Inst_HeadPop(cAvidaContext& ctx); // 25
- bool Inst_HeadMove(cAvidaContext& ctx); // 26
- bool Inst_Search(cAvidaContext& ctx); // 27
- bool Inst_PushNext(cAvidaContext& ctx); // 28
- bool Inst_PushPrevious(cAvidaContext& ctx); // 29
- bool Inst_PushComplement(cAvidaContext& ctx); // 30
- bool Inst_ValDelete(cAvidaContext& ctx); // 31
- bool Inst_ValCopy(cAvidaContext& ctx); // 32
- bool Inst_IO(cAvidaContext& ctx); // 33
+ bool Inst_Alt(cAvidaContext& ctx);
+ bool Inst_ValShift(cAvidaContext& ctx);
+ bool Inst_ValNand(cAvidaContext& ctx);
+ bool Inst_ValAdd(cAvidaContext& ctx);
+ bool Inst_ValSub(cAvidaContext& ctx);
+ bool Inst_ValNegate(cAvidaContext& ctx);
+ bool Inst_ValMult(cAvidaContext& ctx);
+ bool Inst_ValDiv(cAvidaContext& ctx);
+ bool Inst_ValMod(cAvidaContext& ctx);
+ bool Inst_ValInc(cAvidaContext& ctx);
+ bool Inst_ValDec(cAvidaContext& ctx);
+ bool Inst_ValCopy(cAvidaContext& ctx);
+ bool Inst_ValDelete(cAvidaContext& ctx);
+ bool Inst_StackDelete(cAvidaContext& ctx);
+ bool Inst_PushNext(cAvidaContext& ctx);
+ bool Inst_PushPrev(cAvidaContext& ctx);
+ bool Inst_PushComp(cAvidaContext& ctx);
+ bool Inst_MemSet(cAvidaContext& ctx);
+ bool Inst_MemMark(cAvidaContext& ctx);
+ bool Inst_MemSplit(cAvidaContext& ctx);
+ bool Inst_MemMerge(cAvidaContext& ctx);
+ bool Inst_Divide(cAvidaContext& ctx);
+ bool Inst_Inject(cAvidaContext& ctx);
+ bool Inst_InstRead(cAvidaContext& ctx);
+ bool Inst_InstWrite(cAvidaContext& ctx);
+ bool Inst_BlockRead(cAvidaContext& ctx);
+ bool Inst_BlockWrite(cAvidaContext& ctx);
+ bool Inst_IfEqual(cAvidaContext& ctx);
+ bool Inst_IfNotEqual(cAvidaContext& ctx);
+ bool Inst_IfLess(cAvidaContext& ctx);
+ bool Inst_IfGreater(cAvidaContext& ctx);
+ bool Inst_HeadPush(cAvidaContext& ctx);
+ bool Inst_HeadPop(cAvidaContext& ctx);
+ bool Inst_HeadMove(cAvidaContext& ctx);
+ bool Inst_HeadSet(cAvidaContext& ctx);
+ bool Inst_Call(cAvidaContext& ctx);
+ bool Inst_Return(cAvidaContext& ctx);
+ bool Inst_Search(cAvidaContext& ctx);
+ bool Inst_SearchMem(cAvidaContext& ctx);
+ bool Inst_IO(cAvidaContext& ctx);
+ bool Inst_ThreadSet(cAvidaContext& ctx);
+ bool Inst_ThreadGet(cAvidaContext& ctx);
- // Additional Instructions
- bool Inst_ThreadCreate(cAvidaContext& ctx); // 34
- bool Inst_ThreadCancel(cAvidaContext& ctx); // 35
- bool Inst_ThreadKill(cAvidaContext& ctx); // 36
- bool Inst_Inject(cAvidaContext& ctx); // 37
- bool Inst_Apoptosis(cAvidaContext& ctx); // 38
- bool Inst_NetGet(cAvidaContext& ctx); // 39
- bool Inst_NetSend(cAvidaContext& ctx); // 40
- bool Inst_NetReceive(cAvidaContext& ctx); // 41
- bool Inst_NetLast(cAvidaContext& ctx); // 42
- bool Inst_RotateLeft(cAvidaContext& ctx); // 43
- bool Inst_RotateRight(cAvidaContext& ctx); // 44
- bool Inst_CallFlow(cAvidaContext& ctx); // 45
- bool Inst_CallLabel(cAvidaContext& ctx); // 46
- bool Inst_Return(cAvidaContext& ctx); // 47
-
+ bool Inst_Apoptosis(cAvidaContext& ctx);
};
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHardwareTransSMT.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -231,6 +231,7 @@
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
cCPUMemory& GetMemory(int mem_space) { return m_mem_array[NormalizeMemSpace(mem_space)]; }
const cCPUMemory& GetMemory(int mem_space) const { return m_mem_array[NormalizeMemSpace(mem_space)]; }
+ int GetNumMemSpaces() const { return m_mem_array.GetSize(); }
// -------- Register Manipulation --------
Modified: development/source/cpu/cHeadCPU.cc
===================================================================
--- development/source/cpu/cHeadCPU.cc 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHeadCPU.cc 2006-07-15 21:37:38 UTC (rev 838)
@@ -20,6 +20,9 @@
void cHeadCPU::Adjust()
{
+ // Ensure that m_mem_space is valid
+ m_mem_space %= m_hardware->GetNumMemSpaces();
+
const int mem_size = GetMemory().GetSize();
// If we are still in range, stop here!
Modified: development/source/cpu/cHeadCPU.h
===================================================================
--- development/source/cpu/cHeadCPU.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/cpu/cHeadCPU.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -52,12 +52,15 @@
inline const cCPUMemory& GetMemory() const { return m_hardware->GetMemory(m_mem_space); }
inline cCPUMemory& GetMemory() { return m_hardware->GetMemory(m_mem_space); }
- inline int GetMemSpace() const { return m_mem_space; }
-
void Adjust();
inline void Reset(cHardwareBase* hw, int ms = 0) { m_hardware = hw; m_position = 0; m_mem_space = ms; }
+ inline int GetMemSpace() const { return m_mem_space; }
+ inline int GetPosition() const { return m_position; }
+ inline int GetFullLocation() const { return (m_position & 0xFFFFFF) | (m_mem_space << 24); }
+
inline void Set(int pos, int ms = 0) { m_position = pos; m_mem_space = ms; Adjust(); }
+ inline void SetFullLocation(int loc) { m_position = loc & 0xFFFFFF; m_mem_space = (loc >> 24); Adjust(); }
inline void Set(const cHeadCPU& in_head) { m_position = in_head.m_position; m_mem_space = in_head.m_mem_space; }
inline void AbsSet(int new_pos) { m_position = new_pos; }
@@ -69,7 +72,6 @@
inline void Retreat() { m_position--; Adjust(); }
cHeadCPU FindLabel(const cCodeLabel& label, int direction = 1);
- inline int GetPosition() const { return m_position; }
inline const cInstruction& GetInst() const { return GetMemory()[m_position]; }
inline const cInstruction& GetInst(int offset) const { return GetMemory()[m_position + offset]; }
inline const cInstruction& GetNextInst() const;
Modified: development/source/main/cInstSet.cc
===================================================================
--- development/source/main/cInstSet.cc 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/main/cInstSet.cc 2006-07-15 21:37:38 UTC (rev 838)
@@ -18,36 +18,11 @@
// Initialize static variables
-const cInstruction cInstSet::inst_default( 0 );
-cInstruction cInstSet::inst_default2( 0 );
-cInstruction cInstSet::inst_error2 ( 255 );
+const cInstruction cInstSet::inst_default(0);
+cInstruction cInstSet::inst_default2(0);
+cInstruction cInstSet::inst_error2(255);
-cInstSet::cInstSet(cWorld* world) : m_world(world)
-{
-}
-cInstSet::cInstSet(const cInstSet & in_inst_set)
- : m_world(in_inst_set.m_world)
- , m_inst_lib(in_inst_set.m_inst_lib)
- , m_lib_name_map(in_inst_set.m_lib_name_map)
- , m_lib_nopmod_map(in_inst_set.m_lib_nopmod_map)
- , m_mutation_chart(in_inst_set.m_mutation_chart)
-{
-}
-
-cInstSet::~cInstSet()
-{
-}
-
-cInstSet & cInstSet::operator=(const cInstSet & _in)
-{
- m_inst_lib = _in.m_inst_lib;
- m_lib_name_map = _in.m_lib_name_map;
- m_lib_nopmod_map = _in.m_lib_nopmod_map;
- m_mutation_chart = _in.m_mutation_chart;
- return *this;
-}
-
bool cInstSet::OK() const
{
assert(m_lib_name_map.GetSize() < 256);
@@ -74,13 +49,7 @@
return cInstruction(inst_op);
}
-int cInstSet::AddInst(
- const int lib_fun_id,
- const int redundancy,
- const int ft_cost,
- const int cost,
- const double prob_fail
-)
+int cInstSet::AddInst(int lib_fun_id, int redundancy, int ft_cost, int cost, double prob_fail)
{
const int inst_id = m_lib_name_map.GetSize();
@@ -105,14 +74,8 @@
return inst_id;
}
-int cInstSet::AddNop(
- const int lib_nopmod_id,
- const int redundancy,
- const int ft_cost,
- const int cost,
- const double prob_fail
-)
-{
+int cInstSet::AddNop(int lib_nopmod_id, int redundancy, int ft_cost, int cost, double prob_fail)
+{
// Assert nops are at the _beginning_ of an inst_set.
assert(m_lib_name_map.GetSize() == m_lib_nopmod_map.GetSize());
@@ -124,7 +87,7 @@
return inst_id;
}
-cString cInstSet::FindBestMatch(const cString & in_name) const
+cString cInstSet::FindBestMatch(const cString& in_name) const
{
int best_dist = 1024;
cString best_name("");
Modified: development/source/main/cInstSet.h
===================================================================
--- development/source/main/cInstSet.h 2006-07-15 02:17:23 UTC (rev 837)
+++ development/source/main/cInstSet.h 2006-07-15 21:37:38 UTC (rev 838)
@@ -55,59 +55,33 @@
tArray<cInstEntry> m_lib_name_map;
tArray<int> m_lib_nopmod_map;
tArray<int> m_mutation_chart; // ID's represented by redundancy values.
+
// Static components...
static cInstruction inst_error2;
- // static const cInstruction inst_none;
static cInstruction inst_default2;
-
- // Static components...
- //static const cInstruction inst_error;
- // static const cInstruction inst_none;
static const cInstruction inst_default;
cInstSet(); // @not_implemented
public:
- cInstSet(cWorld* world);
- cInstSet(const cInstSet& in_inst_set);
- ~cInstSet();
+ inline cInstSet(cWorld* world) : m_world(world) { ; }
+ inline cInstSet(const cInstSet& is);
+ inline ~cInstSet() { ; }
- cInstSet& operator=(const cInstSet& _in);
+ inline cInstSet& operator=(const cInstSet& _in);
bool OK() const;
// Accessors
- const cString& GetName(int id) const
- {
- return m_inst_lib->GetName(m_lib_name_map[id].lib_fun_id);
- }
- const cString& GetName(const cInstruction & inst) const
- {
- return GetName(inst.GetOp());
- }
- int GetCost(const cInstruction & inst) const
- {
- return m_lib_name_map[inst.GetOp()].cost;
- }
- int GetFTCost(const cInstruction & inst) const
- {
- return m_lib_name_map[inst.GetOp()].ft_cost;
- }
- double GetProbFail(const cInstruction & inst) const
- {
- return m_lib_name_map[inst.GetOp()].prob_fail;
- }
- int GetRedundancy(const cInstruction & inst) const
- {
- return m_lib_name_map[inst.GetOp()].redundancy;
- }
+ const cString& GetName(int id) const { return m_inst_lib->GetName(m_lib_name_map[id].lib_fun_id); }
+ const cString& GetName(const cInstruction& inst) const { return GetName(inst.GetOp()); }
+ int GetCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].cost; }
+ int GetFTCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].ft_cost; }
+ double GetProbFail(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].prob_fail; }
+ 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 GetLibFunctionIndex(const cInstruction & inst) const
- {
- return m_lib_name_map[inst.GetOp()].lib_fun_id;
- }
-
int GetNopMod(const cInstruction & inst) const
{
int nopmod = m_lib_nopmod_map[inst.GetOp()];
@@ -115,59 +89,33 @@
}
cInstruction GetRandomInst(cAvidaContext& ctx) const;
- int GetRandFunctionIndex(cAvidaContext& ctx) const
- {
- return m_lib_name_map[ GetRandomInst(ctx).GetOp() ].lib_fun_id;
- }
+ int GetRandFunctionIndex(cAvidaContext& ctx) const { return m_lib_name_map[ GetRandomInst(ctx).GetOp() ].lib_fun_id; }
- int GetSize() const {
- return m_lib_name_map.GetSize();
- }
- int GetNumNops() const {
- return m_lib_nopmod_map.GetSize();
- }
+ int GetSize() const { return m_lib_name_map.GetSize(); }
+ int GetNumNops() const { return m_lib_nopmod_map.GetSize(); }
// Instruction Analysis.
- int IsNop(const cInstruction & inst) const
- {
- return (inst.GetOp() < m_lib_nopmod_map.GetSize());
- }
+ int IsNop(const cInstruction& inst) const { return (inst.GetOp() < m_lib_nopmod_map.GetSize()); }
// Insertion of new instructions...
- int AddInst(
- const int lib_fun_id,
- const int redundancy=1,
- const int ft_cost=0,
- const int cost=0,
- const double prob_fail=0.0
- );
- int AddNop(
- const int lib_nopmod_id,
- const int redundancy=1,
- const int ft_cost=0,
- const int cost=0,
- const double prob_fail=0.0
- );
+ int AddInst(int lib_fun_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0);
+ int AddNop(int lib_nopmod_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0);
// accessors for instruction library
- cInstLibBase *GetInstLib(){ return m_inst_lib; }
- void SetInstLib(cInstLibBase *inst_lib){
+ cInstLibBase* GetInstLib() { return m_inst_lib; }
+ void SetInstLib(cInstLibBase* inst_lib)
+ {
m_inst_lib = inst_lib;
inst_error2 = inst_lib->GetInstError();
inst_default2 = inst_lib->GetInstDefault();
}
- inline cInstruction GetInst(const cString & in_name) const;
- cString FindBestMatch(const cString & in_name) const;
+ inline cInstruction GetInst(const cString& in_name) const;
+ cString FindBestMatch(const cString& in_name) const;
// Static methods..
- static const cInstruction & GetInstDefault() {
- return inst_default2;
- }
- static const cInstruction & GetInstError() {
- return inst_error2;
- }
- // static const cInstruction & GetInstNone() { return inst_none; }
+ static const cInstruction& GetInstDefault() { return inst_default2; }
+ static const cInstruction & GetInstError() { return inst_error2; }
};
@@ -183,6 +131,21 @@
#endif
+inline cInstSet::cInstSet(const cInstSet& is)
+: m_world(is.m_world), m_inst_lib(is.m_inst_lib), m_lib_name_map(is.m_lib_name_map)
+,m_lib_nopmod_map(is.m_lib_nopmod_map), m_mutation_chart(is.m_mutation_chart)
+{
+}
+
+inline cInstSet& cInstSet::operator=(const cInstSet& _in)
+{
+ m_inst_lib = _in.m_inst_lib;
+ m_lib_name_map = _in.m_lib_name_map;
+ m_lib_nopmod_map = _in.m_lib_nopmod_map;
+ m_mutation_chart = _in.m_mutation_chart;
+ return *this;
+}
+
inline cInstruction cInstSet::GetInst(const cString & in_name) const
{
for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
More information about the Avida-cvs
mailing list