TBETable.hh revision 7039
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __MEM_RUBY_SYSTEM_TBETABLE_HH__
30#define __MEM_RUBY_SYSTEM_TBETABLE_HH__
31
32#include "mem/gems_common/Map.hh"
33#include "mem/ruby/common/Address.hh"
34#include "mem/ruby/common/Global.hh"
35#include "mem/ruby/profiler/Profiler.hh"
36#include "mem/ruby/system/System.hh"
37
38template<class ENTRY>
39class TBETable
40{
41  public:
42    TBETable(int number_of_TBEs)
43        : m_number_of_TBEs(number_of_TBEs)
44    {
45    }
46
47    void
48    printConfig(ostream& out)
49    {
50        out << "TBEs_per_TBETable: " << m_number_of_TBEs << endl;
51    }
52
53    bool isPresent(const Address& address) const;
54    void allocate(const Address& address);
55    void deallocate(const Address& address);
56    bool
57    areNSlotsAvailable(int n) const
58    {
59        return (m_number_of_TBEs - m_map.size()) >= n;
60    }
61
62    ENTRY& lookup(const Address& address);
63    const ENTRY& lookup(const Address& address) const;
64
65    // Print cache contents
66    void print(ostream& out) const;
67
68  private:
69    // Private copy constructor and assignment operator
70    TBETable(const TBETable& obj);
71    TBETable& operator=(const TBETable& obj);
72
73    // Data Members (m_prefix)
74    Map<Address, ENTRY> m_map;
75
76  private:
77    int m_number_of_TBEs;
78};
79
80template<class ENTRY>
81inline ostream&
82operator<<(ostream& out, const TBETable<ENTRY>& obj)
83{
84    obj.print(out);
85    out << flush;
86    return out;
87}
88
89template<class ENTRY>
90inline bool
91TBETable<ENTRY>::isPresent(const Address& address) const
92{
93    assert(address == line_address(address));
94    assert(m_map.size() <= m_number_of_TBEs);
95    return m_map.exist(address);
96}
97
98template<class ENTRY>
99inline void
100TBETable<ENTRY>::allocate(const Address& address)
101{
102    assert(isPresent(address) == false);
103    assert(m_map.size() < m_number_of_TBEs);
104    m_map.add(address, ENTRY());
105}
106
107template<class ENTRY>
108inline void
109TBETable<ENTRY>::deallocate(const Address& address)
110{
111    assert(isPresent(address) == true);
112    assert(m_map.size() > 0);
113    m_map.erase(address);
114}
115
116// looks an address up in the cache
117template<class ENTRY>
118inline ENTRY&
119TBETable<ENTRY>::lookup(const Address& address)
120{
121    assert(isPresent(address) == true);
122    return m_map.lookup(address);
123}
124
125// looks an address up in the cache
126template<class ENTRY>
127inline const ENTRY&
128TBETable<ENTRY>::lookup(const Address& address) const
129{
130    assert(isPresent(address) == true);
131    return m_map.lookup(address);
132}
133
134template<class ENTRY>
135inline void
136TBETable<ENTRY>::print(ostream& out) const
137{
138}
139
140#endif // __MEM_RUBY_SYSTEM_TBETABLE_HH__
141