diff options
-rw-r--r-- | 020run.cc | 15 | ||||
-rw-r--r-- | 032array.cc | 13 |
2 files changed, 21 insertions, 7 deletions
diff --git a/020run.cc b/020run.cc index 504dca88..b0cf644e 100644 --- a/020run.cc +++ b/020run.cc @@ -71,10 +71,12 @@ void run_current_routine() // Each ingredient loads a vector of values rather than a single value; mu // permits operating on reagents spanning multiple locations. vector<vector<double> > ingredients; - for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) { - ingredients.push_back(read_memory(current_instruction().ingredients.at(i))); - Locations_read[current_recipe_name()] += SIZE(ingredients.back()); - Locations_read_by_instruction[current_instruction().name] += SIZE(ingredients.back()); + if (should_copy_ingredients()) { + for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) { + ingredients.push_back(read_memory(current_instruction().ingredients.at(i))); + Locations_read[current_recipe_name()] += SIZE(ingredients.back()); + Locations_read_by_instruction[current_instruction().name] += SIZE(ingredients.back()); + } } // Instructions below will write to 'products'. vector<vector<double> > products; @@ -118,6 +120,11 @@ void run_current_routine() stop_running_current_routine:; } +bool should_copy_ingredients() { + // End should_copy_ingredients Special-cases + return true; +} + //: Some helpers. //: We'll need to override these later as we change the definition of routine. //: Important that they return referrences into the routine. diff --git a/032array.cc b/032array.cc index 173b773b..9ff28800 100644 --- a/032array.cc +++ b/032array.cc @@ -143,7 +143,7 @@ INDEX, Recipe_ordinal["index"] = INDEX; :(before "End Primitive Recipe Implementations") case INDEX: { - if (SIZE(ingredients) != 2) { + if (SIZE(current_instruction().ingredients) != 2) { raise << current_recipe_name() << ": 'index' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end(); break; } @@ -238,7 +238,7 @@ INDEX_ADDRESS, Recipe_ordinal["index-address"] = INDEX_ADDRESS; :(before "End Primitive Recipe Implementations") case INDEX_ADDRESS: { - if (SIZE(ingredients) != 2) { + if (SIZE(current_instruction().ingredients) != 2) { raise << current_recipe_name() << ": 'index-address' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end(); break; } @@ -313,7 +313,7 @@ LENGTH, Recipe_ordinal["length"] = LENGTH; :(before "End Primitive Recipe Implementations") case LENGTH: { - if (SIZE(ingredients) != 1) { + if (SIZE(current_instruction().ingredients) != 1) { raise << current_recipe_name() << ": 'length' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end(); break; } @@ -330,3 +330,10 @@ case LENGTH: { products.at(0).push_back(Memory[x.value]); break; } + +//: optimization: none of the instructions in this layer use 'ingredients' so +//: stop copying potentially huge arrays into it. +:(before "End should_copy_ingredients Special-cases") +recipe_ordinal r = current_instruction().operation; +if (r == CREATE_ARRAY || r == INDEX || r == INDEX_ADDRESS || r == LENGTH) + return false; |