bi_mode.hh revision 13626:d6a6358aa6db
1298SN/A/* 22188SN/A * Copyright (c) 2014 The Regents of The University of Michigan 3298SN/A * All rights reserved. 4298SN/A * 5298SN/A * Redistribution and use in source and binary forms, with or without 6298SN/A * modification, are permitted provided that the following conditions are 7298SN/A * met: redistributions of source code must retain the above copyright 8298SN/A * notice, this list of conditions and the following disclaimer; 9298SN/A * redistributions in binary form must reproduce the above copyright 10298SN/A * notice, this list of conditions and the following disclaimer in the 11298SN/A * documentation and/or other materials provided with the distribution; 12298SN/A * neither the name of the copyright holders nor the names of its 13298SN/A * contributors may be used to endorse or promote products derived from 14298SN/A * this software without specific prior written permission. 15298SN/A * 16298SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17298SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18298SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19298SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20298SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21298SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22298SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23298SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24298SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25298SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26298SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Anthony Gutierrez 29298SN/A */ 30298SN/A 318543Sgblack@eecs.umich.edu/* @file 328543Sgblack@eecs.umich.edu * Implementation of a bi-mode branch predictor 338543Sgblack@eecs.umich.edu */ 342680Sktlim@umich.edu 35298SN/A#ifndef __CPU_PRED_BI_MODE_PRED_HH__ 362980Sgblack@eecs.umich.edu#define __CPU_PRED_BI_MODE_PRED_HH__ 376214Snate@binkert.org 382081SN/A#include "cpu/pred/bpred_unit.hh" 395504Snate@binkert.org#include "cpu/pred/sat_counter.hh" 40349SN/A#include "params/BiModeBP.hh" 415504Snate@binkert.org 425504Snate@binkert.org/** 435504Snate@binkert.org * Implements a bi-mode branch predictor. The bi-mode predictor is a two-level 445504Snate@binkert.org * branch predictor that has three seprate history arrays: a taken array, a 455504Snate@binkert.org * not-taken array, and a choice array. The taken/not-taken arrays are indexed 465504Snate@binkert.org * by a hash of the PC and the global history. The choice array is indexed by 475504Snate@binkert.org * the PC only. Because the taken/not-taken arrays use the same index, they must 485780Ssteve.reinhardt@amd.com * be the same size. 495504Snate@binkert.org * 505504Snate@binkert.org * The bi-mode branch predictor aims to eliminate the destructive aliasing that 518142SAli.Saidi@ARM.com * occurs when two branches of opposite biases share the same global history 525504Snate@binkert.org * pattern. By separating the predictors into taken/not-taken arrays, and using 535504Snate@binkert.org * the branch's PC to choose between the two, destructive aliasing is reduced. 545504Snate@binkert.org */ 555780Ssteve.reinhardt@amd.com 565780Ssteve.reinhardt@amd.comclass BiModeBP : public BPredUnit 575780Ssteve.reinhardt@amd.com{ 585780Ssteve.reinhardt@amd.com public: 595780Ssteve.reinhardt@amd.com BiModeBP(const BiModeBPParams *params); 605780Ssteve.reinhardt@amd.com void uncondBranch(ThreadID tid, Addr pc, void * &bp_history); 615741Snate@binkert.org void squash(ThreadID tid, void *bp_history); 625808Snate@binkert.org bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history); 635504Snate@binkert.org void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history); 645504Snate@binkert.org void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, 655504Snate@binkert.org bool squashed, const StaticInstPtr & inst, Addr corrTarget); 665504Snate@binkert.org unsigned getGHR(ThreadID tid, void *bp_history) const; 675504Snate@binkert.org 685504Snate@binkert.org private: 695504Snate@binkert.org void updateGlobalHistReg(ThreadID tid, bool taken); 707914SBrad.Beckmann@amd.com 717914SBrad.Beckmann@amd.com struct BPHistory { 725504Snate@binkert.org unsigned globalHistoryReg; 737811Ssteve.reinhardt@amd.com // was the taken array's prediction used? 748543Sgblack@eecs.umich.edu // true: takenPred used 758543Sgblack@eecs.umich.edu // false: notPred used 76 bool takenUsed; 77 // prediction of the taken array 78 // true: predict taken 79 // false: predict not-taken 80 bool takenPred; 81 // prediction of the not-taken array 82 // true: predict taken 83 // false: predict not-taken 84 bool notTakenPred; 85 // the final taken/not-taken prediction 86 // true: predict taken 87 // false: predict not-taken 88 bool finalPred; 89 }; 90 91 // choice predictors 92 std::vector<SatCounter> choiceCounters; 93 // taken direction predictors 94 std::vector<SatCounter> takenCounters; 95 // not-taken direction predictors 96 std::vector<SatCounter> notTakenCounters; 97 98 std::vector<unsigned> globalHistoryReg; 99 unsigned globalHistoryBits; 100 unsigned historyRegisterMask; 101 102 unsigned choicePredictorSize; 103 unsigned choiceCtrBits; 104 unsigned choiceHistoryMask; 105 unsigned globalPredictorSize; 106 unsigned globalCtrBits; 107 unsigned globalHistoryMask; 108 109 unsigned choiceThreshold; 110 unsigned takenThreshold; 111 unsigned notTakenThreshold; 112}; 113 114#endif // __CPU_PRED_BI_MODE_PRED_HH__ 115