source: trunk/IPs/systemC/Environnement/Cache/selftest/main.cpp @ 78

Last change on this file since 78 was 78, checked in by rosiere, 16 years ago

Add :

  • Execute_loop (must be test systemC)
  • Prediction
    • Direction : predifined scheme
    • Branch Target Buffer
  • iFetch_unit
    • ifetch_queue
    • pc management
  • Decod_unit
    • coming soon : support for custom operation
  • Rename_unit
    • RAT
    • Free_list
    • Dependence RAW check
    • Load store unit pointer
  • New Environnement (hierarchy_memory will remove in a next version)


Modif :

  • Manage Custom Operation
  • All component in execute_loop to use the new statistics management

Not Finish :

  • Return Address Stack
  • Environnement
File size: 18.8 KB
Line 
1#include <iostream>
2#include "../include/Cache.h"
3
4using namespace std;
5using namespace environnement;
6using namespace environnement::cache;
7
8#define TEST(x,y)                               \
9  {                                             \
10    cout << "Line " << __LINE__ << " : ";       \
11    if (x==y)                                   \
12      {                                         \
13        cout << "Test OK" << endl;              \
14      }                                         \
15    else                                        \
16      {                                         \
17        cout << "Test KO" << endl;              \
18        exit (EXIT_FAILURE);                    \
19      }                                         \
20  } while (0)
21   
22
23
24int main (void)
25{
26  cout << "<main> Begin" << endl;
27
28  {
29    cache_onelevel::Parameters * param = new cache_onelevel::Parameters
30      (
31       4, // nb_port     
32       32, // nb_line     
33       8, // size_line   
34       4,// size_word   
35       4, // associativity
36       2, // hit_latence 
37       3 // miss_penality
38       );
39
40    cout << *param << endl;
41
42    cache_onelevel::Cache_OneLevel * cache = new cache_onelevel::Cache_OneLevel ("my_cache",param);
43    cache->reset();
44   
45    cout << *cache << endl;
46   
47    cache->transition();
48    cache->transition();
49
50    cout << *cache << endl;
51
52    TEST(cache->access(0, 0x100, 0, CACHED, WRITE), MISS);
53    TEST(cache->latence(0), 5);
54    cache->transition(); // miss cycle 1
55
56    TEST(cache->access(0, 0x100, 0, CACHED, WRITE), HIT_WRITE_BUFFER);
57    TEST(cache->latence(0), 4);
58    cache->transition(); // miss cycle 2
59
60    TEST(cache->access(0, 0x100, 0, CACHED, WRITE), HIT_WRITE_BUFFER);
61    TEST(cache->latence(0), 3);
62    cache->transition(); // miss cycle 3
63
64    TEST(cache->access(0, 0x100, 0, CACHED, WRITE), HIT_CACHE); //word 0
65    TEST(cache->latence(0), 2);
66
67    TEST(cache->access(0, 0x104, 0, CACHED, WRITE), HIT_CACHE); //word 1
68    TEST(cache->access(0, 0x108, 0, CACHED, WRITE), HIT_CACHE); //word 2
69    TEST(cache->access(0, 0x10c, 0, CACHED, WRITE), HIT_CACHE); //word 3
70    TEST(cache->access(0, 0x110, 0, CACHED, WRITE), HIT_CACHE); //word 4
71    TEST(cache->access(0, 0x114, 0, CACHED, WRITE), HIT_CACHE); //word 5
72    TEST(cache->access(0, 0x118, 0, CACHED, WRITE), HIT_CACHE); //word 6
73    TEST(cache->access(0, 0x11c, 0, CACHED, WRITE), HIT_CACHE); //word 7
74    TEST(cache->access(0, 0x120, 0, CACHED, WRITE), MISS      );
75    TEST(cache->access(1, 0x140, 0, CACHED, WRITE), MISS      );
76    TEST(cache->access(2, 0x160, 0, CACHED, WRITE), MISS      );
77    TEST(cache->access(3, 0x144, 0, CACHED, WRITE), HIT_BYPASS);
78
79    TEST(cache->latence(0), 5);
80    TEST(cache->latence(1), 5);
81    TEST(cache->latence(2), 5);
82    TEST(cache->latence(3), 5);
83
84    cache->transition(); // miss access   
85    TEST(cache->access(0, 0x180, 0, CACHED, WRITE), MISS      );
86    TEST(cache->access(1, 0x1a0, 0, CACHED, WRITE), MISS      );
87    TEST(cache->access(2, 0x1c0, 0, CACHED, WRITE), MISS      );
88    TEST(cache->access(3, 0x1e0, 0, CACHED, WRITE), MISS      );
89
90    cache->transition(); // miss cycle 1
91    cout << *cache << endl;
92
93    TEST(cache->access(0, 0x200, 0, CACHED, WRITE), MISS      );
94    TEST(cache->access(1, 0x300, 0, CACHED, WRITE), MISS      );
95    TEST(cache->access(2, 0x400, 0, CACHED, WRITE), MISS      );
96
97    cache->transition(); // miss cycle 0
98    cache->transition(); // miss cycle 1
99    cache->transition(); // miss cycle 2
100    cache->transition(); // miss cycle 3
101    cout << *cache << endl;
102
103    // line 0 : all way is use
104    TEST(cache->access(0, 0x118, 0,  CACHED, WRITE), HIT_CACHE );
105    TEST(cache->access(1, 0x204, 0,  CACHED, WRITE), HIT_CACHE );
106    TEST(cache->access(2, 0x100, 0,UNCACHED, WRITE), MISS      );
107    TEST(cache->access(3, 0x118, 0,  CACHED, WRITE), HIT_BYPASS);
108
109    TEST(cache->latence(0), 2);
110    TEST(cache->latence(1), 2);
111    TEST(cache->latence(2), 5);
112    TEST(cache->latence(3), 2);
113
114    cache->transition();
115    cout << *cache << endl;
116   
117    TEST(cache->access(0, 0x500, 0,  CACHED, WRITE), MISS      );
118
119    cache->transition(); // miss cycle 1
120    TEST(cache->access(0, 0x100, 0,  CACHED, WRITE), HIT_CACHE );
121    TEST(cache->access(1, 0x200, 0,  CACHED, WRITE), HIT_CACHE );
122    TEST(cache->access(2, 0x300, 0,  CACHED, WRITE), HIT_CACHE );
123    TEST(cache->access(3, 0x400, 0,  CACHED, WRITE), HIT_CACHE );
124
125    cache->transition(); // miss cycle 2
126
127    TEST(cache->access(0, 0x100, 0,  CACHED, WRITE), HIT_CACHE );
128    TEST(cache->access(1, 0x200, 0,  CACHED, WRITE), HIT_CACHE );
129    TEST(cache->access(2, 0x300, 0,  CACHED, WRITE), HIT_CACHE );
130    TEST(cache->access(3, 0x400, 0,  CACHED, WRITE), HIT_CACHE );
131
132    cache->transition(); // miss cycle 3
133    TEST(cache->access(0, 0x100, 0,  CACHED, WRITE), HIT_CACHE );
134    TEST(cache->access(1, 0x200, 0,  CACHED, WRITE), HIT_CACHE );
135    TEST(cache->access(2, 0x300, 0,  CACHED, WRITE), HIT_CACHE );
136    TEST(cache->access(3, 0x400, 0,  CACHED, WRITE), MISS );
137
138    TEST(cache->latence(0), 2);
139    TEST(cache->latence(1), 2);
140    TEST(cache->latence(2), 2);
141    TEST(cache->latence(3), 5);
142   
143    cout << *cache << endl;
144
145    delete cache;
146    delete param;
147  }
148
149  {
150    uint32_t * nb_line       = new uint32_t [3];
151    uint32_t * size_line     = new uint32_t [3];
152    uint32_t * size_word     = new uint32_t [3];
153    uint32_t * associativity = new uint32_t [3];
154    uint32_t * hit_latence   = new uint32_t [3];
155    uint32_t * miss_penality = new uint32_t [3];
156
157    nb_line       [0] = 4 ; nb_line       [1] = 4 ; nb_line       [2] = 4 ;
158    size_line     [0] = 8 ; size_line     [1] = 8 ; size_line     [2] = 8 ;
159    size_word     [0] = 4 ; size_word     [1] = 4 ; size_word     [2] = 4 ;
160    associativity [0] = 1 ; associativity [1] = 2 ; associativity [2] = 4 ;
161    hit_latence   [0] = 1 ; hit_latence   [1] = 2 ; hit_latence   [2] = 2 ;
162    miss_penality [0] = 3 ; miss_penality [1] = 5 ; miss_penality [2] = 7 ;
163
164    cache_multilevel::Parameters * param = new cache_multilevel::Parameters
165      (
166       3,  // nb_level
167       4,  // nb_port     
168       nb_line      ,
169       size_line    ,
170       size_word    ,
171       associativity,
172       hit_latence  ,
173       miss_penality
174       );
175
176    cout << *param << endl;
177 
178    cache_multilevel::Cache_MultiLevel * cache = new cache_multilevel::Cache_MultiLevel ("my_cache",param);
179
180    cout << *cache << endl;
181    cache->reset();
182    cout << *cache << endl;
183 
184    cache_multilevel::Access access;
185
186    access = cache->access (0, 0x100, 0, CACHED, WRITE);
187    cache->update_access(access);
188
189    TEST(access.num_port     , 0);
190    TEST(access.hit          , MISS);
191    TEST(access.latence      , 20);
192    TEST(access.last_nb_level, 2);
193
194    cache->transition(); //19
195    cache->transition(); //18
196    cache->transition(); //17
197    cache->transition(); //16
198    cache->transition(); //15
199    cache->transition(); //14
200    cache->transition(); //13
201    cache->transition(); //12
202    cache->transition(); //11
203    cache->transition(); //10
204    cout << *cache << endl;
205
206    access = cache->access (0, 0x100, 0, CACHED, WRITE);
207    cache->update_access(access);
208
209    TEST(access.num_port     , 0);
210    TEST(access.hit          , HIT_WRITE_BUFFER);
211    TEST(access.latence      , 10);
212    TEST(access.last_nb_level, 0);
213
214    cache->transition(); // 9
215    cache->transition(); // 8
216    cache->transition(); // 7
217    cache->transition(); // 6
218    cache->transition(); // 5
219    cache->transition(); // 4
220    cache->transition(); // 3
221    cache->transition(); // 2
222
223    access = cache->access (0, 0x100, 0, CACHED, WRITE);
224    cache->update_access(access);
225
226    TEST(access.num_port     , 0);
227    TEST(access.hit          , HIT_WRITE_BUFFER);
228    TEST(access.latence      , 2);
229    TEST(access.last_nb_level, 0);
230
231    cache->transition(); // 1
232
233    access = cache->access (0, 0x100, 0, CACHED, WRITE);
234    cache->update_access(access);
235
236    TEST(access.num_port     , 0);
237    TEST(access.hit          , HIT_CACHE);
238    TEST(access.latence      , 1);
239    TEST(access.last_nb_level, 0);
240    cout << *cache << endl;
241
242    cache->transition();
243
244    access = cache->access (0, 0x100, 0, CACHED, WRITE);
245    cache->update_access(access);
246
247    TEST(access.num_port     , 0);
248    TEST(access.hit          , HIT_CACHE);
249    TEST(access.latence      , 1);
250    TEST(access.last_nb_level, 0);
251
252
253    access = cache->access (0, 0x100, 0, CACHED, WRITE);
254    cache->update_access(access);
255
256    TEST(access.num_port     , 0);
257    TEST(access.hit          , HIT_CACHE);
258    TEST(access.latence      , 1);
259    TEST(access.last_nb_level, 0);
260
261    access = cache->access (1, 0x200, 0, CACHED, WRITE);
262    cache->update_access(access);
263
264    TEST(access.num_port     , 1);
265    TEST(access.hit          , MISS);
266    TEST(access.latence      , 20);
267    TEST(access.last_nb_level, 2);
268
269    access = cache->access (2, 0x100, 0, CACHED, WRITE);
270    cache->update_access(access);
271
272    TEST(access.num_port     , 2);
273    TEST(access.hit          , HIT_BYPASS);
274    TEST(access.latence      , 1);
275    TEST(access.last_nb_level, 0);
276
277    access = cache->access (3, 0x200, 0, CACHED, WRITE);
278    cache->update_access(access);
279
280    TEST(access.num_port     , 3);
281    TEST(access.hit          , HIT_BYPASS);
282    TEST(access.latence      , 20);
283    TEST(access.last_nb_level, 0);
284
285    cache->transition(); //19
286    cache->transition(); //18
287    cache->transition(); //17
288    cache->transition(); //16
289    cache->transition(); //15
290
291
292//     access = cache->access (1, 0x300, 0, CACHED, WRITE);
293//     cache->update_access(access);
294
295//     TEST(access.num_port     , 1);
296//     TEST(access.hit          , MISS);
297//     TEST(access.latence      , 20);
298//     TEST(access.last_nb_level, 2);
299
300    cache->transition(); //14
301    cache->transition(); //13
302    cache->transition(); //12
303    cache->transition(); //11
304    cache->transition(); //10
305    cout << *cache << endl;
306
307    access = cache->access (0, 0x100, 0, CACHED, WRITE);
308    cache->update_access(access);
309
310    TEST(access.num_port     , 0);
311    TEST(access.hit          , HIT_CACHE);
312    TEST(access.latence      , 1);
313    TEST(access.last_nb_level, 0);
314
315    access = cache->access (1, 0x200, 0, CACHED, WRITE);
316    cache->update_access(access);
317
318    TEST(access.num_port     , 1);
319    TEST(access.hit          , HIT_WRITE_BUFFER);
320    TEST(access.latence      , 10);
321    TEST(access.last_nb_level, 0);
322
323    access = cache->access (2, 0x100, 0, CACHED, WRITE);
324    cache->update_access(access);
325
326    TEST(access.num_port     , 2);
327    TEST(access.hit          , HIT_BYPASS);
328    TEST(access.latence      , 1);
329    TEST(access.last_nb_level, 0);
330
331    access = cache->access (3, 0x200, 0, CACHED, WRITE);
332    cache->update_access(access);
333
334    TEST(access.num_port     , 3);
335    TEST(access.hit          , HIT_WRITE_BUFFER);
336    TEST(access.latence      , 10);
337    TEST(access.last_nb_level, 0);
338
339    cache->transition(); //9
340
341    access = cache->access (1, 0x400, 0, CACHED, WRITE);
342    cache->update_access(access);
343
344    TEST(access.num_port     , 1);
345    TEST(access.hit          , MISS);
346    TEST(access.latence      , 20);
347    TEST(access.last_nb_level, 2);
348
349    cache->transition(); //8
350    cache->transition(); //7
351    cache->transition(); //6
352    cache->transition(); //5
353    cache->transition(); //4
354    cache->transition(); //3
355    cache->transition(); //2
356    cache->transition(); //1
357    cache->transition(); //0
358
359    access = cache->access (1, 0x100, 0, CACHED, WRITE);
360    cout << access<< endl;
361   
362    cache->update_access(access);
363
364    TEST(access.num_port     , 1);
365    TEST(access.hit          , HIT_CACHE);
366    TEST(access.latence      , 6 );
367    TEST(access.last_nb_level, 1);
368
369    cout << *cache << endl;
370    delete cache;
371    delete param;
372    delete [] nb_line      ;
373    delete [] size_line    ;
374    delete [] size_word    ;
375    delete [] associativity;
376    delete [] hit_latence  ;
377    delete [] miss_penality;
378  }
379
380  {
381    uint32_t * cache_shared_nb_line       = new uint32_t [1];
382    uint32_t * cache_shared_size_line     = new uint32_t [1];
383    uint32_t * cache_shared_size_word     = new uint32_t [1];
384    uint32_t * cache_shared_associativity = new uint32_t [1];
385    uint32_t * cache_shared_hit_latence   = new uint32_t [1];
386    uint32_t * cache_shared_miss_penality = new uint32_t [1];
387
388    cache_shared_nb_line       [0] = 8 ;
389    cache_shared_size_line     [0] = 8 ;
390    cache_shared_size_word     [0] = 4 ;
391    cache_shared_associativity [0] = 4 ;
392    cache_shared_hit_latence   [0] = 2 ;
393    cache_shared_miss_penality [0] = 5 ;
394
395    uint32_t  * icache_nb_level      = new uint32_t   [2];
396    uint32_t  * icache_nb_port       = new uint32_t   [2];
397    uint32_t ** icache_nb_line       = new uint32_t * [2];
398    uint32_t ** icache_size_line     = new uint32_t * [2];
399    uint32_t ** icache_size_word     = new uint32_t * [2];
400    uint32_t ** icache_associativity = new uint32_t * [2];
401    uint32_t ** icache_hit_latence   = new uint32_t * [2];
402    uint32_t ** icache_miss_penality = new uint32_t * [2];
403
404    icache_nb_level      [0]    = 1;
405    icache_nb_port       [0]    = 2;
406    icache_nb_line       [0]    = new uint32_t [1];
407    icache_size_line     [0]    = new uint32_t [1];
408    icache_size_word     [0]    = new uint32_t [1];
409    icache_associativity [0]    = new uint32_t [1];
410    icache_hit_latence   [0]    = new uint32_t [1];
411    icache_miss_penality [0]    = new uint32_t [1];
412
413    icache_nb_line       [0][0] = 8;
414    icache_size_line     [0][0] = 8;
415    icache_size_word     [0][0] = 4;
416    icache_associativity [0][0] = 1;
417    icache_hit_latence   [0][0] = 1;
418    icache_miss_penality [0][0] = 3;
419
420    icache_nb_level      [1]    = 2;
421    icache_nb_port       [1]    = 2;
422    icache_nb_line       [1]    = new uint32_t [2];
423    icache_size_line     [1]    = new uint32_t [2];
424    icache_size_word     [1]    = new uint32_t [2];
425    icache_associativity [1]    = new uint32_t [2];
426    icache_hit_latence   [1]    = new uint32_t [2];
427    icache_miss_penality [1]    = new uint32_t [2];
428   
429    icache_nb_line       [1][0] = 4;
430    icache_size_line     [1][0] = 8;
431    icache_size_word     [1][0] = 4;
432    icache_associativity [1][0] = 1;
433    icache_hit_latence   [1][0] = 1;
434    icache_miss_penality [1][0] = 3;
435
436    icache_nb_line       [1][1] = 4;
437    icache_size_line     [1][1] = 8;
438    icache_size_word     [1][1] = 4;
439    icache_associativity [1][1] = 4;
440    icache_hit_latence   [1][1] = 1;
441    icache_miss_penality [1][1] = 4;
442
443    uint32_t  * dcache_nb_level      = new uint32_t   [2];
444    uint32_t  * dcache_nb_port       = new uint32_t   [2];
445    uint32_t ** dcache_nb_line       = new uint32_t * [2];
446    uint32_t ** dcache_size_line     = new uint32_t * [2];
447    uint32_t ** dcache_size_word     = new uint32_t * [2];
448    uint32_t ** dcache_associativity = new uint32_t * [2];
449    uint32_t ** dcache_hit_latence   = new uint32_t * [2];
450    uint32_t ** dcache_miss_penality = new uint32_t * [2];
451
452    dcache_nb_level      [0]    = 1;
453    dcache_nb_port       [0]    = 2;
454    dcache_nb_line       [0]    = new uint32_t [1];
455    dcache_size_line     [0]    = new uint32_t [1];
456    dcache_size_word     [0]    = new uint32_t [1];
457    dcache_associativity [0]    = new uint32_t [1];
458    dcache_hit_latence   [0]    = new uint32_t [1];
459    dcache_miss_penality [0]    = new uint32_t [1];
460
461    dcache_nb_line       [0][0] = 8;
462    dcache_size_line     [0][0] = 8;
463    dcache_size_word     [0][0] = 4;
464    dcache_associativity [0][0] = 1;
465    dcache_hit_latence   [0][0] = 1;
466    dcache_miss_penality [0][0] = 3;
467
468    dcache_nb_level      [1]    = 2;
469    dcache_nb_port       [1]    = 2;
470    dcache_nb_line       [1]    = new uint32_t [2];
471    dcache_size_line     [1]    = new uint32_t [2];
472    dcache_size_word     [1]    = new uint32_t [2];
473    dcache_associativity [1]    = new uint32_t [2];
474    dcache_hit_latence   [1]    = new uint32_t [2];
475    dcache_miss_penality [1]    = new uint32_t [2];
476   
477    dcache_nb_line       [1][0] = 4;
478    dcache_size_line     [1][0] = 8;
479    dcache_size_word     [1][0] = 4;
480    dcache_associativity [1][0] = 1;
481    dcache_hit_latence   [1][0] = 1;
482    dcache_miss_penality [1][0] = 3;
483
484    dcache_nb_line       [1][1] = 4;
485    dcache_size_line     [1][1] = 8;
486    dcache_size_word     [1][1] = 4;
487    dcache_associativity [1][1] = 4;
488    dcache_hit_latence   [1][1] = 1;
489    dcache_miss_penality [1][1] = 4;
490
491    Parameters * param = new Parameters
492      (2,//nb_cache_dedicated
493       
494       icache_nb_level      ,
495       icache_nb_port       ,
496       icache_nb_line       ,
497       icache_size_line     ,
498       icache_size_word     ,
499       icache_associativity ,
500       icache_hit_latence   ,
501       icache_miss_penality ,
502       
503       dcache_nb_level      ,
504       dcache_nb_port       ,
505       dcache_nb_line       ,
506       dcache_size_line     ,
507       dcache_size_word     ,
508       dcache_associativity ,
509       dcache_hit_latence   ,
510       dcache_miss_penality ,
511     
512       1,  // nb_level
513       cache_shared_nb_line      ,
514       cache_shared_size_line    ,
515       cache_shared_size_word    ,
516       cache_shared_associativity,
517       cache_shared_hit_latence  ,
518       cache_shared_miss_penality
519       );
520
521    cout << *param << endl;
522
523    cache::Cache * cache = new cache::Cache ("my_cache",param);
524
525    cout << *cache << endl;
526    cache->reset();
527    cout << *cache << endl;
528
529    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 16);
530    cache->transition();
531    TEST(cache->latence (DATA_CACHE, 1, 0, 0x100, 0, CACHED, WRITE), 15);
532    cache->transition();
533
534    cout << *cache << endl;
535
536
537    delete    cache;
538    delete    param;
539    delete [] cache_shared_nb_line      ;
540    delete [] cache_shared_size_line    ;
541    delete [] cache_shared_size_word    ;
542    delete [] cache_shared_associativity;
543    delete [] cache_shared_hit_latence  ;
544    delete [] cache_shared_miss_penality;
545    delete [] icache_nb_level      ;
546    delete [] icache_nb_port       ;
547    delete [] icache_nb_line       [0];
548    delete [] icache_size_line     [0];
549    delete [] icache_size_word     [0];
550    delete [] icache_associativity [0];
551    delete [] icache_hit_latence   [0];
552    delete [] icache_miss_penality [0];
553    delete [] icache_nb_line       [1];
554    delete [] icache_size_line     [1];
555    delete [] icache_size_word     [1];
556    delete [] icache_associativity [1];
557    delete [] icache_hit_latence   [1];
558    delete [] icache_miss_penality [1];
559    delete [] icache_nb_line       ;
560    delete [] icache_size_line     ;
561    delete [] icache_size_word     ;
562    delete [] icache_associativity ;
563    delete [] icache_hit_latence   ;
564    delete [] icache_miss_penality ;
565    delete [] dcache_nb_level      ;
566    delete [] dcache_nb_port       ;
567    delete [] dcache_nb_line       [0];
568    delete [] dcache_size_line     [0];
569    delete [] dcache_size_word     [0];
570    delete [] dcache_associativity [0];
571    delete [] dcache_hit_latence   [0];
572    delete [] dcache_miss_penality [0];
573    delete [] dcache_nb_line       [1];
574    delete [] dcache_size_line     [1];
575    delete [] dcache_size_word     [1];
576    delete [] dcache_associativity [1];
577    delete [] dcache_hit_latence   [1];
578    delete [] dcache_miss_penality [1];
579    delete [] dcache_nb_line       ;
580    delete [] dcache_size_line     ;
581    delete [] dcache_size_word     ;
582    delete [] dcache_associativity ;
583    delete [] dcache_hit_latence   ;
584    delete [] dcache_miss_penality ;
585  }
586
587  cout << "<main> End" << endl;
588 
589  return EXIT_SUCCESS;
590}
Note: See TracBrowser for help on using the repository browser.