[Avida-SVN] r1483 - development/source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Apr 18 11:42:35 PDT 2007
Author: brysonda
Date: 2007-04-18 14:42:35 -0400 (Wed, 18 Apr 2007)
New Revision: 1483
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cHardwareTransSMT.cc
development/source/cpu/cHardwareTransSMT.h
Log:
Add conditional flags in hardware objects that disable instruction cost lookups when either or both first time and per-execution costs are all zero. On Power Mac G5s this yields a 5.5% performance improvement during normal runs. Other platforms not tested.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareCPU.cc 2007-04-18 18:42:35 UTC (rev 1483)
@@ -381,6 +381,8 @@
#if INSTRUCTION_COSTS
, inst_cost(hardware_cpu.inst_cost)
, inst_ft_cost(hardware_cpu.inst_ft_cost)
+, m_has_costs(hardware_cpu.m_has_costs)
+, m_has_ft_costs(hardware_cpu.m_has_ft_costs)
#endif
{
}
@@ -406,10 +408,15 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ m_has_costs = false;
+ m_has_ft_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
+ if (!m_has_costs && inst_cost[i]) m_has_costs = true;
+
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
}
#endif
@@ -540,17 +547,17 @@
assert(cur_inst.GetOp() < inst_cost.GetSize());
// If first time cost hasn't been paid off...
- if ( inst_ft_cost[cur_inst.GetOp()] > 0 ) {
+ if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
inst_ft_cost[cur_inst.GetOp()]--; // dec cost
return false;
}
// Next, look at the per use cost
- if ( m_inst_set->GetCost(cur_inst) > 0 ) {
- if ( inst_cost[cur_inst.GetOp()] > 1 ){ // if isn't paid off (>1)
- inst_cost[cur_inst.GetOp()]--; // dec cost
+ if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
+ if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
+ inst_cost[cur_inst.GetOp()]--; // dec cost
return false;
- } else { // else, reset cost array
+ } else { // else, reset cost array
inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
}
}
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareCPU.h 2007-04-18 18:42:35 UTC (rev 1483)
@@ -142,6 +142,8 @@
#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
+ bool m_has_costs;
+ bool m_has_ft_costs;
#endif
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareExperimental.cc 2007-04-18 18:42:35 UTC (rev 1483)
@@ -167,6 +167,8 @@
#if INSTRUCTION_COSTS
, inst_cost(hardware_cpu.inst_cost)
, inst_ft_cost(hardware_cpu.inst_ft_cost)
+, m_has_costs(hardware_cpu.m_has_costs)
+, m_has_ft_costs(hardware_cpu.m_has_ft_costs)
#endif
{
}
@@ -192,10 +194,15 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ m_has_costs = false;
+ m_has_ft_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
+ if (!m_has_costs && inst_cost[i]) m_has_costs = true;
+
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
}
#endif
@@ -310,17 +317,17 @@
assert(cur_inst.GetOp() < inst_cost.GetSize());
// If first time cost hasn't been paid off...
- if ( inst_ft_cost[cur_inst.GetOp()] > 0 ) {
+ if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
inst_ft_cost[cur_inst.GetOp()]--; // dec cost
return false;
}
// Next, look at the per use cost
- if ( m_inst_set->GetCost(cur_inst) > 0 ) {
- if ( inst_cost[cur_inst.GetOp()] > 1 ){ // if isn't paid off (>1)
- inst_cost[cur_inst.GetOp()]--; // dec cost
+ if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
+ if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
+ inst_cost[cur_inst.GetOp()]--; // dec cost
return false;
- } else { // else, reset cost array
+ } else { // else, reset cost array
inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
}
}
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareExperimental.h 2007-04-18 18:42:35 UTC (rev 1483)
@@ -140,6 +140,8 @@
#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
+ bool m_has_costs;
+ bool m_has_ft_costs;
#endif
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareSMT.cc 2007-04-18 18:42:35 UTC (rev 1483)
@@ -172,10 +172,15 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ m_has_costs = false;
+ m_has_ft_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
+ if (!m_has_costs && inst_cost[i]) m_has_costs = true;
+
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
}
#endif
@@ -259,17 +264,17 @@
assert(cur_inst.GetOp() < inst_cost.GetSize());
// If first time cost hasn't been paid off...
- if ( inst_ft_cost[cur_inst.GetOp()] > 0 ) {
+ if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
inst_ft_cost[cur_inst.GetOp()]--; // dec cost
return false;
}
// Next, look at the per use cost
- if ( m_inst_set->GetCost(cur_inst) > 0 ) {
- if ( inst_cost[cur_inst.GetOp()] > 1 ){ // if isn't paid off (>1)
- inst_cost[cur_inst.GetOp()]--; // dec cost
+ if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
+ if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
+ inst_cost[cur_inst.GetOp()]--; // dec cost
return false;
- } else { // else, reset cost array
+ } else { // else, reset cost array
inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
}
}
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareSMT.h 2007-04-18 18:42:35 UTC (rev 1483)
@@ -127,6 +127,8 @@
#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
+ bool m_has_costs;
+ bool m_has_ft_costs;
#endif
int m_cur_child;
Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareTransSMT.cc 2007-04-18 18:42:35 UTC (rev 1483)
@@ -169,10 +169,15 @@
const int num_inst_cost = m_inst_set->GetSize();
inst_cost.Resize(num_inst_cost);
inst_ft_cost.Resize(num_inst_cost);
+ m_has_costs = false;
+ m_has_ft_costs = false;
for (int i = 0; i < num_inst_cost; i++) {
inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
+ if (!m_has_costs && inst_cost[i]) m_has_costs = true;
+
inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+ if (!m_has_ft_costs && inst_ft_cost[i]) m_has_ft_costs = true;
}
#endif
@@ -256,23 +261,23 @@
assert(cur_inst.GetOp() < inst_cost.GetSize());
// If first time cost hasn't been paid off...
- if ( inst_ft_cost[cur_inst.GetOp()] > 0 ) {
+ if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
inst_ft_cost[cur_inst.GetOp()]--; // dec cost
return false;
}
// Next, look at the per use cost
- if ( m_inst_set->GetCost(cur_inst) > 0 ) {
- if ( inst_cost[cur_inst.GetOp()] > 1 ){ // if isn't paid off (>1)
- inst_cost[cur_inst.GetOp()]--; // dec cost
+ if (m_has_costs && m_inst_set->GetCost(cur_inst) > 0) {
+ if (inst_cost[cur_inst.GetOp()] > 1) { // if isn't paid off (>1)
+ inst_cost[cur_inst.GetOp()]--; // dec cost
return false;
- } else { // else, reset cost array
+ } else { // else, reset cost array
inst_cost[cur_inst.GetOp()] = m_inst_set->GetCost(cur_inst);
}
}
// Prob of exec
- if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ){
+ if (m_inst_set->GetProbFail(cur_inst) > 0.0) {
return !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
}
#endif
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2007-04-18 15:05:29 UTC (rev 1482)
+++ development/source/cpu/cHardwareTransSMT.h 2007-04-18 18:42:35 UTC (rev 1483)
@@ -126,6 +126,8 @@
#if INSTRUCTION_COSTS
tArray<int> inst_cost;
tArray<int> inst_ft_cost;
+ bool m_has_costs;
+ bool m_has_ft_costs;
#endif
int m_cur_child;
More information about the Avida-cvs
mailing list