%------------------------------------------------------------------------------
% $Id: document-morpheo-vhdl_generation-fr-05_02_execute_queue.tex 100 2009-01-08 13:06:27Z rosiere $
%------------------------------------------------------------------------------

\subSection{Tampon entre la boucle d'exécutione et le buffer de réordonnancement}

\subsubSection{Fichier Execute\_queue\_vhdl.cpp}

\lstparam{C++}
\begin{lstlisting}[caption={Execute\_queue\_vhdl.cpp}]
void Execute_queue::vhdl (void)
{
  morpheo::behavioural::generic::queue::Parameters * param_queue;
  
  param_queue = new morpheo::behavioural::generic::queue::Parameters
    (_param->_size_queue,
     _param->_size_internal_queue
     );
  
  morpheo::behavioural::generic::queue::Queue      * queue;

  std::string queue_name = _name + "_queue";
  queue = new morpheo::behavioural::generic::queue::Queue
    (queue_name.c_str()
#ifdef STATISTICS
     ,NULL
#endif
     ,param_queue
     ,USE_VHDL);
  
  _component->set_component(queue->_component
#ifdef POSITION
                            , 50, 50, 50, 50
#endif
                            , INSTANCE_LIBRARY
                            );

  Vhdl * vhdl = new Vhdl (_name);

  _interfaces->set_port(vhdl);
  _component->vhdl_instance(vhdl);

  vhdl_declaration (vhdl);
  vhdl_body        (vhdl);

  vhdl->generate_file();

  delete vhdl;
};
\end{lstlisting}

\subsubSection{Fichier Execute\_queue\_vhdl\_declaration.cpp}

\lstparam{C++}
\begin{lstlisting}[caption={Execute\_queue\_vhdl\_declaration.cpp}]
void Execute_queue::vhdl_declaration (Vhdl * & vhdl)
{
  vhdl->set_alias  ("internal_QUEUE_INSERT_VAL ",
                    1,
                    " in_EXECUTE_QUEUE_IN_VAL",
                    std_logic_range(1));
  vhdl->set_alias  ("internal_QUEUE_INSERT_ACK ",
                    1,
                    "out_EXECUTE_QUEUE_IN_ACK",
                    std_logic_range(1));
  vhdl->set_signal ("internal_QUEUE_INSERT_DATA",
                    _param->_size_internal_queue);
  vhdl->set_signal ("internal_QUEUE_RETIRE_DATA",
                    _param->_size_internal_queue);
  vhdl->set_alias  ("internal_QUEUE_RETIRE_VAL ",
                    1,
                    "out_EXECUTE_QUEUE_OUT_VAL",
                    std_logic_range(1));
  vhdl->set_alias  ("internal_QUEUE_RETIRE_ACK ",
                    1,
                    " in_EXECUTE_QUEUE_OUT_ACK",
                    std_logic_range(1));

  uint32_t min = 0;
  uint32_t max, size;

  if(_param->_have_port_context_id   )
    {
  size = _param->_size_context_id;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_CONTEXT_ID           ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;
    }
  if(_param->_have_port_front_end_id   )
    {
  size = _param->_size_front_end_id;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_FRONT_END_ID         ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;
    }
  if(_param->_have_port_ooo_engine_id   )
    {
  size = _param->_size_ooo_engine_id;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID        ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;
    }
  if(_param->_have_port_rob_ptr)
    {
  size = _param->_size_rob_ptr;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_PACKET_ID            ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;
    }

  size = _param->_size_special_data;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_FLAGS                ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;

  size = _param->_size_exception;    
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_EXCEPTION            ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;

  size = 1;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_NO_SEQUENCE          ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;

  size = _param->_size_instruction_address;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_ADDRESS              ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;

  size = _param->_size_general_data;
  max = min-1+size;
  vhdl->set_alias ("internal_EXECUTE_QUEUE_OUT_DATA                 ",
                   std_logic(size),
                   "internal_QUEUE_RETIRE_DATA",
                   std_logic_range(_param->_size_internal_queue,max,min));
  min = max+1;
};
\end{lstlisting}

\subsubSection{Fichier Execute\_queue\_vhdl\_body.cpp}

\lstparam{C++}
\begin{lstlisting}[caption={Execute\_queue\_vhdl\_body.cpp}]
void Execute_queue::vhdl_body (Vhdl * & vhdl)
{
  vhdl->set_comment(0,"");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"-- Instance queue                  ");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"");

  vhdl->set_body   (0,"instance_"+_name+"_queue : "+_name+"_queue");
  vhdl->set_body   (0,"port map (");
  vhdl->set_body   (1,"  in_CLOCK       \t=>\t      in_CLOCK ");
  vhdl->set_body   (1,", in_NRESET      \t=>\t      in_NRESET");
  vhdl->set_body   (1,", in_INSERT_VAL  \t=>\tinternal_QUEUE_INSERT_VAL");
  vhdl->set_body   (1,",out_INSERT_ACK  \t=>\tinternal_QUEUE_INSERT_ACK");
  vhdl->set_body   (1,", in_INSERT_DATA \t=>\tinternal_QUEUE_INSERT_DATA");
  vhdl->set_body   (1,",out_RETIRE_VAL  \t=>\tinternal_QUEUE_RETIRE_VAL");
  vhdl->set_body   (1,", in_RETIRE_ACK  \t=>\tinternal_QUEUE_RETIRE_ACK");
  vhdl->set_body   (1,",out_RETIRE_DATA \t=>\tinternal_QUEUE_RETIRE_DATA");
  vhdl->set_body   (0,");");

  vhdl->set_comment(0,"");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"-- Input  Buffer                   ");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"");

  {
  uint32_t min = 0;
  uint32_t max, size;
  uint32_t size_queue = _param->_size_internal_queue;

  if(_param->_have_port_context_id   )
    {
  size = _param->_size_context_id;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_CONTEXT_ID;");
  min = max+1;
    }
  if(_param->_have_port_front_end_id   )
    {
  size = _param->_size_front_end_id;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_FRONT_END_ID;");
  min = max+1;
    }
  if(_param->_have_port_ooo_engine_id   )
    {
  size = _param->_size_ooo_engine_id;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_OOO_ENGINE_ID;");
  min = max+1;
    }
  if(_param->_have_port_rob_ptr)
    {
  size = _param->_size_rob_ptr;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_PACKET_ID;");
  min = max+1;
    }

  size = _param->_size_special_data;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_FLAGS;");
  min = max+1;

  size = _param->_size_exception;    
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_EXCEPTION;");
  min = max+1;

  size = 1;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_NO_SEQUENCE;");
  min = max+1;

  size = _param->_size_instruction_address;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_ADDRESS;");
  min = max+1;

  size = _param->_size_general_data;
  max = min-1+size;
  vhdl->set_body   (0,"internal_QUEUE_INSERT_DATA "+std_logic_range(size_queue,max,min)+
                      " <= in_EXECUTE_QUEUE_IN_DATA;");
  min = max+1;
  }

  vhdl->set_comment(0,"");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"-- Output Buffer                   ");
  vhdl->set_comment(0,"-----------------------------------");
  vhdl->set_comment(0,"");

  if(_param->_have_port_context_id)
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_CONTEXT_ID   "+
                      " <= internal_EXECUTE_QUEUE_OUT_CONTEXT_ID   ;");
  if(_param->_have_port_front_end_id)
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_FRONT_END_ID "+
                      " <= internal_EXECUTE_QUEUE_OUT_FRONT_END_ID ;");
  if(_param->_have_port_ooo_engine_id)
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID"+
                      " <= internal_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID;");
  if(_param->_have_port_rob_ptr)
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_PACKET_ID    "+
                      " <= internal_EXECUTE_QUEUE_OUT_PACKET_ID    ;");
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_FLAGS        "+
                      " <= internal_EXECUTE_QUEUE_OUT_FLAGS        ;");
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_EXCEPTION    "+
                      " <= internal_EXECUTE_QUEUE_OUT_EXCEPTION    ;");
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_NO_SEQUENCE  "+
                      " <= internal_EXECUTE_QUEUE_OUT_NO_SEQUENCE  ;");
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_ADDRESS      "+
                      " <= internal_EXECUTE_QUEUE_OUT_ADDRESS      ;");
  vhdl->set_body   (0,"out_EXECUTE_QUEUE_OUT_DATA         "+
                      " <= internal_EXECUTE_QUEUE_OUT_DATA         ;");
};
\end{lstlisting}

\subsubSection{Fichier Execute\_queue.vhdl}

\lstparam{VHDL}
\begin{lstlisting}[caption={Execute\_queue.cpp}]
library ieee;
  use ieee.numeric_bit.all;       
  use ieee.numeric_std.all;       
  use ieee.std_logic_1164.all;    
  use ieee.std_logic_arith.all;   
  use ieee.std_logic_misc.all;    
--use ieee.std_logic_signed.all;  
  use ieee.std_logic_unsigned.all;
--use ieee.std_logic_textio.all;  

library work;
use work.Execute_queue_0_Pack.all;
use work.Execute_queue_0_queue_Pack.all;

entity Execute_queue_0 is
  port (
   in_CLOCK                           : in  std_logic;
   in_NRESET                          : in  std_logic;
   in_EXECUTE_QUEUE_IN_VAL            : in  std_logic;
  out_EXECUTE_QUEUE_IN_ACK            : out std_logic;
   in_EXECUTE_QUEUE_IN_CONTEXT_ID     : in  std_logic;
   in_EXECUTE_QUEUE_IN_FRONT_END_ID   : in  std_logic;
   in_EXECUTE_QUEUE_IN_OOO_ENGINE_ID  : in  std_logic;
   in_EXECUTE_QUEUE_IN_PACKET_ID      : in  std_logic_vector(5 downto 0);
   in_EXECUTE_QUEUE_IN_FLAGS          : in  std_logic_vector(1 downto 0);
   in_EXECUTE_QUEUE_IN_EXCEPTION      : in  std_logic_vector(4 downto 0);
   in_EXECUTE_QUEUE_IN_NO_SEQUENCE    : in  std_logic;
   in_EXECUTE_QUEUE_IN_ADDRESS        : in  std_logic_vector(31 downto 0);
   in_EXECUTE_QUEUE_IN_DATA           : in  std_logic_vector(31 downto 0);
  out_EXECUTE_QUEUE_OUT_VAL           : out std_logic;
   in_EXECUTE_QUEUE_OUT_ACK           : in  std_logic;
  out_EXECUTE_QUEUE_OUT_CONTEXT_ID    : out std_logic;
  out_EXECUTE_QUEUE_OUT_FRONT_END_ID  : out std_logic;
  out_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID : out std_logic;
  out_EXECUTE_QUEUE_OUT_PACKET_ID     : out std_logic_vector(5 downto 0);
  out_EXECUTE_QUEUE_OUT_FLAGS         : out std_logic_vector(1 downto 0);
  out_EXECUTE_QUEUE_OUT_EXCEPTION     : out std_logic_vector(4 downto 0);
  out_EXECUTE_QUEUE_OUT_NO_SEQUENCE   : out std_logic;
  out_EXECUTE_QUEUE_OUT_ADDRESS       : out std_logic_vector(31 downto 0);
  out_EXECUTE_QUEUE_OUT_DATA          : out std_logic_vector(31 downto 0)
  );
