[Avida-SVN] r1995 - in development/source: . cpu main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Aug 23 12:45:59 PDT 2007
Author: brysonda
Date: 2007-08-23 15:45:59 -0400 (Thu, 23 Aug 2007)
New Revision: 1995
Modified:
development/source/cpu/cInstSet.cc
development/source/cpu/cInstSet.h
development/source/defs.h
development/source/main/cAvidaConfig.h
Log:
Implement instruction binary code support in cInstSet. Only available via the new format instruction set configuration.
Modified: development/source/cpu/cInstSet.cc
===================================================================
--- development/source/cpu/cInstSet.cc 2007-08-23 17:14:50 UTC (rev 1994)
+++ development/source/cpu/cInstSet.cc 2007-08-23 19:45:59 UTC (rev 1995)
@@ -158,7 +158,15 @@
// Double
schema.AddEntry("prob_fail", 0, 0.0);
+ // String
+ schema.AddEntry("inst_code", 0, "");
+
+ // Ensure that the instruction code length is in the range of bits supported by the int type
+ int inst_code_len = m_world->GetConfig().INST_CODE_LENGTH.Get();
+ if ((unsigned)inst_code_len > (sizeof(int) * 8)) inst_code_len = sizeof(int) * 8;
+ else if (inst_code_len <= 0) inst_code_len = 1;
+
tList<cString> errors;
bool success = true;
for (int line_id = 0; line_id < sl.GetSize(); line_id++) {
@@ -194,7 +202,6 @@
continue;
}
-
int redundancy = args->GetInt(0);
if (redundancy < 0) {
m_world->GetDriver().NotifyWarning(cString("Instruction '") + inst_name + "' has negative redundancy, ignoring.");
@@ -225,6 +232,38 @@
m_lib_name_map[inst_id].prob_fail = args->GetDouble(0);
m_lib_name_map[inst_id].addl_time_cost = args->GetInt(4);
+
+ // Parse the instruction code
+ cString inst_code = args->GetString(0);
+ if (inst_code == "") {
+ switch (m_world->GetConfig().INST_CODE_DEFAULT_TYPE.Get()) {
+ case INST_CODE_ZEROS:
+ m_lib_name_map[inst_id].inst_code = 0;
+ break;
+ case INST_CODE_INSTNUM:
+ m_lib_name_map[inst_id].inst_code = ((~0) >> ((sizeof(int) * 8) - inst_code_len)) & inst_id;
+ break;
+ default:
+ errors.PushRear(new cString("Invalid default instruction code type."));
+ success = false;
+ break;
+ }
+ } else {
+ const int iclidx = inst_code.GetSize() - 1;
+ int inst_code_val = 0;
+ for (int i = 0; i < inst_code_len && i <= iclidx; i++) {
+ inst_code_val <<= 1;
+ if (inst_code[iclidx - i] == '1') inst_code_val |= 1;
+ else if (inst_code[iclidx - i] != '0') {
+ errors.PushRear(new cString("Invalid character in instruction code, must be 0 or 1."));
+ success = false;
+ break;
+ }
+ }
+
+ m_lib_name_map[inst_id].inst_code = inst_code_val;
+ }
+
// If this is a nop, add it to the proper mappings
if ((*m_inst_lib)[fun_id].IsNop()) {
@@ -322,6 +361,7 @@
m_lib_name_map[inst_id].energy_cost = energy_cost;
m_lib_name_map[inst_id].prob_fail = prob_fail;
m_lib_name_map[inst_id].addl_time_cost = addl_time_cost;
+ m_lib_name_map[inst_id].inst_code = 0;
const int total_redundancy = m_mutation_chart.GetSize();
m_mutation_chart.Resize(total_redundancy + redundancy);
Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h 2007-08-23 17:14:50 UTC (rev 1994)
+++ development/source/cpu/cInstSet.h 2007-08-23 19:45:59 UTC (rev 1995)
@@ -72,6 +72,7 @@
int energy_cost; // energy required to execute.
double prob_fail; // probability of failing to execute inst
int addl_time_cost; // additional time added to age for executing instruction
+ int inst_code; // instruction binary code
};
tSmartArray<sInstEntry> m_lib_name_map;
@@ -95,12 +96,15 @@
// 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 GetRedundancy(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].redundancy; }
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; }
int GetEnergyCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].energy_cost; }
+ double GetProbFail(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].prob_fail; }
int GetAddlTimeCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].addl_time_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 GetInstructionCode(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].inst_code; }
+
int GetLibFunctionIndex(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].lib_fun_id; }
int GetNopMod(const cInstruction& inst) const
Modified: development/source/defs.h
===================================================================
--- development/source/defs.h 2007-08-23 17:14:50 UTC (rev 1994)
+++ development/source/defs.h 2007-08-23 19:45:59 UTC (rev 1995)
@@ -158,6 +158,12 @@
BASE_MERIT_NUM_BONUS_INST
};
+enum eINST_CODE_DEFAULT
+{
+ INST_CODE_ZEROS = 0,
+ INST_CODE_INSTNUM
+};
+
enum eVerbosity {
VERBOSE_SILENT = 0, // No output at all
VERBOSE_NORMAL, // Notification at start of commands.
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2007-08-23 17:14:50 UTC (rev 1994)
+++ development/source/main/cAvidaConfig.h 2007-08-23 19:45:59 UTC (rev 1995)
@@ -471,6 +471,8 @@
CONFIG_ADD_VAR(PROMOTER_BG_STRENGTH, double, 0, "Probability of positions that are not promoter\ninstructions initiating execution (promoters are 1).");
CONFIG_ADD_VAR(REGULATION_STRENGTH, double, 1, "Strength added or subtracted to a promoter by regulation.");
CONFIG_ADD_VAR(REGULATION_DECAY_FRAC, double, 0.1, "Fraction of regulation that decays away. \nMax regulation = 2^(REGULATION_STRENGTH/REGULATION_DECAY_FRAC)");
+ CONFIG_ADD_VAR(INST_CODE_LENGTH, int, 4, "Instruction binary code length (number of bits)");
+ CONFIG_ADD_VAR(INST_CODE_DEFAULT_TYPE, int, 0, "Default value of instruction binary code value.\n0 = All zeros\n1 = Based of the instruction number");
CONFIG_ADD_GROUP(COLORS_GROUP, "Output colors for when data files are printed in HTML mode.\nThere are two sets of these; the first are for lineages,\nand the second are for mutation tests.");
CONFIG_ADD_VAR(COLOR_DIFF, cString, "CCCCFF", "Color to flag stat that has changed since parent.");
More information about the Avida-cvs
mailing list