bi_mode.hh revision 13959:ea907b02c800
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com * Copyright (c) 2014 The Regents of The University of Michigan
312837Sgabeblack@google.com * All rights reserved.
412837Sgabeblack@google.com *
512837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612837Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112837Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412837Sgabeblack@google.com * this software without specific prior written permission.
1512837Sgabeblack@google.com *
1612837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712837Sgabeblack@google.com *
2812837Sgabeblack@google.com * Authors: Anthony Gutierrez
2912837Sgabeblack@google.com */
3012837Sgabeblack@google.com
3112837Sgabeblack@google.com/* @file
3212862Sgabeblack@google.com * Implementation of a bi-mode branch predictor
3312837Sgabeblack@google.com */
3412862Sgabeblack@google.com
3512837Sgabeblack@google.com#ifndef __CPU_PRED_BI_MODE_PRED_HH__
3612956Sgabeblack@google.com#define __CPU_PRED_BI_MODE_PRED_HH__
3712862Sgabeblack@google.com
3812837Sgabeblack@google.com#include "cpu/pred/bpred_unit.hh"
3912956Sgabeblack@google.com#include "cpu/pred/sat_counter.hh"
4012837Sgabeblack@google.com#include "params/BiModeBP.hh"
4112861Sgabeblack@google.com
4212837Sgabeblack@google.com/**
4312949Sgabeblack@google.com * Implements a bi-mode branch predictor. The bi-mode predictor is a two-level
4412949Sgabeblack@google.com * branch predictor that has three seprate history arrays: a taken array, a
4512837Sgabeblack@google.com * not-taken array, and a choice array. The taken/not-taken arrays are indexed
4612837Sgabeblack@google.com * by a hash of the PC and the global history. The choice array is indexed by
4712837Sgabeblack@google.com * the PC only. Because the taken/not-taken arrays use the same index, they must
4812837Sgabeblack@google.com * be the same size.
4912837Sgabeblack@google.com *
5012837Sgabeblack@google.com * The bi-mode branch predictor aims to eliminate the destructive aliasing that
5112837Sgabeblack@google.com * occurs when two branches of opposite biases share the same global history
5212837Sgabeblack@google.com * pattern. By separating the predictors into taken/not-taken arrays, and using
5312837Sgabeblack@google.com * the branch's PC to choose between the two, destructive aliasing is reduced.
5412837Sgabeblack@google.com */
5512837Sgabeblack@google.com
5612837Sgabeblack@google.comclass BiModeBP : public BPredUnit
5712862Sgabeblack@google.com{
5812862Sgabeblack@google.com  public:
5912862Sgabeblack@google.com    BiModeBP(const BiModeBPParams *params);
6012862Sgabeblack@google.com    void uncondBranch(ThreadID tid, Addr pc, void * &bp_history);
6112862Sgabeblack@google.com    void squash(ThreadID tid, void *bp_history);
6212949Sgabeblack@google.com    bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history);
6312949Sgabeblack@google.com    void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history);
6412949Sgabeblack@google.com    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
6512949Sgabeblack@google.com                bool squashed, const StaticInstPtr & inst, Addr corrTarget);
6612949Sgabeblack@google.com
6712949Sgabeblack@google.com  private:
6812862Sgabeblack@google.com    void updateGlobalHistReg(ThreadID tid, bool taken);
6912862Sgabeblack@google.com
7012862Sgabeblack@google.com    struct BPHistory {
7112862Sgabeblack@google.com        unsigned globalHistoryReg;
7212862Sgabeblack@google.com        // was the taken array's prediction used?
7312837Sgabeblack@google.com        // true: takenPred used
7412837Sgabeblack@google.com        // false: notPred used
7512837Sgabeblack@google.com        bool takenUsed;
7612837Sgabeblack@google.com        // prediction of the taken array
7712837Sgabeblack@google.com        // true: predict taken
7812837Sgabeblack@google.com        // false: predict not-taken
7912837Sgabeblack@google.com        bool takenPred;
8012837Sgabeblack@google.com        // prediction of the not-taken array
8112837Sgabeblack@google.com        // true: predict taken
8212837Sgabeblack@google.com        // false: predict not-taken
8312837Sgabeblack@google.com        bool notTakenPred;
8412837Sgabeblack@google.com        // the final taken/not-taken prediction
8512837Sgabeblack@google.com        // true: predict taken
8612837Sgabeblack@google.com        // false: predict not-taken
8712837Sgabeblack@google.com        bool finalPred;
8812837Sgabeblack@google.com    };
8912837Sgabeblack@google.com
9012837Sgabeblack@google.com    std::vector<unsigned> globalHistoryReg;
9112837Sgabeblack@google.com    unsigned globalHistoryBits;
9212837Sgabeblack@google.com    unsigned historyRegisterMask;
9312837Sgabeblack@google.com
9412837Sgabeblack@google.com    unsigned choicePredictorSize;
9512837Sgabeblack@google.com    unsigned choiceCtrBits;
9612837Sgabeblack@google.com    unsigned choiceHistoryMask;
9712837Sgabeblack@google.com    unsigned globalPredictorSize;
9812837Sgabeblack@google.com    unsigned globalCtrBits;
9912837Sgabeblack@google.com    unsigned globalHistoryMask;
10012837Sgabeblack@google.com
10112837Sgabeblack@google.com    // choice predictors
10212837Sgabeblack@google.com    std::vector<SatCounter> choiceCounters;
10312837Sgabeblack@google.com    // taken direction predictors
10412837Sgabeblack@google.com    std::vector<SatCounter> takenCounters;
10512837Sgabeblack@google.com    // not-taken direction predictors
10612837Sgabeblack@google.com    std::vector<SatCounter> notTakenCounters;
10712837Sgabeblack@google.com
10812837Sgabeblack@google.com    unsigned choiceThreshold;
10912837Sgabeblack@google.com    unsigned takenThreshold;
11012862Sgabeblack@google.com    unsigned notTakenThreshold;
11112837Sgabeblack@google.com};
11212837Sgabeblack@google.com
11312837Sgabeblack@google.com#endif // __CPU_PRED_BI_MODE_PRED_HH__
11412837Sgabeblack@google.com