From d71db85c711c2f0d1500802237c98cfc19c5420b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 18 Apr 2023 16:55:12 +0200 Subject: [PATCH] Bytecode: move more cached information about current block out of the Evaluate class --- mex/sources/bytecode/Evaluate.cc | 5 ---- mex/sources/bytecode/Evaluate.hh | 35 ++++++++++++++++++++++------ mex/sources/bytecode/Interpreter.cc | 10 ++++++-- mex/sources/bytecode/SparseMatrix.hh | 8 +++++++ preprocessor | 2 +- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc index f664acf7e..c271006cf 100644 --- a/mex/sources/bytecode/Evaluate.cc +++ b/mex/sources/bytecode/Evaluate.cc @@ -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 diff --git a/mex/sources/bytecode/Evaluate.hh b/mex/sources/bytecode/Evaluate.hh index 301b2d8fd..46ccb0815 100644 --- a/mex/sources/bytecode/Evaluate.hh +++ b/mex/sources/bytecode/Evaluate.hh @@ -53,6 +53,9 @@ private: // Index of beginnings of blocks within instructions_list vector 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 &TEF, map, double> &TEFD, map, 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; - 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 { diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index 858fc07ce..eeae7b364 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -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); diff --git a/mex/sources/bytecode/SparseMatrix.hh b/mex/sources/bytecode/SparseMatrix.hh index d6cfcf258..2f69253f4 100644 --- a/mex/sources/bytecode/SparseMatrix.hh +++ b/mex/sources/bytecode/SparseMatrix.hh @@ -218,6 +218,14 @@ protected: map, double> TEFD; map, 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; + 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); diff --git a/preprocessor b/preprocessor index faa129105..34edd4e14 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit faa12910552c82bf5cb92d700bd12817408d22aa +Subproject commit 34edd4e1433ad4047a9b1f5535d9147135f26f53