summaryrefslogtreecommitdiff
path: root/inc/cache.h
blob: d9d8ba76cea4e3ca07d674bd03fa2103b2d67060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef CACHE_H
#define CACHE_H
#include "definitions.h"
#include "storage.h"
#include <array>
#include <bitset>

class Cache : public Storage
{
  public:
	/**
	 * Constructor.
	 * @param The number of `lines` contained in memory. The total number of
	 * words is this number multiplied by LINE_SIZE.
	 * @param The next lowest level in storage. Methods from this object are
	 * called in case of a cache miss.
	 * @param The number of clock cycles each access takes.
	 * @return A new cache object.
	 */
	Cache(int lines, Storage *lower, int delay);
	~Cache();

	Response write(Accessor accessor, signed int data, int address) override;
	Response read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) override;

  private:
	/**
	 * An array of paired bits.
	 * If the least significant bit of an element is set, the corresponding
	 * element in `data` is invalid. If the most significant bit of an element
	 * is set, the corresponding element in `data` is dirty.
	 */
	std::array<std::bitset<2>, L1_CACHE_SIZE> stat;
};

#endif /* CACHE_H_INCLUDED */