Bytecode: move more cached information about current block out of the Evaluate class

mr#2134
Sébastien Villemot 2023-04-18 16:55:12 +02:00
parent 36e8062e25
commit d71db85c71
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 45 additions and 15 deletions

View File

@ -2231,12 +2231,7 @@ Evaluate::gotoBlock(int block)
if (fb->op_code != Tags::FBEGINBLOCK)
throw FatalException {"Evaluate::gotoBlock: internal inconsistency"};
Block_Contain = fb->get_Block_Contain();
size = fb->get_size();
type = fb->get_type();
is_linear = fb->get_is_linear();
symbol_table_endo_nbr = fb->get_endo_nbr();
u_count_int = fb->get_u_count_int();
}
void

View File

@ -53,6 +53,9 @@ private:
// Index of beginnings of blocks within instructions_list
vector<size_t> begin_block;
int block_num; // Index of the current block
int size; // Size of the current block
ExpressionType EQN_type;
int EQN_equation, EQN_dvar1;
int EQN_lag1, EQN_lag2, EQN_lag3;
@ -76,13 +79,6 @@ protected:
BasicSymbolTable &symbol_table;
void evaluateBlock(int it_, double *y, const double *ya, int y_size, double *x, int nb_row_x, double *params, const double *steady_y, double *u, int Per_u_, double *T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *r, double *g1, double *jacob, double *jacob_exo, double *jacob_exo_det, bool evaluate, bool no_derivatives);
int block_num; // Index of the current block
int size; // Size of the current block
BlockSimulationType type;
bool is_linear;
int symbol_table_endo_nbr, u_count_int;
vector<Block_contain_type> Block_Contain;
bool steady_state;
/* Prints a bytecode expression in human readable form.
@ -99,6 +95,31 @@ protected:
int getNumberOfTemporaryTerms() const;
auto
getCurrentBlockSize() const
{
return currentBlockTag()->get_size();
}
auto
getCurrentBlockType() const
{
return currentBlockTag()->get_type();
}
auto
isCurrentBlockLinear() const
{
return currentBlockTag()->get_is_linear();
}
auto
getCurrentBlockEquationsAndVariables() const
{
return currentBlockTag()->get_Block_Contain();
}
auto
getCurrentBlockUCount() const
{
return currentBlockTag()->get_u_count_int();
}
auto
getCurrentBlockExogenous() const
{

View File

@ -565,7 +565,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
copy_n(y_save, y_size*(periods+y_kmax+y_kmin), y);
u_count = u_count_saved;
int prev_iter = iter;
Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local);
Simulate_Newton_Two_Boundaries(block_num, y_size, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local);
iter++;
if (iter > prev_iter)
{
@ -589,7 +589,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
compute_complete_2b(false, &res1, &res2, &max_res, &max_res_idx);
cvg = false;
Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local);
Simulate_Newton_Two_Boundaries(block_num, y_size, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local);
max_res = 0; max_res_idx = 0;
}
slowc = 1; // slowc is modified when stack_solve_algo=4, so restore it
@ -692,6 +692,12 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool
for (int current_block : blocks)
{
gotoBlock(current_block);
block_num = current_block;
size = getCurrentBlockSize();
type = getCurrentBlockType();
is_linear = isCurrentBlockLinear();
Block_Contain = getCurrentBlockEquationsAndVariables();
u_count_int = getCurrentBlockUCount();
if (constrained)
check_for_controlled_exo_validity(current_block, sconstrained_extended_path);

View File

@ -218,6 +218,14 @@ protected:
map<pair<int, int>, double> TEFD;
map<tuple<int, int, int>, double> TEFDD;
// Information about the current block
int block_num; // Index of the current block
int size; // Size of the current block
BlockSimulationType type;
bool is_linear;
int u_count_int;
vector<Block_contain_type> Block_Contain;
void compute_block_time(int Per_u_, bool evaluate, bool no_derivatives);
bool compute_complete(bool no_derivatives, double &res1, double &res2, double &max_res, int &max_res_idx);

@ -1 +1 @@
Subproject commit faa12910552c82bf5cb92d700bd12817408d22aa
Subproject commit 34edd4e1433ad4047a9b1f5535d9147135f26f53