summaryrefslogtreecommitdiff
path: root/cpu/beta_cpu/2bit_local_pred.hh
blob: 6f9b9eedcb27596cd30602f0d931ad460b419af9 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __CPU_BETA_CPU_2BIT_LOCAL_PRED_HH__
#define __CPU_BETA_CPU_2BIT_LOCAL_PRED_HH__

// For Addr type.
#include "arch/alpha/isa_traits.hh"
#include "cpu/beta_cpu/sat_counter.hh"

class DefaultBP
{
  public:
    /**
     * Default branch predictor constructor.
     */
    DefaultBP(unsigned localPredictorSize, unsigned localCtrBits,
              unsigned instShiftAmt);

    /**
     * Looks up the given address in the branch predictor and returns
     * a true/false value as to whether it is taken.
     * @param branch_addr The address of the branch to look up.
     * @return Whether or not the branch is taken.
     */
    bool lookup(Addr &branch_addr);

    /**
     * Updates the branch predictor with the actual result of a branch.
     * @param branch_addr The address of the branch to update.
     * @param taken Whether or not the branch was taken.
     */
    void update(Addr &branch_addr, bool taken);

  private:

    /** Returns the taken/not taken prediction given the value of the
     *  counter.
     */
    inline bool getPrediction(uint8_t &count);

    /** Calculates the local index based on the PC. */
    inline unsigned getLocalIndex(Addr &PC);

    /** Array of counters that make up the local predictor. */
    SatCounter *localCtrs;

    /** Size of the local predictor. */
    unsigned localPredictorSize;

    /** Number of bits of the local predictor's counters. */
    unsigned localCtrBits;

    /** Number of bits to shift the PC when calculating index. */
    unsigned instShiftAmt;

    /** Mask to get index bits. */
    unsigned indexMask;
};

#endif // __CPU_BETA_CPU_2BIT_LOCAL_PRED_HH__