Merge ktlim@zizzer.eecs.umich.edu:/bk/m5
[gem5.git] / cpu / beta_cpu / sat_counter.hh
1 #ifndef __CPU_BETA_CPU_SAT_COUNTER_HH__
2 #define __CPU_BETA_CPU_SAT_COUNTER_HH__
3
4 #include <stdint.h>
5
6 /**
7 * Private counter class for the internal saturating counters.
8 * Implements an n bit saturating counter and provides methods to
9 * increment, decrement, and read it.
10 * @todo Consider making this something that more closely mimics a
11 * built in class so you can use ++ or --.
12 */
13 class SatCounter
14 {
15 public:
16 /**
17 * Constructor for the counter.
18 */
19 SatCounter();
20
21 /**
22 * Constructor for the counter.
23 * @param bits How many bits the counter will have.
24 */
25 SatCounter(unsigned bits);
26
27 /**
28 * Constructor for the counter.
29 * @param bits How many bits the counter will have.
30 * @param initial_val Starting value for each counter.
31 */
32 SatCounter(unsigned bits, unsigned initial_val);
33
34 /**
35 * Sets the number of bits.
36 */
37 void setBits(unsigned bits);
38
39 /**
40 * Increments the counter's current value.
41 */
42 void increment();
43
44 /**
45 * Decrements the counter's current value.
46 */
47 void decrement();
48
49 /**
50 * Read the counter's value.
51 */
52 const uint8_t read() const
53 {
54 return counter;
55 }
56
57 private:
58 uint8_t maxVal;
59 uint8_t counter;
60 };
61
62 #endif // __CPU_BETA_CPU_SAT_COUNTER_HH__