From cbd1e8d8850ea4832cad32b5a00be39d78e47ad5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 7 Mar 2024 15:17:40 +0100
Subject: [PATCH] Bytecode: merge FSTPG3 opcode into FSTPG2

---
 src/Bytecode.hh  | 12 +-----------
 src/ModelTree.hh | 10 +++-------
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/src/Bytecode.hh b/src/Bytecode.hh
index 2c1e3083..f2d30ffc 100644
--- a/src/Bytecode.hh
+++ b/src/Bytecode.hh
@@ -75,8 +75,7 @@ enum class Tag
   FSTPR, // Stores a residual from the stack
 
   FSTPG,  // Stores the derivative of a simple (single-equation) block in simulate mode
-  FSTPG2, // Stores a derivative matrix for a static model from the stack
-  FSTPG3, // Stores a derivative matrix for a dynamic model from the stack
+  FSTPG2, // Stores the derivative matrix of a block in evaluate mode
 
   FUNARY,   // A unary operator
   FBINARY,  // A binary operator
@@ -292,15 +291,6 @@ struct FSTPG2 final : public Instruction
   }
 };
 
-struct FSTPG3 final : public Instruction
-{
-  const int row, col, lag, col_pos;
-  FSTPG3(int row_arg, int col_arg, int lag_arg, int col_pos_arg) :
-      Instruction {Tag::FSTPG3}, row {row_arg}, col {col_arg}, lag {lag_arg}, col_pos {col_pos_arg}
-  {
-  }
-};
-
 struct FUNARY final : public Instruction
 {
   const UnaryOpcode op_code;
diff --git a/src/ModelTree.hh b/src/ModelTree.hh
index 169d52a4..9edcb21e 100644
--- a/src/ModelTree.hh
+++ b/src/ModelTree.hh
@@ -1687,7 +1687,7 @@ ModelTree::writeBytecodeHelper(Bytecode::Writer& code_file) const
         {
           // Bytecode MEX uses a separate matrix for exogenous and exodet Jacobians
           int jacob_col {type == SymbolType::endogenous ? getJacobianCol(deriv_id, false) : tsid};
-          code_file << Bytecode::FSTPG3 {eq, tsid, lag, jacob_col};
+          code_file << Bytecode::FSTPG2 {eq, jacob_col};
         }
       else
         code_file << Bytecode::FSTPG2 {eq, tsid};
@@ -1907,12 +1907,8 @@ ModelTree::writeBlockBytecodeHelper(Bytecode::Writer& code_file, int block,
       d->writeBytecodeOutput(code_file, output_type, temporary_terms_union,
                              blocks_temporary_terms_idxs, tef_terms);
       assert(eq >= block_recursive);
-      if constexpr (dynamic)
-        code_file << Bytecode::FSTPG3 {eq - block_recursive, var, lag,
-                                       getBlockJacobianEndoCol(block, var, lag)};
-      else
-        code_file << Bytecode::FSTPG2 {eq - block_recursive,
-                                       getBlockJacobianEndoCol(block, var, lag)};
+      code_file << Bytecode::FSTPG2 {eq - block_recursive,
+                                     getBlockJacobianEndoCol(block, var, lag)};
     }
 
   // Update jump offset for previous JMP
-- 
GitLab