bi_mode.hh revision 13626
11689SN/A/*
210330Smitch.hayenga@arm.com * Copyright (c) 2014 The Regents of The University of Michigan
38842Smrinmoy.ghosh@arm.com * All rights reserved.
48842Smrinmoy.ghosh@arm.com *
58842Smrinmoy.ghosh@arm.com * Redistribution and use in source and binary forms, with or without
68842Smrinmoy.ghosh@arm.com * modification, are permitted provided that the following conditions are
78842Smrinmoy.ghosh@arm.com * met: redistributions of source code must retain the above copyright
88842Smrinmoy.ghosh@arm.com * notice, this list of conditions and the following disclaimer;
98842Smrinmoy.ghosh@arm.com * redistributions in binary form must reproduce the above copyright
108842Smrinmoy.ghosh@arm.com * notice, this list of conditions and the following disclaimer in the
118842Smrinmoy.ghosh@arm.com * documentation and/or other materials provided with the distribution;
128842Smrinmoy.ghosh@arm.com * neither the name of the copyright holders nor the names of its
138842Smrinmoy.ghosh@arm.com * contributors may be used to endorse or promote products derived from
142329SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271689SN/A *
281689SN/A * Authors: Anthony Gutierrez
291689SN/A */
301689SN/A
311689SN/A/* @file
321689SN/A * Implementation of a bi-mode branch predictor
331689SN/A */
341689SN/A
351689SN/A#ifndef __CPU_PRED_BI_MODE_PRED_HH__
361689SN/A#define __CPU_PRED_BI_MODE_PRED_HH__
371689SN/A
381689SN/A#include "cpu/pred/bpred_unit.hh"
392665SN/A#include "cpu/pred/sat_counter.hh"
402665SN/A#include "params/BiModeBP.hh"
419480Snilay@cs.wisc.edu
421689SN/A/**
431689SN/A * Implements a bi-mode branch predictor. The bi-mode predictor is a two-level
449480Snilay@cs.wisc.edu * branch predictor that has three seprate history arrays: a taken array, a
459480Snilay@cs.wisc.edu * not-taken array, and a choice array. The taken/not-taken arrays are indexed
461061SN/A * by a hash of the PC and the global history. The choice array is indexed by
476216SN/A * the PC only. Because the taken/not-taken arrays use the same index, they must
486216SN/A * be the same size.
496216SN/A *
509480Snilay@cs.wisc.edu * The bi-mode branch predictor aims to eliminate the destructive aliasing that
519480Snilay@cs.wisc.edu * occurs when two branches of opposite biases share the same global history
5210785Sgope@wisc.edu * pattern. By separating the predictors into taken/not-taken arrays, and using
532292SN/A * the branch's PC to choose between the two, destructive aliasing is reduced.
542345SN/A */
552345SN/A
562345SN/Aclass BiModeBP : public BPredUnit
572345SN/A{
582345SN/A  public:
592345SN/A    BiModeBP(const BiModeBPParams *params);
602345SN/A    void uncondBranch(ThreadID tid, Addr pc, void * &bp_history);
619480Snilay@cs.wisc.edu    void squash(ThreadID tid, void *bp_history);
621061SN/A    bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history);
631061SN/A    void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history);
641061SN/A    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
651061SN/A                bool squashed, const StaticInstPtr & inst, Addr corrTarget);
661061SN/A    unsigned getGHR(ThreadID tid, void *bp_history) const;
6710785Sgope@wisc.edu
689480Snilay@cs.wisc.edu  private:
6911434Smitch.hayenga@arm.com    void updateGlobalHistReg(ThreadID tid, bool taken);
701061SN/A
711061SN/A    struct BPHistory {
721061SN/A        unsigned globalHistoryReg;
731061SN/A        // was the taken array's prediction used?
741061SN/A        // true: takenPred used
752345SN/A        // false: notPred used
761061SN/A        bool takenUsed;
771061SN/A        // prediction of the taken array
7811434Smitch.hayenga@arm.com        // true: predict taken
791061SN/A        // false: predict not-taken
801061SN/A        bool takenPred;
818842Smrinmoy.ghosh@arm.com        // prediction of the not-taken array
828842Smrinmoy.ghosh@arm.com        // true: predict taken
838842Smrinmoy.ghosh@arm.com        // false: predict not-taken
848842Smrinmoy.ghosh@arm.com        bool notTakenPred;
858842Smrinmoy.ghosh@arm.com        // the final taken/not-taken prediction
868842Smrinmoy.ghosh@arm.com        // true: predict taken
8711434Smitch.hayenga@arm.com        // false: predict not-taken
888842Smrinmoy.ghosh@arm.com        bool finalPred;
898842Smrinmoy.ghosh@arm.com    };
901061SN/A
911061SN/A    // choice predictors
921061SN/A    std::vector<SatCounter> choiceCounters;
931061SN/A    // taken direction predictors
9411434Smitch.hayenga@arm.com    std::vector<SatCounter> takenCounters;
9513626Sjairo.balart@metempsy.com    // not-taken direction predictors
962345SN/A    std::vector<SatCounter> notTakenCounters;
9711434Smitch.hayenga@arm.com
982345SN/A    std::vector<unsigned> globalHistoryReg;
991061SN/A    unsigned globalHistoryBits;
1002307SN/A    unsigned historyRegisterMask;
1012307SN/A
1021061SN/A    unsigned choicePredictorSize;
1032292SN/A    unsigned choiceCtrBits;
1042292SN/A    unsigned choiceHistoryMask;
1051684SN/A    unsigned globalPredictorSize;
1062292SN/A    unsigned globalCtrBits;
1072292SN/A    unsigned globalHistoryMask;
1081684SN/A
1091061SN/A    unsigned choiceThreshold;
1101061SN/A    unsigned takenThreshold;
1111684SN/A    unsigned notTakenThreshold;
1121061SN/A};
1131061SN/A
1141061SN/A#endif // __CPU_PRED_BI_MODE_PRED_HH__
1152292SN/A