gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cacheset.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2009 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Lisa Hsu
41  */
42 
48 #ifndef __MEM_CACHE_TAGS_CACHESET_HH__
49 #define __MEM_CACHE_TAGS_CACHESET_HH__
50 
51 #include <cassert>
52 
56 template <class Blktype>
57 class CacheSet
58 {
59  public:
61  int assoc;
62 
64  Blktype **blks;
65 
73  Blktype* findBlk(Addr tag, bool is_secure, int& way_id) const ;
74  Blktype* findBlk(Addr tag, bool is_secure) const ;
75 
80  void moveToHead(Blktype *blk);
81 
86  void moveToTail(Blktype *blk);
87 
88 };
89 
90 template <class Blktype>
91 Blktype*
92 CacheSet<Blktype>::findBlk(Addr tag, bool is_secure, int& way_id) const
93 {
98  way_id = assoc;
99  for (int i = 0; i < assoc; ++i) {
100  if (blks[i]->tag == tag && blks[i]->isValid() &&
101  blks[i]->isSecure() == is_secure) {
102  way_id = i;
103  return blks[i];
104  }
105  }
106  return nullptr;
107 }
108 
109 template <class Blktype>
110 Blktype*
111 CacheSet<Blktype>::findBlk(Addr tag, bool is_secure) const
112 {
113  int ignored_way_id;
114  return findBlk(tag, is_secure, ignored_way_id);
115 }
116 
117 template <class Blktype>
118 void
120 {
121  // nothing to do if blk is already head
122  if (blks[0] == blk)
123  return;
124 
125  // write 'next' block into blks[i], moving up from MRU toward LRU
126  // until we overwrite the block we moved to head.
127 
128  // start by setting up to write 'blk' into blks[0]
129  int i = 0;
130  Blktype *next = blk;
131 
132  do {
133  assert(i < assoc);
134  std::swap(blks[i], next);
135  ++i;
136  } while (next != blk);
137 }
138 
139 template <class Blktype>
140 void
142 {
143  // nothing to do if blk is already tail
144  if (blks[assoc - 1] == blk)
145  return;
146 
147  // write 'next' block into blks[i], moving from LRU to MRU
148  // until we overwrite the block we moved to tail.
149 
150  // start by setting up to write 'blk' into tail
151  int i = assoc - 1;
152  Blktype *next = blk;
153 
154  do {
155  assert(i >= 0);
156  std::swap(blks[i], next);
157  --i;
158  } while (next != blk);
159 }
160 
161 #endif
Bitfield< 7 > i
Definition: miscregs.hh:1378
int assoc
The associativity of this set.
Definition: cacheset.hh:61
An associative set of cache blocks.
Definition: cacheset.hh:57
Blktype * findBlk(Addr tag, bool is_secure, int &way_id) const
Find a block matching the tag in this set.
Definition: cacheset.hh:92
Blktype ** blks
Cache blocks in this set, maintained in LRU order 0 = MRU.
Definition: cacheset.hh:64
void moveToHead(Blktype *blk)
Move the given block to the head of the list.
Definition: cacheset.hh:119
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
void moveToTail(Blktype *blk)
Move the given block to the tail of the list.
Definition: cacheset.hh:141

Generated on Fri Jun 9 2017 13:03:48 for gem5 by doxygen 1.8.6