1: <?php
2:
3: namespace Csim\Model;
4:
5: 6: 7:
8: class Set {
9:
10: private $tag;
11: private $layout;
12:
13: 14: 15: 16:
17: public function __construct(\Csim\Model\CacheLayout $layout) {
18: $this->layout = $layout;
19: $this->size = $layout->getBlockCount() * $layout->getBlockSize();
20: $this->tag_size = $layout->getTagBits();
21: }
22:
23: 24: 25: 26: 27: 28:
29: public function loadAddress($address) {
30: $this->tag = $address & $this->layout->getTagBitMask();
31: $index = ($address & $this->layout->getIndexBitMask()) >> $this->layout->getOffsetBits();
32: return $index;
33: }
34:
35: 36: 37: 38: 39: 40: 41: 42:
43: public function addressLocation(\Csim\Model\Instruction $instruction) {
44: if ($instruction->addressEquals($this->tag, $this->layout->getTagBitMask())) {
45: $index = ($this->layout->getIndexBitMask() & $instruction->getAddress()) >>
46: $this->layout->getOffsetBits();
47: $offset = $this->layout->getOffsetBitMask() & $instruction->getAddress();
48: return new \Csim\Model\CacheCell(0, $index, $offset);
49: } else {
50: return NULL;
51: }
52: }
53:
54: }
55: