source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Select/Pseudo_LRU/src/Pseudo_LRU_vhdl_body.cpp @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 7.3 KB
Line 
1#ifdef VHDL
2/*
3 * $Id$
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Generic/Select/Pseudo_LRU/include/Pseudo_LRU.h"
10
11namespace morpheo {
12namespace behavioural {
13namespace generic {
14namespace select {
15namespace pseudo_lru {
16
17  void Pseudo_LRU::vhdl_body (Vhdl & vhdl)
18  {
19    vhdl.set_body ("");
20    vhdl.set_body ("-----------------------------------------------------------------------------");
21    vhdl.set_body ("-- Access");
22    vhdl.set_body ("-----------------------------------------------------------------------------");
23    vhdl.set_body ("");
24    vhdl.set_body ("-- Tree of Pseudo-LRU - example to 8 entity");
25    vhdl.set_body ("--");
26    vhdl.set_body ("--                4-5-6-7?              ");
27    vhdl.set_body ("--           0_______|_______1          ");
28    vhdl.set_body ("--           |               |          ");
29    vhdl.set_body ("--          2-3?            6-7?        ");
30    vhdl.set_body ("--       0___|___1       0___|___1      ");
31    vhdl.set_body ("--       |       |       |       |      ");
32    vhdl.set_body ("--       1?      3?      5?      7?     ");
33    vhdl.set_body ("--     0_|_1   0_|_1   0_|_1   0_|_1    ");
34    vhdl.set_body ("--     |   |   |   |   |   |   |   |    ");
35    vhdl.set_body ("--    Way Way Way Way Way Way Way Way   ");
36    vhdl.set_body ("--     0   1   2   3   4   5   6   7    ");
37    for (uint32_t i=0; i<_param._nb_access; i++)
38      {
39        vhdl.set_body ("");
40        // Read the table
41       
42        string access_address;
43
44        if (_param._size_table>1)
45          access_address = "conv_integer(in_ACCESS_ADDRESS_"+toString(i)+")";
46        else
47          access_address = "0";
48
49        vhdl.set_body ("access_entry_"+toString(i)+" <= reg_TABLE ("+access_address+");");
50        vhdl.set_body ("");
51
52        for (int32_t j=static_cast<uint32_t>(log2(_param._nb_entity)-1); j>=0; j--)
53          {
54            vhdl.set_body ("access_entity_"+toString(i)+"("+toString(j)+") <= ");
55
56            uint32_t cpt=0;
57
58            for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param._nb_entity-1); k+=(1<<(j+1)))
59              {
60                string cond = "";
61               
62                // Create the condition
63                for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param._nb_entity));l++)
64                  {
65                    if (l==static_cast<uint32_t>(j+1))
66                      cond += "when";
67                    else
68                      cond += " and";
69                    cond += " access_entity_"+toString(i)+"("+toString(l)+") = '"+toString((cpt>>(l-(j+1)))&1)+"'";
70                  }
71               
72                string print_else = (k==(1<<j)-1)?"     ":"else ";
73
74                vhdl.set_body ("\t"+print_else+"access_entry_"+toString(i)+"("+toString(k)+") "+cond);
75                cpt ++;
76              }
77            vhdl.set_body ("\t;");
78          }
79      }
80
81    vhdl.set_body ("");
82    vhdl.set_body ("-----------------------------------------------------------------------------");
83    vhdl.set_body ("-- Update");
84    vhdl.set_body ("-----------------------------------------------------------------------------");
85    vhdl.set_body ("");
86    vhdl.set_body ("-- port access");
87    for (uint32_t i=0; i<_param._nb_access; i++)
88      for (int32_t j=static_cast<uint32_t>(log2(_param._nb_entity)-1); j>=0; j--)
89        {
90          uint32_t cpt=0;
91         
92          for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param._nb_entity-1); k+=(1<<(j+1)))
93            {
94              bool   have_cond = false;
95              string cond      = "";
96             
97              // condition to change the bit
98              for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param._nb_entity));l++)
99                {
100                  have_cond = true;
101
102                  if (l==static_cast<uint32_t>(j+1))
103                    cond += "when";
104                  else
105                    cond += " and";
106                  cond += " access_entity_"+toString(i)+"("+toString(l)+")='"+toString((cpt>>(l-(j+1)))&1)+"'";
107                }
108             
109              vhdl.set_body ("access_next_entry_"+toString(i)+"("+toString(k)+") <=");
110              vhdl.set_body ("\tnot access_entity_"+toString(i)+"("+toString(j)+") "+cond);
111              if (have_cond == true)
112                vhdl.set_body ("\telse access_entry_"+toString(i)+"("+toString(k)+")");
113              vhdl.set_body ("\t;");         
114              cpt ++;
115            }
116        }
117
118    vhdl.set_body ("");
119    vhdl.set_body ("-- port update");
120    for (uint32_t i=0; i<_param._nb_update; i++)
121      for (int32_t j=static_cast<uint32_t>(log2(_param._nb_entity)-1); j>=0; j--)
122        {
123          uint32_t cpt=0;
124         
125          for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param._nb_entity-1); k+=(1<<(j+1)))
126            {
127              bool   have_cond = false;
128              string cond      = "";
129             
130              // condition to change the bit
131              for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param._nb_entity));l++)
132                {
133                  have_cond = true;
134
135                  if (l==static_cast<uint32_t>(j+1))
136                    cond += "when";
137                  else
138                    cond += " and";
139                  cond += " in_UPDATE_ENTITY_"+toString(i)+"("+toString(l)+")='"+toString((cpt>>(l-(j+1)))&1)+"'";
140                }
141             
142              vhdl.set_body ("update_next_entry_"+toString(i)+"("+toString(k)+") <=");
143              vhdl.set_body ("\tnot in_UPDATE_ENTITY_"+toString(i)+"("+toString(j)+") "+cond);
144              if (have_cond == true)
145                {
146                  string update_address;
147
148                  if (_param._size_table>1)
149                    update_address = "conv_integer(in_UPDATE_ADDRESS_"+toString(i)+")";
150                  else
151                    update_address = "0";
152                 
153                  vhdl.set_body ("\telse reg_TABLE ("+update_address+")("+toString(k)+")");
154                }
155              vhdl.set_body ("\t;");         
156              cpt ++;
157            }
158        }
159
160    vhdl.set_body ("");
161    vhdl.set_body ("-----------------------------------------------------------------------------");
162    vhdl.set_body ("-- Transition");
163    vhdl.set_body ("-----------------------------------------------------------------------------");
164    vhdl.set_body ("");
165
166    vhdl.set_body ("reg_TABLE_write: process (in_CLOCK)");
167    vhdl.set_body ("begin");
168    vhdl.set_body ("\tif in_CLOCK'event and in_CLOCK = '1' then");
169    vhdl.set_body ("\t\t-- Access port");
170    for (uint32_t i=0; i<_param._nb_access; i++)
171      {
172        string access_address;
173
174        if (_param._size_table>1)
175          access_address = "conv_integer(in_ACCESS_ADDRESS_"+toString(i)+")";
176        else
177          access_address = "0";
178
179        vhdl.set_body ("\t\tif (in_ACCESS_VAL_"+toString(i)+" = '1') then");
180        vhdl.set_body ("\t\t\treg_TABLE ("+access_address+") <= access_next_entry_"+toString(i)+";");
181        vhdl.set_body ("\t\tend if;");
182      }
183
184    vhdl.set_body ("\t\t-- Update port");
185    for (uint32_t i=0; i<_param._nb_update; i++)
186      {
187        string update_address;
188
189        if (_param._size_table>1)
190          update_address = "conv_integer(in_UPDATE_ADDRESS_"+toString(i)+")";
191        else
192          update_address = "0";
193                 
194        vhdl.set_body ("\t\tif (in_UPDATE_VAL_"+toString(i)+" = '1') then");
195        vhdl.set_body ("\t\t\treg_TABLE ("+update_address+") <= update_next_entry_"+toString(i)+";");
196        vhdl.set_body ("\t\tend if;");
197      }
198
199    vhdl.set_body ("\tend if;");
200    vhdl.set_body ("end process reg_TABLE_write;");
201
202    vhdl.set_body ("");
203    vhdl.set_body ("-----------------------------------------------------------------------------");
204    vhdl.set_body ("-- Output");
205    vhdl.set_body ("-----------------------------------------------------------------------------");
206    vhdl.set_body ("");
207    vhdl.set_body ("-- Ack is always ");
208    vhdl.set_body ("");
209    for (uint32_t i=0; i<_param._nb_access; i++)
210      {
211        vhdl.set_body ("out_ACCESS_ACK_"+toString(i)+"    <= '1';");
212        vhdl.set_body ("out_ACCESS_ENTITY_"+toString(i)+" <= access_entity_"+toString(i)+" when in_ACCESS_VAL_"+toString(i)+" = '1' else (others => '0');");
213      }
214    vhdl.set_body ("");
215    for (uint32_t i=0; i<_param._nb_update; i++)
216      {
217        vhdl.set_body ("out_UPDATE_ACK_"+toString(i)+"    <= '1';");
218      }
219  };
220
221}; // end namespace pseudo_lru
222}; // end namespace select
223}; // end namespace generic
224
225}; // end namespace behavioural
226}; // end namespace morpheo             
227#endif
Note: See TracBrowser for help on using the repository browser.