end Execute_queue_0;

architecture behavioural of Execute_queue_0 is

  signal internal_QUEUE_INSERT_DATA              : std_logic_vector(80 downto 0);
  signal internal_QUEUE_RETIRE_DATA              : std_logic_vector(80 downto 0);

  alias internal_QUEUE_INSERT_VAL                : std_logic                     is
          in_EXECUTE_QUEUE_IN_VAL;
  alias internal_QUEUE_INSERT_ACK                : std_logic                     is
         out_EXECUTE_QUEUE_IN_ACK;
  alias internal_QUEUE_RETIRE_VAL                : std_logic                     is
        out_EXECUTE_QUEUE_OUT_VAL;
  alias internal_QUEUE_RETIRE_ACK                : std_logic                     is
         in_EXECUTE_QUEUE_OUT_ACK;
  alias internal_EXECUTE_QUEUE_OUT_CONTEXT_ID    : std_logic                     is
        internal_QUEUE_RETIRE_DATA   (0);
  alias internal_EXECUTE_QUEUE_OUT_FRONT_END_ID  : std_logic                     is
        internal_QUEUE_RETIRE_DATA   (1);
  alias internal_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID : std_logic                     is
        internal_QUEUE_RETIRE_DATA   (2);
  alias internal_EXECUTE_QUEUE_OUT_PACKET_ID     : std_logic_vector(5 downto 0)  is
        internal_QUEUE_RETIRE_DATA   (8 downto 3);
  alias internal_EXECUTE_QUEUE_OUT_FLAGS         : std_logic_vector(1 downto 0)  is
        internal_QUEUE_RETIRE_DATA   (10 downto 9);
  alias internal_EXECUTE_QUEUE_OUT_EXCEPTION     : std_logic_vector(4 downto 0)  is
        internal_QUEUE_RETIRE_DATA   (15 downto 11);
  alias internal_EXECUTE_QUEUE_OUT_NO_SEQUENCE   : std_logic                     is
        internal_QUEUE_RETIRE_DATA   (16);
  alias internal_EXECUTE_QUEUE_OUT_ADDRESS       : std_logic_vector(31 downto 0) is
        internal_QUEUE_RETIRE_DATA   (48 downto 17);
  alias internal_EXECUTE_QUEUE_OUT_DATA          : std_logic_vector(31 downto 0) is
        internal_QUEUE_RETIRE_DATA   (80 downto 49);

