bi_mode.hh revision 10785
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 3810244Satgutier@umich.edu#include "cpu/pred/bpred_unit.hh" 3910244Satgutier@umich.edu#include "cpu/pred/sat_counter.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); 6010785Sgope@wisc.edu void uncondBranch(Addr pc, void * &bp_history); 6110244Satgutier@umich.edu void squash(void *bp_history); 6210244Satgutier@umich.edu bool lookup(Addr branch_addr, void * &bp_history); 6310244Satgutier@umich.edu void btbUpdate(Addr branch_addr, void * &bp_history); 6410244Satgutier@umich.edu void update(Addr branch_addr, bool taken, void *bp_history, bool squashed); 6510244Satgutier@umich.edu void retireSquashed(void *bp_history); 6610244Satgutier@umich.edu 6710244Satgutier@umich.edu private: 6810244Satgutier@umich.edu void updateGlobalHistReg(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 9010244Satgutier@umich.edu // choice predictors 9110244Satgutier@umich.edu std::vector<SatCounter> choiceCounters; 9210244Satgutier@umich.edu // taken direction predictors 9310244Satgutier@umich.edu std::vector<SatCounter> takenCounters; 9410244Satgutier@umich.edu // not-taken direction predictors 9510244Satgutier@umich.edu std::vector<SatCounter> notTakenCounters; 9610244Satgutier@umich.edu 9710244Satgutier@umich.edu unsigned globalHistoryReg; 9810244Satgutier@umich.edu unsigned globalHistoryBits; 9910244Satgutier@umich.edu unsigned historyRegisterMask; 10010244Satgutier@umich.edu 10110244Satgutier@umich.edu unsigned choicePredictorSize; 10210244Satgutier@umich.edu unsigned choiceCtrBits; 10310244Satgutier@umich.edu unsigned choiceHistoryMask; 10410244Satgutier@umich.edu unsigned globalPredictorSize; 10510244Satgutier@umich.edu unsigned globalCtrBits; 10610244Satgutier@umich.edu unsigned globalHistoryMask; 10710244Satgutier@umich.edu 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