base_set_assoc.cc (12545:13eaf39f933b) base_set_assoc.cc (12548:285f1792a2da)
1/*
2 * Copyright (c) 2012-2014 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

--- 42 unchanged lines hidden (view full) ---

51
52#include "base/intmath.hh"
53#include "sim/core.hh"
54
55using namespace std;
56
57BaseSetAssoc::BaseSetAssoc(const Params *p)
58 :BaseTags(p), assoc(p->assoc), allocAssoc(p->assoc),
1/*
2 * Copyright (c) 2012-2014 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

--- 42 unchanged lines hidden (view full) ---

51
52#include "base/intmath.hh"
53#include "sim/core.hh"
54
55using namespace std;
56
57BaseSetAssoc::BaseSetAssoc(const Params *p)
58 :BaseTags(p), assoc(p->assoc), allocAssoc(p->assoc),
59 blks(p->size / p->block_size),
60 dataBlks(new uint8_t[p->size]), // Allocate data storage in one big chunk
59 numSets(p->size / (p->block_size * p->assoc)),
61 numSets(p->size / (p->block_size * p->assoc)),
60 sequentialAccess(p->sequential_access)
62 sequentialAccess(p->sequential_access),
63 sets(p->size / (p->block_size * p->assoc))
61{
62 // Check parameters
63 if (blkSize < 4 || !isPowerOf2(blkSize)) {
64 fatal("Block size must be at least 4 and a power of 2");
65 }
66 if (!isPowerOf2(numSets)) {
67 fatal("# of sets must be non-zero and a power of 2");
68 }
69 if (assoc <= 0) {
70 fatal("associativity must be greater than zero");
71 }
72
73 setShift = floorLog2(blkSize);
74 setMask = numSets - 1;
75 tagShift = setShift + floorLog2(numSets);
76
64{
65 // Check parameters
66 if (blkSize < 4 || !isPowerOf2(blkSize)) {
67 fatal("Block size must be at least 4 and a power of 2");
68 }
69 if (!isPowerOf2(numSets)) {
70 fatal("# of sets must be non-zero and a power of 2");
71 }
72 if (assoc <= 0) {
73 fatal("associativity must be greater than zero");
74 }
75
76 setShift = floorLog2(blkSize);
77 setMask = numSets - 1;
78 tagShift = setShift + floorLog2(numSets);
79
77 sets = new SetType[numSets];
78 blks = new BlkType[numSets * assoc];
79 // allocate data storage in one big chunk
80 numBlocks = numSets * assoc;
81 dataBlks = new uint8_t[numBlocks * blkSize];
82
83 unsigned blkIndex = 0; // index into blks array
84 for (unsigned i = 0; i < numSets; ++i) {
85 sets[i].assoc = assoc;
86
87 sets[i].blks.resize(assoc);
88
89 // link in the data blocks
90 for (unsigned j = 0; j < assoc; ++j) {

--- 14 unchanged lines hidden (view full) ---

105 blk->isTouched = false;
106 sets[i].blks[j]=blk;
107 blk->set = i;
108 blk->way = j;
109 }
110 }
111}
112
80 unsigned blkIndex = 0; // index into blks array
81 for (unsigned i = 0; i < numSets; ++i) {
82 sets[i].assoc = assoc;
83
84 sets[i].blks.resize(assoc);
85
86 // link in the data blocks
87 for (unsigned j = 0; j < assoc; ++j) {

--- 14 unchanged lines hidden (view full) ---

102 blk->isTouched = false;
103 sets[i].blks[j]=blk;
104 blk->set = i;
105 blk->way = j;
106 }
107 }
108}
109
113BaseSetAssoc::~BaseSetAssoc()
114{
115 delete [] dataBlks;
116 delete [] blks;
117 delete [] sets;
118}
119
120CacheBlk*
121BaseSetAssoc::findBlock(Addr addr, bool is_secure) const
122{
123 Addr tag = extractTag(addr);
124 unsigned set = extractSet(addr);
125 BlkType *blk = sets[set].findBlk(tag, is_secure);
126 return blk;
127}

--- 68 unchanged lines hidden ---
110CacheBlk*
111BaseSetAssoc::findBlock(Addr addr, bool is_secure) const
112{
113 Addr tag = extractTag(addr);
114 unsigned set = extractSet(addr);
115 BlkType *blk = sets[set].findBlk(tag, is_secure);
116 return blk;
117}

--- 68 unchanged lines hidden ---