110244Satgutier@umich.edu/*
210244Satgutier@umich.edu * Copyright (c) 2014 The Regents of The University of Michigan
310244Satgutier@umich.edu * All rights reserved.
410244Satgutier@umich.edu *
510244Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without
610244Satgutier@umich.edu * modification, are permitted provided that the following conditions are
710244Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
810244Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
910244Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
1010244Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
1110244Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
1210244Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
1310244Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
1410244Satgutier@umich.edu * this software without specific prior written permission.
1510244Satgutier@umich.edu *
1610244Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710244Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810244Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910244Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010244Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110244Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210244Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310244Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410244Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510244Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610244Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710244Satgutier@umich.edu *
2810244Satgutier@umich.edu * Authors: Anthony Gutierrez
2910244Satgutier@umich.edu */
3010244Satgutier@umich.edu
3110244Satgutier@umich.edu/* @file
3210244Satgutier@umich.edu * Implementation of a bi-mode branch predictor
3310244Satgutier@umich.edu */
3410244Satgutier@umich.edu
3510244Satgutier@umich.edu#ifndef __CPU_PRED_BI_MODE_PRED_HH__
3610244Satgutier@umich.edu#define __CPU_PRED_BI_MODE_PRED_HH__
3710244Satgutier@umich.edu
3813960Sodanrc@yahoo.com.br#include "base/sat_counter.hh"
3910244Satgutier@umich.edu#include "cpu/pred/bpred_unit.hh"
4010785Sgope@wisc.edu#include "params/BiModeBP.hh"
4110244Satgutier@umich.edu
4210244Satgutier@umich.edu/**
4310244Satgutier@umich.edu * Implements a bi-mode branch predictor. The bi-mode predictor is a two-level
4410244Satgutier@umich.edu * branch predictor that has three seprate history arrays: a taken array, a
4510244Satgutier@umich.edu * not-taken array, and a choice array. The taken/not-taken arrays are indexed
4610244Satgutier@umich.edu * by a hash of the PC and the global history. The choice array is indexed by
4710244Satgutier@umich.edu * the PC only. Because the taken/not-taken arrays use the same index, they must
4810244Satgutier@umich.edu * be the same size.
4910244Satgutier@umich.edu *
5010244Satgutier@umich.edu * The bi-mode branch predictor aims to eliminate the destructive aliasing that
5110244Satgutier@umich.edu * occurs when two branches of opposite biases share the same global history
5210244Satgutier@umich.edu * pattern. By separating the predictors into taken/not-taken arrays, and using
5310244Satgutier@umich.edu * the branch's PC to choose between the two, destructive aliasing is reduced.
5410244Satgutier@umich.edu */
5510244Satgutier@umich.edu
5610244Satgutier@umich.educlass BiModeBP : public BPredUnit
5710244Satgutier@umich.edu{
5810244Satgutier@umich.edu  public:
5910785Sgope@wisc.edu    BiModeBP(const BiModeBPParams *params);
6011434Smitch.hayenga@arm.com    void uncondBranch(ThreadID tid, Addr pc, void * &bp_history);
6111434Smitch.hayenga@arm.com    void squash(ThreadID tid, void *bp_history);
6211434Smitch.hayenga@arm.com    bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history);
6311434Smitch.hayenga@arm.com    void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history);
6411434Smitch.hayenga@arm.com    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
6513626Sjairo.balart@metempsy.com                bool squashed, const StaticInstPtr & inst, Addr corrTarget);
6610244Satgutier@umich.edu
6710244Satgutier@umich.edu  private:
6811434Smitch.hayenga@arm.com    void updateGlobalHistReg(ThreadID tid, bool taken);
6910244Satgutier@umich.edu
7010244Satgutier@umich.edu    struct BPHistory {
7110244Satgutier@umich.edu        unsigned globalHistoryReg;
7210244Satgutier@umich.edu        // was the taken array's prediction used?
7310244Satgutier@umich.edu        // true: takenPred used
7410244Satgutier@umich.edu        // false: notPred used
7510244Satgutier@umich.edu        bool takenUsed;
7610244Satgutier@umich.edu        // prediction of the taken array
7710244Satgutier@umich.edu        // true: predict taken
7810244Satgutier@umich.edu        // false: predict not-taken
7910244Satgutier@umich.edu        bool takenPred;
8010244Satgutier@umich.edu        // prediction of the not-taken array
8110244Satgutier@umich.edu        // true: predict taken
8210244Satgutier@umich.edu        // false: predict not-taken
8310244Satgutier@umich.edu        bool notTakenPred;
8410244Satgutier@umich.edu        // the final taken/not-taken prediction
8510244Satgutier@umich.edu        // true: predict taken
8610244Satgutier@umich.edu        // false: predict not-taken
8710244Satgutier@umich.edu        bool finalPred;
8810244Satgutier@umich.edu    };
8910244Satgutier@umich.edu
9011434Smitch.hayenga@arm.com    std::vector<unsigned> globalHistoryReg;
9110244Satgutier@umich.edu    unsigned globalHistoryBits;
9210244Satgutier@umich.edu    unsigned historyRegisterMask;
9310244Satgutier@umich.edu
9410244Satgutier@umich.edu    unsigned choicePredictorSize;
9510244Satgutier@umich.edu    unsigned choiceCtrBits;
9610244Satgutier@umich.edu    unsigned choiceHistoryMask;
9710244Satgutier@umich.edu    unsigned globalPredictorSize;
9810244Satgutier@umich.edu    unsigned globalCtrBits;
9910244Satgutier@umich.edu    unsigned globalHistoryMask;
10010244Satgutier@umich.edu
10113959Sodanrc@yahoo.com.br    // choice predictors
10213959Sodanrc@yahoo.com.br    std::vector<SatCounter> choiceCounters;
10313959Sodanrc@yahoo.com.br    // taken direction predictors
10413959Sodanrc@yahoo.com.br    std::vector<SatCounter> takenCounters;
10513959Sodanrc@yahoo.com.br    // not-taken direction predictors
10613959Sodanrc@yahoo.com.br    std::vector<SatCounter> notTakenCounters;
10713959Sodanrc@yahoo.com.br
10810244Satgutier@umich.edu    unsigned choiceThreshold;
10910244Satgutier@umich.edu    unsigned takenThreshold;
11010244Satgutier@umich.edu    unsigned notTakenThreshold;
11110244Satgutier@umich.edu};
11210244Satgutier@umich.edu
11310244Satgutier@umich.edu#endif // __CPU_PRED_BI_MODE_PRED_HH__
114