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