source: trunk/src/cache_store.cpp @ 7

Last change on this file since 7 was 5, checked in by guillaumeb, 15 years ago

Réorganisation des dossiers

déplacement des fichiers source dans le sous dossier ./src
déplacement de systemc dans le sous-dossier ./lib

File size: 3.2 KB
Line 
1#include "cache_store.h"
2
3
4// FIXME is_loaded : addresse de block et non addresse absolues
5//    Le cache store ne stocke que des lignes et se moque des adresses
6
7/*
8bool CacheStore::is_loaded( list<int> *lines, int line)
9{
10    list<int>::iterator it;
11
12    //
13    // simple lookup : iterates over all elements and
14    // returns true if found
15    //
16    for(it = lines->begin(); it != lines->end(); ++it)
17    {
18        if(*it == line )
19            return true;
20    }
21
22    return false;
23}
24*/
25
26bool CacheStore::is_loaded(Address address)
27{
28    list<int>::iterator it;
29
30    if (associativity == DIRECT_MAPPING) {
31        // direct mapping :
32        //  the data is in a set determined by its modulo. The set size is 1
33        unsigned int location = address.block;
34        std::list<int> set = cache_lines[location];
35
36        // this should be only one iteration
37        for (it=set.begin(); it!= set.end(); ++it)
38        {
39            if (*it == address.block)
40                return true;
41        }
42        return false;
43
44    } else if (associativity == FULLY_ASSOCIATIVE) {
45        // fully associative :
46        //    the data can be anywhere in the set. There is only 1 set, and it is
47        //    in index 0
48
49        // FIXME URGENT CA PLANTE ICI
50        std::list<int> set = cache_lines[0];
51
52        for (it=set.begin(); it != set.end(); ++it)
53        {
54            if (*it == address.block)
55                return true;
56        }
57        return false;
58
59    } else {
60        // N-Way associative :
61        //    the data can be anywhere in a N-Set which position is given
62        //    by the modulo
63        unsigned int location = address.block;
64        std::list<int> set = cache_lines[location];
65
66        for (it = set.begin(); it != set.end(); ++it)
67        {
68            if (*it == address.block)
69                return true;
70        }
71        return false;
72    }
73}
74
75/*
76void CacheStore::do_load( list<int> *lines, int line)
77{
78   
79     * LRU placement :
80     * if the list contains more than *N* associativity
81     *  remove the oldest element (back)
82     *  and insert the new element (front)
83     *
84    if ( lines->size() >= associativity)
85        lines->pop_back();
86
87    lines->push_front(line);
88}*/
89
90int CacheStore::get_line_width()
91{
92    return this->line_width;
93}
94
95// FIXME harmonize between address.absolute % line_width
96//                  and    address.block
97void CacheStore::do_load(Address address)
98{
99   // LRU replacement :
100   // if the list contains more than *N* (assossiativity)
101   //   then remove the oldest element (back)
102   //   and insert the new element (front)
103   if (associativity ==  DIRECT_MAPPING) {
104       unsigned int location = address.as_absolute() % line_width;
105       if (cache_lines[location].size() >= associativity)
106           cache_lines[location].pop_back();
107
108       cache_lines[location].push_front(address.block);
109
110   } else if (associativity == FULLY_ASSOCIATIVE) {
111       if(cache_lines[0].size() >= num_lines)
112           cache_lines[0].pop_back();
113       cache_lines[0].push_front(address.block);
114   } else {
115
116       unsigned int location = address.block;
117       if(cache_lines[location].size() >= associativity)
118           cache_lines[location].pop_back();
119       cache_lines[location].push_front(address.block);
120   }
121}
Note: See TracBrowser for help on using the repository browser.