[Avida-SVN] r2285 - development/source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Jan 28 04:54:11 PST 2008
Author: brysonda
Date: 2008-01-28 07:54:10 -0500 (Mon, 28 Jan 2008)
New Revision: 2285
Modified:
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
development/source/cpu/cHardwareGX.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.cc
development/source/cpu/cHeadCPU.h
Log:
More hardware object performance tweaks.
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareBase.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -147,8 +147,10 @@
// -------- Memory Manipulation --------
virtual const cCPUMemory& GetMemory() const = 0;
virtual cCPUMemory& GetMemory() = 0;
+ virtual int GetMemSize() const = 0;
virtual const cCPUMemory& GetMemory(int value) const = 0;
virtual cCPUMemory& GetMemory(int value) = 0;
+ virtual int GetMemSize(int value) const = 0;
virtual int GetNumMemSpaces() const = 0;
@@ -161,8 +163,8 @@
// -------- Thread Manipulation --------
virtual bool ThreadSelect(const int thread_id) = 0;
virtual bool ThreadSelect(const cCodeLabel& in_label) = 0;
+ virtual void ThreadNext() = 0;
virtual void ThreadPrev() = 0;
- virtual void ThreadNext() = 0;
virtual cInjectGenotype* ThreadGetOwner() = 0;
virtual void ThreadSetOwner(cInjectGenotype* in_genotype) = 0;
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareCPU.cc 2008-01-28 12:54:10 UTC (rev 2285)
@@ -466,9 +466,9 @@
m_promoter_index = -1; // Meaning the last promoter was nothing
m_promoter_offset = 0;
m_promoters.Resize(0);
- for (int i=0; i<GetMemory().GetSize(); i++)
+ for (int i=0; i< m_memory.GetSize(); i++)
{
- if ( (GetMemory())[i] == promoter_inst)
+ if (m_memory[i] == promoter_inst)
{
int code = Numberate(i-1, -1, m_world->GetConfig().PROMOTER_CODE_SIZE.Get());
m_promoters.Push( cPromoter(i,code) );
@@ -521,7 +521,7 @@
phenotype.IncCPUCyclesUsed();
if (!m_world->GetConfig().NO_CPU_CYCLE_TIME.Get()) phenotype.IncTimeUsed();
- const int num_threads = GetNumThreads();
+ const int num_threads = m_threads.GetSize();
// If we have threads turned on and we executed each thread in a single
// timestep, adjust the number of instructions executed accordingly.
@@ -529,7 +529,8 @@
for (int i = 0; i < num_inst_exec; i++) {
// Setup the hardware for the next instruction to be executed.
- ThreadNext();
+ m_cur_thread++;
+ if (m_cur_thread >= num_threads) m_cur_thread = 0;
m_advance_ip = true;
IP().Adjust();
@@ -675,7 +676,7 @@
if (!m_memory.OK()) result = false;
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
if (m_threads[i].stack.OK() == false) result = false;
if (m_threads[i].next_label.OK() == false) result = false;
}
@@ -714,8 +715,8 @@
fp << setfill(' ') << setbase(10) << endl;
}
- fp << " Mem (" << GetMemory().GetSize() << "):"
- << " " << GetMemory().AsString()
+ fp << " Mem (" << m_memory.GetSize() << "):"
+ << " " << m_memory.AsString()
<< endl;
if (m_world->GetConfig().PROMOTERS_ENABLED.Get())
@@ -987,7 +988,7 @@
{
// Make sure the genome will be below max size after injection.
- const int new_size = injection.GetSize() + GetMemory().GetSize();
+ const int new_size = injection.GetSize() + m_memory.GetSize();
if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
const int inject_line = FindLabelFull(in_label).GetPosition();
@@ -1036,7 +1037,7 @@
void cHardwareCPU::AdjustHeads()
{
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
for (int j = 0; j < NUM_HEADS; j++) {
m_threads[i].heads[j].Adjust();
}
@@ -1072,7 +1073,7 @@
bool cHardwareCPU::ForkThread()
{
- const int num_threads = GetNumThreads();
+ const int num_threads = m_threads.GetSize();
if (num_threads == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
// Make room for the new thread.
@@ -1095,7 +1096,7 @@
bool cHardwareCPU::KillThread()
{
// Make sure that there is always at least one thread...
- if (GetNumThreads() == 1) return false;
+ if (m_threads.GetSize() == 1) return false;
// Note the current thread and set the current back one.
const int kill_thread = m_cur_thread;
@@ -1105,13 +1106,13 @@
m_thread_id_chart ^= 1 << m_threads[kill_thread].GetID();
// Copy the last thread into the kill position
- const int last_thread = GetNumThreads() - 1;
+ const int last_thread = m_threads.GetSize() - 1;
if (last_thread != kill_thread) {
m_threads[kill_thread] = m_threads[last_thread];
}
// Kill the thread!
- m_threads.Resize(GetNumThreads() - 1);
+ m_threads.Resize(m_threads.GetSize() - 1);
if (m_cur_thread > kill_thread) m_cur_thread--;
@@ -1184,23 +1185,23 @@
bool cHardwareCPU::Allocate_Necro(const int new_size)
{
- GetMemory().ResizeOld(new_size);
+ m_memory.ResizeOld(new_size);
return true;
}
bool cHardwareCPU::Allocate_Random(cAvidaContext& ctx, const int old_size, const int new_size)
{
- GetMemory().Resize(new_size);
+ m_memory.Resize(new_size);
for (int i = old_size; i < new_size; i++) {
- GetMemory()[i] = m_inst_set->GetRandomInst(ctx);
+ m_memory[i] = m_inst_set->GetRandomInst(ctx);
}
return true;
}
bool cHardwareCPU::Allocate_Default(const int new_size)
{
- GetMemory().Resize(new_size);
+ m_memory.Resize(new_size);
// New space already defaults to default instruction...
@@ -1220,7 +1221,7 @@
return false;
}
- const int old_size = GetMemory().GetSize();
+ const int old_size = m_memory.GetSize();
const int new_size = old_size + allocated_size;
// Make sure that the new size is in range.
@@ -1268,9 +1269,8 @@
int cHardwareCPU::GetCopiedSize(const int parent_size, const int child_size)
{
int copied_size = 0;
- const cCPUMemory& memory = GetMemory();
for (int i = parent_size; i < parent_size + child_size; i++) {
- if (memory.FlagCopied(i)) copied_size++;
+ if (m_memory.FlagCopied(i)) copied_size++;
}
return copied_size;
}
@@ -1279,7 +1279,7 @@
bool cHardwareCPU::Divide_Main(cAvidaContext& ctx, const int div_point,
const int extra_lines, double mut_multiplier)
{
- const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+ const int child_size = m_memory.GetSize() - div_point - extra_lines;
// Make sure this divide will produce a viable offspring.
const bool viable = Divide_CheckViable(ctx, div_point, child_size);
@@ -1291,7 +1291,7 @@
child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
// Cut off everything in this memory past the divide point.
- GetMemory().Resize(div_point);
+ m_memory.Resize(div_point);
// Handle Divide Mutations...
Divide_DoMutations(ctx, mut_multiplier);
@@ -1336,7 +1336,7 @@
{
//cStats stats = m_world->GetStats();
- const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+ const int child_size = m_memory.GetSize() - div_point - extra_lines;
// Make sure this divide will produce a viable offspring.
const bool viable = Divide_CheckViable(ctx, div_point, child_size);
@@ -1348,7 +1348,7 @@
child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
// Cut off everything in this memory past the divide point.
- GetMemory().Resize(div_point);
+ m_memory.Resize(div_point);
unsigned
totalMutations = 0,
@@ -1427,7 +1427,7 @@
{
//cStats stats = m_world->GetStats();
- const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+ const int child_size = m_memory.GetSize() - div_point - extra_lines;
// Make sure this divide will produce a viable offspring.
const bool viable = Divide_CheckViable(ctx, div_point, child_size);
@@ -1439,7 +1439,7 @@
child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
// Cut off everything in this memory past the divide point.
- GetMemory().Resize(div_point);
+ m_memory.Resize(div_point);
unsigned
totalMutations = 0,
@@ -1518,7 +1518,7 @@
{
//cStats stats = m_world->GetStats();
- const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+ const int child_size = m_memory.GetSize() - div_point - extra_lines;
// Make sure this divide will produce a viable offspring.
const bool viable = Divide_CheckViable(ctx, div_point, child_size);
@@ -1530,7 +1530,7 @@
child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
// Cut off everything in this memory past the divide point.
- GetMemory().Resize(div_point);
+ m_memory.Resize(div_point);
unsigned
totalMutations = 0,
@@ -2423,7 +2423,7 @@
{
const int src = REG_BX;
const int dst = REG_AX;
- const int size = GetMemory().GetSize();
+ const int size = m_memory.GetSize();
if (Allocate_Main(ctx, GetRegister(src))) {
GetRegister(dst) = size;
return true;
@@ -2453,18 +2453,18 @@
bool cHardwareCPU::Inst_CDivide(cAvidaContext& ctx)
{
- return Divide_Main(ctx, GetMemory().GetSize() / 2);
+ return Divide_Main(ctx, m_memory.GetSize() / 2);
}
bool cHardwareCPU::Inst_CAlloc(cAvidaContext& ctx)
{
- return Allocate_Main(ctx, GetMemory().GetSize());
+ return Allocate_Main(ctx, m_memory.GetSize());
}
bool cHardwareCPU::Inst_MaxAlloc(cAvidaContext& ctx) // Allocate maximal more
{
const int dst = REG_AX;
- const int cur_size = GetMemory().GetSize();
+ const int cur_size = m_memory.GetSize();
const int alloc_size = Min((int) (m_world->GetConfig().CHILD_SIZE_RANGE.Get() * cur_size),
MAX_CREATURE_SIZE - cur_size);
if (Allocate_Main(ctx, alloc_size)) {
@@ -2477,7 +2477,7 @@
bool cHardwareCPU::Inst_MaxAllocMoveWriteHead(cAvidaContext& ctx) // Allocate maximal more
{
const int dst = REG_AX;
- const int cur_size = GetMemory().GetSize();
+ const int cur_size = m_memory.GetSize();
const int alloc_size = Min((int) (m_world->GetConfig().CHILD_SIZE_RANGE.Get() * cur_size),
MAX_CREATURE_SIZE - cur_size);
if (Allocate_Main(ctx, alloc_size)) {
@@ -2545,12 +2545,12 @@
// Setup child
cCPUMemory& child_genome = organism->ChildGenome();
- child_genome = GetMemory();
- organism->GetPhenotype().SetLinesCopied(GetMemory().GetSize());
+ child_genome = m_memory;
+ organism->GetPhenotype().SetLinesCopied(m_memory.GetSize());
int lines_executed = 0;
- for ( int i = 0; i < GetMemory().GetSize(); i++ ) {
- if ( GetMemory().FlagExecuted(i)) lines_executed++;
+ for ( int i = 0; i < m_memory.GetSize(); i++ ) {
+ if ( m_memory.FlagExecuted(i)) lines_executed++;
}
organism->GetPhenotype().SetLinesExecuted(lines_executed);
@@ -2559,7 +2559,7 @@
// Perform Copy Mutations...
if (organism->GetCopyMutProb() > 0) { // Skip this if no mutations....
- for (int i = 0; i < GetMemory().GetSize(); i++) {
+ for (int i = 0; i < m_memory.GetSize(); i++) {
if (organism->TestCopyMut(ctx)) {
child_genome[i] = m_inst_set->GetRandomInst(ctx);
//organism->GetPhenotype().IsMutated() = true;
@@ -2686,8 +2686,8 @@
}
// Since its legal to cut out the injected piece, do so.
- cGenome inject_code( cGenomeUtil::Crop(GetMemory(), start_pos, end_pos) );
- GetMemory().Remove(start_pos, inject_size);
+ cGenome inject_code( cGenomeUtil::Crop(m_memory, start_pos, end_pos) );
+ m_memory.Remove(start_pos, inject_size);
// If we don't have a host, stop here.
cOrganism * host_organism = organism->GetNeighbor();
@@ -2753,8 +2753,8 @@
}
// Since its legal to cut out the injected piece, do so.
- cGenome inject_code( cGenomeUtil::Crop(GetMemory(), start_pos, end_pos) );
- GetMemory().Remove(start_pos, inject_size);
+ cGenome inject_code( cGenomeUtil::Crop(m_memory, start_pos, end_pos) );
+ m_memory.Remove(start_pos, inject_size);
// If we don't have a host, stop here.
cOrganism * host_organism = organism->GetNeighbor();
@@ -3659,7 +3659,7 @@
bool cHardwareCPU::Inst_MemSize(cAvidaContext& ctx)
{
- GetRegister(FindModifiedRegister(REG_BX)) = GetMemory().GetSize();
+ GetRegister(FindModifiedRegister(REG_BX)) = m_memory.GetSize();
return true;
}
@@ -3967,8 +3967,8 @@
AdjustHeads();
const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
- if (child_end == 0) child_end = GetMemory().GetSize();
- const int extra_lines = GetMemory().GetSize() - child_end;
+ if (child_end == 0) child_end = m_memory.GetSize();
+ const int extra_lines = m_memory.GetSize() - child_end;
bool ret_val = Divide_Main(ctx, divide_pos, extra_lines, mut_multiplier);
// Re-adjust heads.
AdjustHeads();
@@ -3990,8 +3990,8 @@
AdjustHeads();
const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
- if (child_end == 0) child_end = GetMemory().GetSize();
- const int extra_lines = GetMemory().GetSize() - child_end;
+ if (child_end == 0) child_end = m_memory.GetSize();
+ const int extra_lines = m_memory.GetSize() - child_end;
bool ret_val = Divide_MainRS(ctx, divide_pos, extra_lines, 1);
// Re-adjust heads.
AdjustHeads();
@@ -4007,8 +4007,8 @@
AdjustHeads();
const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
- if (child_end == 0) child_end = GetMemory().GetSize();
- const int extra_lines = GetMemory().GetSize() - child_end;
+ if (child_end == 0) child_end = m_memory.GetSize();
+ const int extra_lines = m_memory.GetSize() - child_end;
bool ret_val = Divide_Main1RS(ctx, divide_pos, extra_lines, 1);
// Re-adjust heads.
AdjustHeads();
@@ -4024,8 +4024,8 @@
AdjustHeads();
const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
- if (child_end == 0) child_end = GetMemory().GetSize();
- const int extra_lines = GetMemory().GetSize() - child_end;
+ if (child_end == 0) child_end = m_memory.GetSize();
+ const int extra_lines = m_memory.GetSize() - child_end;
bool ret_val = Divide_Main2RS(ctx, divide_pos, extra_lines, 1);
// Re-adjust heads.
AdjustHeads();
@@ -4498,13 +4498,13 @@
if (_num_bits == 0) _num_bits = max_bits;
// Enforce a boundary, sometimes -1 can be passed for _pos
- int j = _pos + GetMemory().GetSize();
- j %= GetMemory().GetSize();
+ int j = _pos + m_memory.GetSize();
+ j %= m_memory.GetSize();
assert(j >=0);
- assert(j < GetMemory().GetSize());
+ assert(j < m_memory.GetSize());
while (code_size < _num_bits)
{
- unsigned int inst_code = (unsigned int) GetInstSet().GetInstructionCode( (GetMemory())[j] );
+ unsigned int inst_code = (unsigned int) GetInstSet().GetInstructionCode(m_memory[j]);
// shift bits in, one by one ... excuse the counter variable pun
for (int code_on = 0; (code_size < _num_bits) && (code_on < m_world->GetConfig().INST_CODE_LENGTH.Get()); code_on++)
{
@@ -4524,8 +4524,8 @@
}
// move back one inst
- j += GetMemory().GetSize() + _dir;
- j %= GetMemory().GetSize();
+ j += m_memory.GetSize() + _dir;
+ j %= m_memory.GetSize();
}
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareCPU.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -261,8 +261,10 @@
// -------- Memory Manipulation --------
const cCPUMemory& GetMemory() const { return m_memory; }
cCPUMemory& GetMemory() { return m_memory; }
+ int GetMemSize() const { return m_memory.GetSize(); }
const cCPUMemory& GetMemory(int value) const { return m_memory; }
cCPUMemory& GetMemory(int value) { return m_memory; }
+ int GetMemSize(int value) const { return m_memory.GetSize(); }
int GetNumMemSpaces() const { return 1; }
@@ -604,12 +606,12 @@
inline void cHardwareCPU::ThreadNext()
{
m_cur_thread++;
- if (m_cur_thread >= GetNumThreads()) m_cur_thread = 0;
+ if (m_cur_thread >= m_threads.GetSize()) m_cur_thread = 0;
}
inline void cHardwareCPU::ThreadPrev()
{
- if (m_cur_thread == 0) m_cur_thread = GetNumThreads() - 1;
+ if (m_cur_thread == 0) m_cur_thread = m_threads.GetSize() - 1;
else m_cur_thread--;
}
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareExperimental.cc 2008-01-28 12:54:10 UTC (rev 2285)
@@ -280,7 +280,7 @@
phenotype.IncCPUCyclesUsed();
if (!m_world->GetConfig().NO_CPU_CYCLE_TIME.Get()) phenotype.IncTimeUsed();
- const int num_threads = GetNumThreads();
+ const int num_threads = m_threads.GetSize();
// If we have threads turned on and we executed each thread in a single
// timestep, adjust the number of instructions executed accordingly.
@@ -289,7 +289,9 @@
for (int i = 0; i < num_inst_exec; i++) {
// Setup the hardware for the next instruction to be executed.
- ThreadNext();
+ m_cur_thread++;
+ if (m_cur_thread >= num_threads) m_cur_thread = 0;
+
m_advance_ip = true;
IP().Adjust();
@@ -436,7 +438,7 @@
if (!m_memory.OK()) result = false;
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
if (m_threads[i].stack.OK() == false) result = false;
if (m_threads[i].next_label.OK() == false) result = false;
}
@@ -475,8 +477,8 @@
fp << setfill(' ') << setbase(10) << endl;
}
- fp << " Mem (" << GetMemory().GetSize() << "):"
- << " " << GetMemory().AsString()
+ fp << " Mem (" << m_memory.GetSize() << "):"
+ << " " << m_memory.AsString()
<< endl;
@@ -602,7 +604,7 @@
{
// Make sure the genome will be below max size after injection.
- const int new_size = injection.GetSize() + GetMemory().GetSize();
+ const int new_size = injection.GetSize() + m_memory.GetSize();
if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
const int inject_line = FindLabelFull(in_label).GetPosition();
@@ -655,7 +657,7 @@
void cHardwareExperimental::AdjustHeads()
{
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
for (int j = 0; j < NUM_HEADS; j++) {
m_threads[i].heads[j].Adjust();
}
@@ -691,7 +693,7 @@
bool cHardwareExperimental::ForkThread()
{
- const int num_threads = GetNumThreads();
+ const int num_threads = m_threads.GetSize();
if (num_threads == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
// Make room for the new thread.
@@ -714,7 +716,7 @@
bool cHardwareExperimental::KillThread()
{
// Make sure that there is always at least one thread...
- if (GetNumThreads() == 1) return false;
+ if (m_threads.GetSize() == 1) return false;
// Note the current thread and set the current back one.
const int kill_thread = m_cur_thread;
@@ -724,13 +726,13 @@
m_thread_id_chart ^= 1 << m_threads[kill_thread].GetID();
// Copy the last thread into the kill position
- const int last_thread = GetNumThreads() - 1;
+ const int last_thread = m_threads.GetSize() - 1;
if (last_thread != kill_thread) {
m_threads[kill_thread] = m_threads[last_thread];
}
// Kill the thread!
- m_threads.Resize(GetNumThreads() - 1);
+ m_threads.Resize(m_threads.GetSize() - 1);
if (m_cur_thread > kill_thread) m_cur_thread--;
@@ -803,23 +805,23 @@
bool cHardwareExperimental::Allocate_Necro(const int new_size)
{
- GetMemory().ResizeOld(new_size);
+ m_memory.ResizeOld(new_size);
return true;
}
bool cHardwareExperimental::Allocate_Random(cAvidaContext& ctx, const int old_size, const int new_size)
{
- GetMemory().Resize(new_size);
+ m_memory.Resize(new_size);
for (int i = old_size; i < new_size; i++) {
- GetMemory()[i] = m_inst_set->GetRandomInst(ctx);
+ m_memory[i] = m_inst_set->GetRandomInst(ctx);
}
return true;
}
bool cHardwareExperimental::Allocate_Default(const int new_size)
{
- GetMemory().Resize(new_size);
+ m_memory.Resize(new_size);
// New space already defaults to default instruction...
@@ -839,7 +841,7 @@
return false;
}
- const int old_size = GetMemory().GetSize();
+ const int old_size = m_memory.GetSize();
const int new_size = old_size + allocated_size;
// Make sure that the new size is in range.
@@ -887,9 +889,8 @@
int cHardwareExperimental::GetCopiedSize(const int parent_size, const int child_size)
{
int copied_size = 0;
- const cCPUMemory& memory = GetMemory();
for (int i = parent_size; i < parent_size + child_size; i++) {
- if (memory.FlagCopied(i)) copied_size++;
+ if (m_memory.FlagCopied(i)) copied_size++;
}
return copied_size;
}
@@ -898,7 +899,7 @@
bool cHardwareExperimental::Divide_Main(cAvidaContext& ctx, const int div_point,
const int extra_lines, double mut_multiplier)
{
- const int child_size = GetMemory().GetSize() - div_point - extra_lines;
+ const int child_size = m_memory.GetSize() - div_point - extra_lines;
// Make sure this divide will produce a viable offspring.
const bool viable = Divide_CheckViable(ctx, div_point, child_size);
@@ -910,7 +911,7 @@
child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
// Cut off everything in this memory past the divide point.
- GetMemory().Resize(div_point);
+ m_memory.Resize(div_point);
// Handle Divide Mutations...
Divide_DoMutations(ctx, mut_multiplier);
@@ -1100,7 +1101,7 @@
bool cHardwareExperimental::Inst_HeadAlloc(cAvidaContext& ctx) // Allocate maximal more
{
const int dst = FindModifiedRegister(REG_AX);
- const int cur_size = GetMemory().GetSize();
+ const int cur_size = m_memory.GetSize();
const int alloc_size = Min((int) (m_world->GetConfig().CHILD_SIZE_RANGE.Get() * cur_size),
MAX_CREATURE_SIZE - cur_size);
if (Allocate_Main(ctx, alloc_size)) {
@@ -1166,8 +1167,8 @@
AdjustHeads();
const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
int child_end = GetHead(nHardware::HEAD_WRITE).GetPosition();
- if (child_end == 0) child_end = GetMemory().GetSize();
- const int extra_lines = GetMemory().GetSize() - child_end;
+ if (child_end == 0) child_end = m_memory.GetSize();
+ const int extra_lines = m_memory.GetSize() - child_end;
bool ret_val = Divide_Main(ctx, divide_pos, extra_lines, 1.0);
// Re-adjust heads.
AdjustHeads();
@@ -1401,7 +1402,7 @@
GetRegister(reg_used) = 0;
// @JEB HACK! -- All kinds of bad stuff happens if execution length is zero. For now:
- if (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2) GetMemory().SetFlagExecuted(0);
+ if (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2) m_memory.SetFlagExecuted(0);
break;
case 1: // Death to organisms that refuse to use promoters!
organism->Die();
@@ -1541,13 +1542,13 @@
if (_num_bits == 0) _num_bits = max_bits;
// Enforce a boundary, sometimes -1 can be passed for _pos
- int j = _pos + GetMemory().GetSize();
- j %= GetMemory().GetSize();
+ int j = _pos + m_memory.GetSize();
+ j %= m_memory.GetSize();
assert(j >=0);
- assert(j < GetMemory().GetSize());
+ assert(j < m_memory.GetSize());
while (code_size < _num_bits)
{
- unsigned int inst_code = (unsigned int) GetInstSet().GetInstructionCode( (GetMemory())[j] );
+ unsigned int inst_code = (unsigned int) GetInstSet().GetInstructionCode(m_memory[j]);
// shift bits in, one by one ... excuse the counter variable pun
for (int code_on = 0; (code_size < _num_bits) && (code_on < m_world->GetConfig().INST_CODE_LENGTH.Get()); code_on++)
{
@@ -1567,8 +1568,8 @@
}
// move back one inst
- j += GetMemory().GetSize() + _dir;
- j %= GetMemory().GetSize();
+ j += m_memory.GetSize() + _dir;
+ j %= m_memory.GetSize();
}
@@ -1651,7 +1652,7 @@
// Perform Copy Mutations...
if (organism->GetCopyMutProb() > 0) { // Skip this if no mutations....
- for (int i = 0; i < GetMemory().GetSize(); i++) {
+ for (int i = 0; i < m_memory.GetSize(); i++) {
if (organism->TestCopyMut(ctx)) child_genome[i] = m_inst_set->GetRandomInst(ctx);
}
}
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareExperimental.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -264,8 +264,10 @@
// -------- Memory Manipulation --------
const cCPUMemory& GetMemory() const { return m_memory; }
cCPUMemory& GetMemory() { return m_memory; }
+ int GetMemSize() const { return m_memory.GetSize(); }
const cCPUMemory& GetMemory(int value) const { return m_memory; }
cCPUMemory& GetMemory(int value) { return m_memory; }
+ int GetMemSize(int value) const { return m_memory.GetSize(); }
int GetNumMemSpaces() const { return 1; }
@@ -393,12 +395,12 @@
inline void cHardwareExperimental::ThreadNext()
{
m_cur_thread++;
- if (m_cur_thread >= GetNumThreads()) m_cur_thread = 0;
+ if (m_cur_thread >= m_threads.GetSize()) m_cur_thread = 0;
}
inline void cHardwareExperimental::ThreadPrev()
{
- if (m_cur_thread == 0) m_cur_thread = GetNumThreads() - 1;
+ if (m_cur_thread == 0) m_cur_thread = m_threads.GetSize() - 1;
else m_cur_thread--;
}
Modified: development/source/cpu/cHardwareGX.h
===================================================================
--- development/source/cpu/cHardwareGX.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareGX.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -342,8 +342,10 @@
// so be careful to fix these when changing the programid list.
const cCPUMemory& GetMemory() const { assert(m_current); return m_current->m_memory; }
cCPUMemory& GetMemory() { assert(m_current); return m_current->m_memory; }
+ int GetMemSize() const { assert(m_current); return m_current->m_memory.GetSize(); }
const cCPUMemory& GetMemory(int value) const { return m_programids[value]->m_memory; }
cCPUMemory& GetMemory(int value) { return m_programids[value]->m_memory; }
+ int GetMemSize(int value) const { return m_programids[value]->m_memory.GetSize(); }
int GetNumMemSpaces() const { return m_programids.size(); }
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareSMT.cc 2008-01-28 12:54:10 UTC (rev 2285)
@@ -196,11 +196,13 @@
cPhenotype& phenotype = organism->GetPhenotype();
phenotype.IncTimeUsed();
- const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? GetNumThreads() : 1;
+ const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? m_threads.GetSize() : 1;
for (int i = 0; i < num_inst_exec; i++) {
// Setup the hardware for the next instruction to be executed.
- ThreadNext();
+ m_cur_thread++;
+ if (m_cur_thread >= m_threads.GetSize()) m_cur_thread = 0;
+
if (!ThreadIsRunning()) continue;
AdvanceIP() = true;
@@ -304,7 +306,7 @@
if (!m_mem_array[i].OK()) return false;
}
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
for(int j=0; j < NUM_LOCAL_STACKS; j++)
if (m_threads[i].local_stacks[j].OK() == false) return false;
if (m_threads[i].next_label.OK() == false) return false;
@@ -955,7 +957,7 @@
}
else if (div_method == DIVIDE_METHOD_BIRTH)
{
- if((!organism->GetPhenotype().IsModified() && GetNumThreads() > 1) || GetNumThreads() > 2) {
+ if((!organism->GetPhenotype().IsModified() && m_threads.GetSize() > 1) || m_threads.GetSize() > 2) {
ThreadKill(m_cur_thread + 1);
} else {
//this will reset the current thread's heads and stacks. It will
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareSMT.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -232,8 +232,10 @@
// -------- Memory Manipulation --------
cCPUMemory& GetMemory() { return m_mem_array[0]; }
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
+ int GetMemSize() const { return m_mem_array[0].GetSize(); }
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 GetMemSize(int mem_space) const { return m_mem_array[NormalizeMemSpace(mem_space)].GetSize(); }
int GetNumMemSpaces() const { return m_mem_array.GetSize(); }
Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareTransSMT.cc 2008-01-28 12:54:10 UTC (rev 2285)
@@ -194,11 +194,13 @@
cPhenotype& phenotype = organism->GetPhenotype();
phenotype.IncTimeUsed();
- const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? GetNumThreads() : 1;
+ const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? m_threads.GetSize() : 1;
for (int i = 0; i < num_inst_exec; i++) {
// Setup the hardware for the next instruction to be executed.
- ThreadNext();
+ m_cur_thread++;
+ if (m_cur_thread >= m_threads.GetSize()) m_cur_thread = 0;
+
if (!ThreadIsRunning()) continue;
AdvanceIP() = true;
@@ -301,7 +303,7 @@
if (!m_mem_array[i].OK()) return false;
}
- for (int i = 0; i < GetNumThreads(); i++) {
+ for (int i = 0; i < m_threads.GetSize(); i++) {
for(int j=0; j < NUM_LOCAL_STACKS; j++)
if (m_threads[i].local_stacks[j].OK() == false) return false;
if (m_threads[i].next_label.OK() == false) return false;
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHardwareTransSMT.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -231,8 +231,10 @@
// -------- Memory Manipulation --------
cCPUMemory& GetMemory() { return m_mem_array[0]; }
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
+ int GetMemSize() const { return m_mem_array[0].GetSize(); }
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 GetMemSize(int mem_space) const { return m_mem_array[NormalizeMemSpace(mem_space)].GetSize(); }
int GetNumMemSpaces() const { return m_mem_array.GetSize(); }
Modified: development/source/cpu/cHeadCPU.cc
===================================================================
--- development/source/cpu/cHeadCPU.cc 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHeadCPU.cc 2008-01-28 12:54:10 UTC (rev 2285)
@@ -32,18 +32,22 @@
{
assert(m_mem_space >= 0);
// Ensure that m_mem_space is valid
- if (m_mem_space >= m_hardware->GetNumMemSpaces()) m_mem_space %= m_hardware->GetNumMemSpaces();
+ if (m_mem_space != 0 && m_mem_space >= m_hardware->GetNumMemSpaces()) m_mem_space %= m_hardware->GetNumMemSpaces();
- const int mem_size = GetMemory().GetSize();
+ const int mem_size = GetMemSize();
// If we are still in range, stop here!
if (m_position >= 0 && m_position < mem_size) return;
// If the memory is gone, just stick it at the begining of its parent.
// @DMB - note: this violates the circularity of memory spaces. You can loop forward, but not backward.
- if (mem_size == 0 || m_position < 0) m_position = 0;
+ if (mem_size == 0 || m_position < 0) {
+ m_position = 0;
+ return;
+ }
// position back at the begining of the creature as necessary.
- m_position %= GetMemory().GetSize();
+ if (m_position < (2 * mem_size)) m_position -= mem_size;
+ else m_position %= mem_size;
}
Modified: development/source/cpu/cHeadCPU.h
===================================================================
--- development/source/cpu/cHeadCPU.h 2008-01-28 11:48:55 UTC (rev 2284)
+++ development/source/cpu/cHeadCPU.h 2008-01-28 12:54:10 UTC (rev 2285)
@@ -66,6 +66,7 @@
inline const cCPUMemory& GetMemory() const { return m_hardware->GetMemory(m_mem_space); }
inline cCPUMemory& GetMemory() { return m_hardware->GetMemory(m_mem_space); }
+ inline int GetMemSize() const { return m_hardware->GetMemSize(m_mem_space); }
void Adjust();
inline void Reset(cHardwareBase* hw, int ms = 0) { m_hardware = hw; m_position = 0; m_mem_space = ms; }
More information about the Avida-cvs
mailing list