begin
  -- 
  -- -----------------------------------
  -- -- Instance queue                  
  -- -----------------------------------
  -- 
  instance_Execute_queue_0_queue : Execute_queue_0_queue
  port map (
            in_CLOCK              =>            in_CLOCK 
          , in_NRESET             =>            in_NRESET
          , in_INSERT_VAL         =>      internal_QUEUE_INSERT_VAL
          ,out_INSERT_ACK         =>      internal_QUEUE_INSERT_ACK
          , in_INSERT_DATA        =>      internal_QUEUE_INSERT_DATA
          ,out_RETIRE_VAL         =>      internal_QUEUE_RETIRE_VAL
          , in_RETIRE_ACK         =>      internal_QUEUE_RETIRE_ACK
          ,out_RETIRE_DATA        =>      internal_QUEUE_RETIRE_DATA
  );
  -- 
  -- -----------------------------------
  -- -- Input  Buffer                   
  -- -----------------------------------
  -- 
  internal_QUEUE_INSERT_DATA (0)            <= in_EXECUTE_QUEUE_IN_CONTEXT_ID;
  internal_QUEUE_INSERT_DATA (1)            <= in_EXECUTE_QUEUE_IN_FRONT_END_ID;
  internal_QUEUE_INSERT_DATA (2)            <= in_EXECUTE_QUEUE_IN_OOO_ENGINE_ID;
  internal_QUEUE_INSERT_DATA (8 downto 3)   <= in_EXECUTE_QUEUE_IN_PACKET_ID;
  internal_QUEUE_INSERT_DATA (10 downto 9)  <= in_EXECUTE_QUEUE_IN_FLAGS;
  internal_QUEUE_INSERT_DATA (15 downto 11) <= in_EXECUTE_QUEUE_IN_EXCEPTION;
  internal_QUEUE_INSERT_DATA (16)           <= in_EXECUTE_QUEUE_IN_NO_SEQUENCE;
  internal_QUEUE_INSERT_DATA (48 downto 17) <= in_EXECUTE_QUEUE_IN_ADDRESS;
  internal_QUEUE_INSERT_DATA (80 downto 49) <= in_EXECUTE_QUEUE_IN_DATA;
  -- 
  -- -----------------------------------
  -- -- Output Buffer                   
  -- -----------------------------------
  -- 
  out_EXECUTE_QUEUE_OUT_CONTEXT_ID    <= internal_EXECUTE_QUEUE_OUT_CONTEXT_ID;
  out_EXECUTE_QUEUE_OUT_FRONT_END_ID  <= internal_EXECUTE_QUEUE_OUT_FRONT_END_ID;
  out_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID <= internal_EXECUTE_QUEUE_OUT_OOO_ENGINE_ID;
  out_EXECUTE_QUEUE_OUT_PACKET_ID     <= internal_EXECUTE_QUEUE_OUT_PACKET_ID;
  out_EXECUTE_QUEUE_OUT_FLAGS         <= internal_EXECUTE_QUEUE_OUT_FLAGS;
  out_EXECUTE_QUEUE_OUT_EXCEPTION     <= internal_EXECUTE_QUEUE_OUT_EXCEPTION;
  out_EXECUTE_QUEUE_OUT_NO_SEQUENCE   <= internal_EXECUTE_QUEUE_OUT_NO_SEQUENCE;
  out_EXECUTE_QUEUE_OUT_ADDRESS       <= internal_EXECUTE_QUEUE_OUT_ADDRESS;
  out_EXECUTE_QUEUE_OUT_DATA          <= internal_EXECUTE_QUEUE_OUT_DATA;

end behavioural;
\end{lstlisting}

