2bit_local.hh revision 10785
11689SN/A/* 210330Smitch.hayenga@arm.com * Copyright (c) 2011, 2014 ARM Limited 38842Smrinmoy.ghosh@arm.com * All rights reserved 48842Smrinmoy.ghosh@arm.com * 58842Smrinmoy.ghosh@arm.com * The license below extends only to copyright in the software and shall 68842Smrinmoy.ghosh@arm.com * not be construed as granting a license to any other intellectual 78842Smrinmoy.ghosh@arm.com * property including but not limited to intellectual property relating 88842Smrinmoy.ghosh@arm.com * to a hardware implementation of the functionality of the software 98842Smrinmoy.ghosh@arm.com * licensed hereunder. You may use the software subject to the license 108842Smrinmoy.ghosh@arm.com * terms below provided that you ensure that this notice is replicated 118842Smrinmoy.ghosh@arm.com * unmodified and in its entirety in all distributions of the software, 128842Smrinmoy.ghosh@arm.com * modified or unmodified, in source code or in binary form. 138842Smrinmoy.ghosh@arm.com * 142329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 271689SN/A * 281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Kevin Lim 419480Snilay@cs.wisc.edu * Timothy M. Jones 421689SN/A */ 431689SN/A 449480Snilay@cs.wisc.edu#ifndef __CPU_PRED_2BIT_LOCAL_PRED_HH__ 459480Snilay@cs.wisc.edu#define __CPU_PRED_2BIT_LOCAL_PRED_HH__ 461061SN/A 476216SN/A#include <vector> 486216SN/A 496216SN/A#include "base/types.hh" 509480Snilay@cs.wisc.edu#include "cpu/pred/bpred_unit.hh" 519480Snilay@cs.wisc.edu#include "cpu/pred/sat_counter.hh" 5210785Sgope@wisc.edu#include "params/LocalBP.hh" 532292SN/A 542345SN/A/** 552345SN/A * Implements a local predictor that uses the PC to index into a table of 562345SN/A * counters. Note that any time a pointer to the bp_history is given, it 572345SN/A * should be NULL using this predictor because it does not have any branch 582345SN/A * predictor state that needs to be recorded or updated; the update can be 592345SN/A * determined solely by the branch being taken or not taken. 602345SN/A */ 619480Snilay@cs.wisc.educlass LocalBP : public BPredUnit 621061SN/A{ 631061SN/A public: 641061SN/A /** 651061SN/A * Default branch predictor constructor. 661061SN/A */ 6710785Sgope@wisc.edu LocalBP(const LocalBPParams *params); 689480Snilay@cs.wisc.edu 6910785Sgope@wisc.edu virtual void uncondBranch(Addr pc, void * &bp_history); 701061SN/A 711061SN/A /** 721061SN/A * Looks up the given address in the branch predictor and returns 731061SN/A * a true/false value as to whether it is taken. 741061SN/A * @param branch_addr The address of the branch to look up. 752345SN/A * @param bp_history Pointer to any bp history state. 761061SN/A * @return Whether or not the branch is taken. 771061SN/A */ 789480Snilay@cs.wisc.edu bool lookup(Addr branch_addr, void * &bp_history); 791061SN/A 801061SN/A /** 818842Smrinmoy.ghosh@arm.com * Updates the branch predictor to Not Taken if a BTB entry is 828842Smrinmoy.ghosh@arm.com * invalid or not found. 838842Smrinmoy.ghosh@arm.com * @param branch_addr The address of the branch to look up. 848842Smrinmoy.ghosh@arm.com * @param bp_history Pointer to any bp history state. 858842Smrinmoy.ghosh@arm.com * @return Whether or not the branch is taken. 868842Smrinmoy.ghosh@arm.com */ 879480Snilay@cs.wisc.edu void btbUpdate(Addr branch_addr, void * &bp_history); 888842Smrinmoy.ghosh@arm.com 898842Smrinmoy.ghosh@arm.com /** 901061SN/A * Updates the branch predictor with the actual result of a branch. 911061SN/A * @param branch_addr The address of the branch to update. 921061SN/A * @param taken Whether or not the branch was taken. 931061SN/A */ 949480Snilay@cs.wisc.edu void update(Addr branch_addr, bool taken, void *bp_history, bool squashed); 952345SN/A 9610330Smitch.hayenga@arm.com void retireSquashed(void *bp_history) 9710330Smitch.hayenga@arm.com { assert(bp_history == NULL); } 9810330Smitch.hayenga@arm.com 992345SN/A void squash(void *bp_history) 1002345SN/A { assert(bp_history == NULL); } 1011061SN/A 1022307SN/A void reset(); 1032307SN/A 1041061SN/A private: 1052292SN/A /** 1062292SN/A * Returns the taken/not taken prediction given the value of the 1071684SN/A * counter. 1082292SN/A * @param count The value of the counter. 1092292SN/A * @return The prediction based on the counter value. 1101684SN/A */ 1111061SN/A inline bool getPrediction(uint8_t &count); 1121061SN/A 1131684SN/A /** Calculates the local index based on the PC. */ 1141061SN/A inline unsigned getLocalIndex(Addr &PC); 1151061SN/A 1161061SN/A /** Array of counters that make up the local predictor. */ 1172292SN/A std::vector<SatCounter> localCtrs; 1181061SN/A 1191061SN/A /** Size of the local predictor. */ 1201061SN/A unsigned localPredictorSize; 1211061SN/A 1222292SN/A /** Number of sets. */ 1232292SN/A unsigned localPredictorSets; 1242292SN/A 1251061SN/A /** Number of bits of the local predictor's counters. */ 1261061SN/A unsigned localCtrBits; 1271061SN/A 1281061SN/A /** Mask to get index bits. */ 1291061SN/A unsigned indexMask; 1301061SN/A}; 1311061SN/A 1329480Snilay@cs.wisc.edu#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__ 133