2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Erik Hallnor
33 * Definitions of the Indirect Index Cache tagstore.
42 #include "mem/cache/base_cache.hh"
43 #include "mem/cache/tags/iic.hh"
44 #include "base/intmath.hh"
45 #include "sim/root.hh" // for curTick
47 #include "base/trace.hh" // for DPRINTF
52 /** Track the number of accesses to each cache set. */
55 IIC::IIC(IIC::Params
¶ms
) :
56 hashSets(params
.numSets
), blkSize(params
.blkSize
), assoc(params
.assoc
),
57 hitLatency(params
.hitLatency
), subSize(params
.subblockSize
),
58 numSub(blkSize
/subSize
),
59 trivialSize((floorLog2(params
.size
/subSize
)*numSub
)/8),
60 tagShift(floorLog2(blkSize
)), blkMask(blkSize
- 1),
61 subShift(floorLog2(subSize
)), subMask(numSub
- 1),
62 hashDelay(params
.hashDelay
),
63 numBlocks(params
.size
/subSize
),
64 numTags(hashSets
* assoc
+ params
.size
/blkSize
-1),
65 numSecondary(params
.size
/blkSize
),
67 primaryBound(hashSets
* assoc
)
72 if (blkSize
< 4 || !isPowerOf2(blkSize
)) {
73 fatal("Block size must be at least 4 and a power of 2");
75 if (hashSets
<= 0 || !isPowerOf2(hashSets
)) {
76 fatal("# of hashsets must be non-zero and a power of 2");
79 fatal("associativity must be greater than zero");
81 if (hitLatency
<= 0) {
82 fatal("access latency must be greater than zero");
84 if (numSub
*subSize
!= blkSize
) {
85 fatal("blocksize must be evenly divisible by subblock size");
89 freeSecond
= numSecondary
;
92 warmupBound
= params
.size
/blkSize
;
94 // Replacement Policy Initialization
100 // allocate data reference counters
101 dataReferenceCount
= new int[numBlocks
];
102 memset(dataReferenceCount
, 0, numBlocks
*sizeof(int));
104 // Allocate storage for both internal data and block fast access data.
105 // We allocate it as one large chunk to reduce overhead and to make
108 dataStore
= new uint8_t[(numBlocks
+ numTags
) * blkSize
];
109 dataBlks
= new uint8_t*[numBlocks
];
110 for (i
= 0; i
< numBlocks
; ++i
) {
111 dataBlks
[i
] = &dataStore
[data_index
];
113 data_index
+= subSize
;
116 assert(data_index
== numBlocks
* subSize
);
118 // allocate and init tag store
119 tagStore
= new IICTag
[numTags
];
122 // allocate and init sets
123 sets
= new IICSet
[hashSets
];
124 for (i
= 0; i
< hashSets
; ++i
) {
125 sets
[i
].assoc
= assoc
;
126 sets
[i
].tags
= new IICTag
*[assoc
];
127 sets
[i
].chain_ptr
= tagNull
;
129 for (int j
= 0; j
< assoc
; ++j
) {
130 IICTag
*tag
= &tagStore
[blkIndex
++];
131 tag
->chain_ptr
= tagNull
;
132 tag
->data_ptr
.resize(numSub
);
134 tag
->trivialData
= new uint8_t[trivialSize
];
136 sets
[i
].tags
[j
] = tag
;
138 tag
->data
= &dataStore
[data_index
];
139 data_index
+= blkSize
;
143 assert(blkIndex
== primaryBound
);
145 for (i
= primaryBound
; i
< tagNull
; i
++) {
146 tagStore
[i
].chain_ptr
= i
+1;
147 //setup data ptrs to subblocks
148 tagStore
[i
].data_ptr
.resize(numSub
);
149 tagStore
[i
].size
= blkSize
;
150 tagStore
[i
].trivialData
= new uint8_t[trivialSize
];
151 tagStore
[i
].numData
= 0;
153 tagStore
[i
].data
= &dataStore
[data_index
];
154 data_index
+= blkSize
;
156 freelist
= primaryBound
;
161 delete [] dataReferenceCount
;
167 /* register cache stats */
169 IIC::regStats(const string
&name
)
171 using namespace Stats
;
173 BaseTags::regStats(name
);
175 hitHashDepth
.init(0, 20, 1);
176 missHashDepth
.init(0, 20, 1);
177 setAccess
.init(0, hashSets
, 1);
179 /** IIC Statistics */
181 .name(name
+ ".hit_hash_depth_dist")
182 .desc("Dist. of Hash lookup depths")
187 .name(name
+ ".miss_hash_depth_dist")
188 .desc("Dist. of Hash lookup depths")
192 repl
->regStats(name
);
196 .name(name
+ ".set_access_dist")
197 .desc("Dist. of Accesses across sets")
202 .name(name
+ ".miss_depth_total")
203 .desc("Total of miss depths")
207 .name(name
+ ".hash_miss")
208 .desc("Total of misses in hash table")
212 .name(name
+ ".hit_depth_total")
213 .desc("Total of hit depths")
217 .name(name
+ ".hash_hit")
218 .desc("Total of hites in hash table")
222 // probe cache for presence of given block.
224 IIC::probe(Addr addr
) const
226 return (findBlock(addr
) != NULL
);
230 IIC::findBlock(Addr addr
, int &lat
)
232 Addr tag
= extractTag(addr
);
233 unsigned set
= hash(addr
);
236 unsigned long chain_ptr
;
239 setAccess
.sample(set
);
241 IICTag
*tag_ptr
= sets
[set
].findTag(tag
, chain_ptr
);
243 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
245 tag_ptr
= secondaryChain(tag
, chain_ptr
, &secondary_depth
);
246 set_lat
+= secondary_depth
;
247 // set depth for statistics fix this later!!! egh
248 sets
[set
].depth
= set_lat
;
250 if (tag_ptr
!= NULL
) {
251 /* need to move tag into primary table */
252 // need to preserve chain: fix this egh
253 sets
[set
].tags
[assoc
-1]->chain_ptr
= tag_ptr
->chain_ptr
;
254 tagSwap(tag_ptr
- tagStore
, sets
[set
].tags
[assoc
-1] - tagStore
);
255 tag_ptr
= sets
[set
].findTag(tag
, chain_ptr
);
256 assert(tag_ptr
!=NULL
);
260 set_lat
= set_lat
* hashDelay
+ hitLatency
;
261 if (tag_ptr
!= NULL
) {
262 // IIC replacement: if this is not the first element of
264 sets
[set
].moveToHead(tag_ptr
);
266 hitHashDepth
.sample(sets
[set
].depth
);
268 hitDepthTotal
+= sets
[set
].depth
;
269 tag_ptr
->status
|= BlkReferenced
;
271 if (tag_ptr
->whenReady
> curTick
&& tag_ptr
->whenReady
- curTick
> set_lat
) {
272 lat
= tag_ptr
->whenReady
- curTick
;
275 tag_ptr
->refCount
+= 1;
278 // fall through: cache block not found, not a hit...
279 missHashDepth
.sample(sets
[set
].depth
);
281 missDepthTotal
+= sets
[set
].depth
;
288 IIC::findBlock(Packet
* &pkt
, int &lat
)
290 Addr addr
= pkt
->getAddr();
292 Addr tag
= extractTag(addr
);
293 unsigned set
= hash(addr
);
296 unsigned long chain_ptr
;
299 setAccess
.sample(set
);
301 IICTag
*tag_ptr
= sets
[set
].findTag(tag
, chain_ptr
);
303 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
305 tag_ptr
= secondaryChain(tag
, chain_ptr
, &secondary_depth
);
306 set_lat
+= secondary_depth
;
307 // set depth for statistics fix this later!!! egh
308 sets
[set
].depth
= set_lat
;
310 if (tag_ptr
!= NULL
) {
311 /* need to move tag into primary table */
312 // need to preserve chain: fix this egh
313 sets
[set
].tags
[assoc
-1]->chain_ptr
= tag_ptr
->chain_ptr
;
314 tagSwap(tag_ptr
- tagStore
, sets
[set
].tags
[assoc
-1] - tagStore
);
315 tag_ptr
= sets
[set
].findTag(tag
, chain_ptr
);
316 assert(tag_ptr
!=NULL
);
320 set_lat
= set_lat
* hashDelay
+ hitLatency
;
321 if (tag_ptr
!= NULL
) {
322 // IIC replacement: if this is not the first element of
324 sets
[set
].moveToHead(tag_ptr
);
326 hitHashDepth
.sample(sets
[set
].depth
);
328 hitDepthTotal
+= sets
[set
].depth
;
329 tag_ptr
->status
|= BlkReferenced
;
331 if (tag_ptr
->whenReady
> curTick
&& tag_ptr
->whenReady
- curTick
> set_lat
) {
332 lat
= tag_ptr
->whenReady
- curTick
;
335 tag_ptr
->refCount
+= 1;
338 // fall through: cache block not found, not a hit...
339 missHashDepth
.sample(sets
[set
].depth
);
341 missDepthTotal
+= sets
[set
].depth
;
348 IIC::findBlock(Addr addr
) const
350 Addr tag
= extractTag(addr
);
351 unsigned set
= hash(addr
);
353 unsigned long chain_ptr
;
355 IICTag
*tag_ptr
= sets
[set
].findTag(tag
, chain_ptr
);
356 if (tag_ptr
== NULL
&& chain_ptr
!= tagNull
) {
358 tag_ptr
= secondaryChain(tag
, chain_ptr
, &secondary_depth
);
365 IIC::findReplacement(Packet
* &pkt
, PacketList
&writebacks
,
366 BlkList
&compress_blocks
)
368 DPRINTF(IIC
, "Finding Replacement for %x\n", pkt
->getAddr());
369 unsigned set
= hash(pkt
->getAddr());
371 unsigned long *tmp_data
= new unsigned long[numSub
];
373 // Get a enough subblocks for a full cache line
374 for (int i
= 0; i
< numSub
; ++i
){
375 tmp_data
[i
] = getFreeDataBlock(writebacks
);
376 assert(dataReferenceCount
[tmp_data
[i
]]==0);
379 tag_ptr
= getFreeTag(set
, writebacks
);
382 for (int i
=0; i
< numSub
; ++i
) {
383 tag_ptr
->data_ptr
[i
] = tmp_data
[i
];
384 dataReferenceCount
[tag_ptr
->data_ptr
[i
]]++;
386 tag_ptr
->numData
= numSub
;
387 assert(tag_ptr
- tagStore
< primaryBound
); // make sure it is in primary
388 tag_ptr
->chain_ptr
= tagNull
;
389 sets
[set
].moveToHead(tag_ptr
);
392 list
<unsigned long> tag_indexes
;
393 repl
->doAdvance(tag_indexes
);
394 while (!tag_indexes
.empty()) {
395 if (!tagStore
[tag_indexes
.front()].isCompressed()) {
396 compress_blocks
.push_back(&tagStore
[tag_indexes
.front()]);
398 tag_indexes
.pop_front();
401 tag_ptr
->re
= (void*)repl
->add(tag_ptr
-tagStore
);
407 IIC::freeReplacementBlock(PacketList
& writebacks
)
410 unsigned long data_ptr
;
411 /* consult replacement policy */
412 tag_ptr
= &tagStore
[repl
->getRepl()];
413 assert(tag_ptr
->isValid());
415 DPRINTF(Cache
, "Replacing %x in IIC: %s\n",
416 regenerateBlkAddr(tag_ptr
->tag
,0),
417 tag_ptr
->isModified() ? "writeback" : "clean");
418 /* write back replaced block data */
419 if (tag_ptr
&& (tag_ptr
->isValid())) {
421 totalRefs
+= tag_ptr
->refCount
;
423 tag_ptr
->refCount
= 0;
425 if (tag_ptr
->isModified()) {
426 /* Packet * writeback =
427 buildWritebackReq(regenerateBlkAddr(tag_ptr->tag, 0),
428 tag_ptr->req->asid, tag_ptr->xc, blkSize,
432 Request
*writebackReq
= new Request(regenerateBlkAddr(tag_ptr
->tag
, 0),
434 Packet
*writeback
= new Packet(writebackReq
, Packet::Writeback
, -1);
435 writeback
->allocate();
436 memcpy(writeback
->getPtr
<uint8_t>(), tag_ptr
->data
, blkSize
);
438 writebacks
.push_back(writeback
);
442 // free the data blocks
443 for (int i
= 0; i
< tag_ptr
->numData
; ++i
) {
444 data_ptr
= tag_ptr
->data_ptr
[i
];
445 assert(dataReferenceCount
[data_ptr
]>0);
446 if (--dataReferenceCount
[data_ptr
] == 0) {
447 freeDataBlock(data_ptr
);
454 IIC::getFreeDataBlock(PacketList
& writebacks
)
456 struct IICTag
*tag_ptr
;
457 unsigned long data_ptr
;
460 /* find data block */
461 while (blkFreelist
.empty()) {
462 freeReplacementBlock(writebacks
);
465 data_ptr
= blkFreelist
.front();
466 blkFreelist
.pop_front();
467 DPRINTF(IICMore
,"Found free data at %d\n",data_ptr
);
474 IIC::getFreeTag(int set
, PacketList
& writebacks
)
476 unsigned long tag_index
;
479 tag_ptr
= sets
[set
].findFree();
480 // if no free in primary, and secondary exists
481 if (!tag_ptr
&& numSecondary
) {
482 // need to spill a tag into secondary storage
483 while (freelist
== tagNull
) {
484 // get replacements until one is in secondary
485 freeReplacementBlock(writebacks
);
488 tag_index
= freelist
;
489 freelist
= tagStore
[freelist
].chain_ptr
;
492 assert(tag_index
!= tagNull
);
493 tagSwap(tag_index
, sets
[set
].tags
[assoc
-1] - tagStore
);
494 tagStore
[tag_index
].chain_ptr
= sets
[set
].chain_ptr
;
495 sets
[set
].chain_ptr
= tag_index
;
497 tag_ptr
= sets
[set
].tags
[assoc
-1];
499 DPRINTF(IICMore
,"Found free tag at %d\n",tag_ptr
- tagStore
);
501 if (!warmedUp
&& tagsInUse
.value() >= warmupBound
) {
503 warmupCycle
= curTick
;
510 IIC::freeTag(IICTag
*tag_ptr
)
512 unsigned long tag_index
, tmp_index
;
515 // we have a tag to clear
516 DPRINTF(IICMore
,"Freeing Tag for %x\n",
517 regenerateBlkAddr(tag_ptr
->tag
,0));
520 tag_ptr
->numData
= 0;
522 tag_index
= tag_ptr
- tagStore
;
523 if (tag_index
>= primaryBound
) {
524 // tag_ptr points to secondary store
525 assert(tag_index
< tagNull
); // remove this?? egh
526 if (tag_ptr
->chain_ptr
== tagNull
) {
527 // need to fix chain list
528 unsigned tmp_set
= hash(tag_ptr
->tag
<< tagShift
);
529 if (sets
[tmp_set
].chain_ptr
== tag_index
) {
530 sets
[tmp_set
].chain_ptr
= tagNull
;
532 tmp_index
= sets
[tmp_set
].chain_ptr
;
533 while (tmp_index
!= tagNull
534 && tagStore
[tmp_index
].chain_ptr
!= tag_index
) {
535 tmp_index
= tagStore
[tmp_index
].chain_ptr
;
537 assert(tmp_index
!= tagNull
);
538 tagStore
[tmp_index
].chain_ptr
= tagNull
;
540 tag_ptr
->chain_ptr
= freelist
;
541 freelist
= tag_index
;
544 // copy next chained entry to this tag location
545 tmp_index
= tag_ptr
->chain_ptr
;
546 tagSwap(tmp_index
, tag_index
);
547 tagStore
[tmp_index
].chain_ptr
= freelist
;
548 freelist
= tmp_index
;
552 // tag_ptr in primary hash table
553 assert(tag_index
< primaryBound
);
555 unsigned tmp_set
= hash(tag_ptr
->tag
<< tagShift
);
556 if (sets
[tmp_set
].chain_ptr
!= tagNull
) { // collapse chain
557 tmp_index
= sets
[tmp_set
].chain_ptr
;
558 tagSwap(tag_index
, tmp_index
);
559 tagStore
[tmp_index
].chain_ptr
= freelist
;
560 freelist
= tmp_index
;
562 sets
[tmp_set
].chain_ptr
= tag_ptr
->chain_ptr
;
563 sets
[tmp_set
].moveToTail(tag_ptr
);
570 IIC::freeDataBlock(unsigned long data_ptr
)
572 assert(dataReferenceCount
[data_ptr
] == 0);
573 DPRINTF(IICMore
, "Freeing data at %d\n", data_ptr
);
574 blkFreelist
.push_front(data_ptr
);
577 /** Use a simple modulo hash. */
578 #define SIMPLE_HASH 0
581 IIC::hash(Addr addr
) const {
583 return extractTag(addr
) % iic_hash_size
;
585 Addr tag
, mask
, x
, y
;
586 tag
= extractTag(addr
);
587 mask
= hashSets
-1; /* assumes iic_hash_size is a power of 2 */
589 y
= (tag
>> (int)(::log(hashSets
)/::log(2))) & mask
;
590 assert (x
< hashSets
&& y
< hashSets
);
597 IICSet::moveToHead(IICTag
*tag
)
602 // write 'next' block into blks[i], moving up from MRU toward LRU
603 // until we overwrite the block we moved to head.
605 // start by setting up to write 'blk' into blks[0]
611 // swap blks[i] and next
612 IICTag
*tmp
= tags
[i
];
616 } while (next
!= tag
);
620 IICSet::moveToTail(IICTag
*tag
)
622 if (tags
[assoc
-1] == tag
)
625 // write 'next' block into blks[i], moving up from MRU toward LRU
626 // until we overwrite the block we moved to head.
628 // start by setting up to write 'blk' into blks[0]
634 // swap blks[i] and next
635 IICTag
*tmp
= tags
[i
];
639 } while (next
!= tag
);
643 IIC::tagSwap(unsigned long index1
, unsigned long index2
)
645 DPRINTF(IIC
,"Swapping tag[%d]=%x for tag[%d]=%x\n",index1
,
646 tagStore
[index1
].tag
<<tagShift
, index2
,
647 tagStore
[index2
].tag
<<tagShift
);
649 tmp_tag
= tagStore
[index1
];
650 tagStore
[index1
] = tagStore
[index2
];
651 tagStore
[index2
] = tmp_tag
;
652 if (tagStore
[index1
].isValid())
653 repl
->fixTag(tagStore
[index1
].re
, index2
, index1
);
654 if (tagStore
[index2
].isValid())
655 repl
->fixTag(tagStore
[index2
].re
, index1
, index2
);
660 IIC::secondaryChain(Addr tag
, unsigned long chain_ptr
,
664 while (chain_ptr
!= tagNull
) {
665 DPRINTF(IIC
,"Searching secondary at %d for %x\n", chain_ptr
,
667 if (tagStore
[chain_ptr
].tag
== tag
&&
668 (tagStore
[chain_ptr
].isValid())) {
670 return &tagStore
[chain_ptr
];
673 chain_ptr
= tagStore
[chain_ptr
].chain_ptr
;
680 IIC::decompressBlock(unsigned long index
)
682 IICTag
*tag_ptr
= &tagStore
[index
];
683 if (tag_ptr
->isCompressed()) {
684 // decompress the data here.
689 IIC::compressBlock(unsigned long index
)
691 IICTag
*tag_ptr
= &tagStore
[index
];
692 if (!tag_ptr
->isCompressed()) {
693 // Compress the data here.
698 IIC::invalidateBlk(Addr addr
)
700 IICTag
* tag_ptr
= findBlock(addr
);
702 for (int i
= 0; i
< tag_ptr
->numData
; ++i
) {
703 dataReferenceCount
[tag_ptr
->data_ptr
[i
]]--;
704 if (dataReferenceCount
[tag_ptr
->data_ptr
[i
]] == 0) {
705 freeDataBlock(tag_ptr
->data_ptr
[i
]);
708 repl
->removeEntry(tag_ptr
->re
);
714 IIC::readData(IICTag
*blk
, uint8_t *data
){
715 // assert(cache->doData());
716 assert(blk
->size
<= trivialSize
|| blk
->numData
> 0);
717 int data_size
= blk
->size
;
718 if (data_size
> trivialSize
) {
719 for (int i
= 0; i
< blk
->numData
; ++i
){
720 memcpy(data
+i
*subSize
,
721 &(dataBlks
[blk
->data_ptr
[i
]][0]),
722 (data_size
>subSize
)?subSize
:data_size
);
723 data_size
-= subSize
;
726 memcpy(data
,blk
->trivialData
,data_size
);
731 IIC::writeData(IICTag
*blk
, uint8_t *write_data
, int size
,
732 PacketList
& writebacks
){
733 // assert(cache->doData());
734 assert(size
< blkSize
|| !blk
->isCompressed());
735 DPRINTF(IIC
, "Writing %d bytes to %x\n", size
,
737 // Find the number of subblocks needed, (round up)
738 int num_subs
= (size
+ (subSize
-1))/subSize
;
739 if (size
<= trivialSize
) {
742 assert(num_subs
<= numSub
);
743 if (num_subs
> blk
->numData
) {
744 // need to allocate more data blocks
745 for (int i
= blk
->numData
; i
< num_subs
; ++i
){
746 blk
->data_ptr
[i
] = getFreeDataBlock(writebacks
);
747 dataReferenceCount
[blk
->data_ptr
[i
]] += 1;
749 } else if (num_subs
< blk
->numData
){
750 // can free data blocks
751 for (int i
=num_subs
; i
< blk
->numData
; ++i
){
752 // decrement reference count and compare to zero
755 * Make this work with copying.
757 if (--dataReferenceCount
[blk
->data_ptr
[i
]] == 0) {
758 freeDataBlock(blk
->data_ptr
[i
]);
763 blk
->numData
= num_subs
;
765 assert(size
<= trivialSize
|| blk
->numData
> 0);
766 if (size
> trivialSize
){
767 for (int i
= 0; i
< blk
->numData
; ++i
){
768 memcpy(&dataBlks
[blk
->data_ptr
[i
]][0], write_data
+ i
*subSize
,
769 (size
>subSize
)?subSize
:size
);
773 memcpy(blk
->trivialData
,write_data
,size
);
779 * @todo This code can break if the src is evicted to get a tag for the dest.
782 IIC::doCopy(Addr source
, Addr dest
, PacketList
&writebacks
)
784 //Copy unsuported now
786 IICTag
*dest_tag
= findBlock(dest
);
789 for (int i
= 0; i
< dest_tag
->numData
; ++i
) {
790 if (--dataReferenceCount
[dest_tag
->data_ptr
[i
]] == 0) {
791 freeDataBlock(dest_tag
->data_ptr
[i
]);
794 // Reset replacement entry
796 dest_tag
= getFreeTag(hash(dest
), writebacks
);
797 dest_tag
->re
= (void*) repl
->add(dest_tag
- tagStore
);
798 dest_tag
->set
= hash(dest
);
799 dest_tag
->tag
= extractTag(dest
);
800 dest_tag
->status
= BlkValid
| BlkWritable
;
802 // Find the source tag here since it might move if we need to find a
803 // tag for the destination.
804 IICTag
*src_tag
= findBlock(source
);
806 assert(!cache
->doData() || src_tag
->size
<= trivialSize
807 || src_tag
->numData
> 0);
808 // point dest to source data and inc counter
809 for (int i
= 0; i
< src_tag
->numData
; ++i
) {
810 dest_tag
->data_ptr
[i
] = src_tag
->data_ptr
[i
];
811 ++dataReferenceCount
[dest_tag
->data_ptr
[i
]];
814 // Maintain fast access data.
815 memcpy(dest_tag
->data
, src_tag
->data
, blkSize
);
817 dest_tag
->xc
= src_tag
->xc
;
818 dest_tag
->size
= src_tag
->size
;
819 dest_tag
->numData
= src_tag
->numData
;
820 if (src_tag
->numData
== 0) {
821 // Data is stored in the trivial data, just copy it.
822 memcpy(dest_tag
->trivialData
, src_tag
->trivialData
, src_tag
->size
);
825 dest_tag
->status
|= BlkDirty
;
826 if (dest_tag
->size
< blkSize
) {
827 dest_tag
->status
|= BlkCompressed
;
829 dest_tag
->status
&= ~BlkCompressed
;
835 IIC::fixCopy(Packet
* &pkt
, PacketList
&writebacks
)
838 // if reference counter is greater than 1, do copy
840 Addr blk_addr
= blkAlign(pkt
->getAddr
);
841 IICTag
* blk
= findBlock(blk_addr
);
843 if (blk
->numData
> 0 && dataReferenceCount
[blk
->data_ptr
[0]] != 1) {
845 // Mark the block as referenced so it doesn't get replaced.
846 blk
->status
|= BlkReferenced
;
847 for (int i
= 0; i
< blk
->numData
; ++i
){
848 unsigned long new_data
= getFreeDataBlock(writebacks
);
849 // Need to refresh pointer
851 * @todo Remove this refetch once we change IIC to pointer based
853 blk
= findBlock(blk_addr
);
855 if (cache
->doData()) {
856 memcpy(&(dataBlks
[new_data
][0]),
857 &(dataBlks
[blk
->data_ptr
[i
]][0]),
860 dataReferenceCount
[blk
->data_ptr
[i
]]--;
861 dataReferenceCount
[new_data
]++;
862 blk
->data_ptr
[i
] = new_data
;
871 for (int i
= 0; i
< numTags
; ++i
) {
872 if (tagStore
[i
].isValid()) {
873 totalRefs
+= tagStore
[i
].refCount
;