Merge ktlim@zizzer.eecs.umich.edu:/bk/m5
[gem5.git] / cpu / beta_cpu / sat_counter.cc
1 #include "base/misc.hh"
2 #include "cpu/beta_cpu/sat_counter.hh"
3
4 SatCounter::SatCounter()
5 : maxVal(0), counter(0)
6 {
7 }
8
9 SatCounter::SatCounter(unsigned bits)
10 : maxVal((1 << bits) - 1), counter(0)
11 {
12 }
13
14 SatCounter::SatCounter(unsigned bits, unsigned initial_val)
15 : maxVal((1 << bits) - 1), counter(initial_val)
16 {
17 // Check to make sure initial value doesn't exceed the max counter value.
18 if (initial_val > maxVal) {
19 panic("BP: Initial counter value exceeds max size.");
20 }
21 }
22
23 void
24 SatCounter::setBits(unsigned bits)
25 {
26 maxVal = (1 << bits) - 1;
27 }
28
29 void
30 SatCounter::increment()
31 {
32 if(counter < maxVal) {
33 ++counter;
34 }
35 }
36
37 void
38 SatCounter::decrement()
39 {
40 if(counter > 0) {
41 --counter;
42 }
43 }