2bit_local.hh revision 9480
11689SN/A/* 28842Smrinmoy.ghosh@arm.com * Copyright (c) 2011 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" 522292SN/A 532345SN/A/** 542345SN/A * Implements a local predictor that uses the PC to index into a table of 552345SN/A * counters. Note that any time a pointer to the bp_history is given, it 562345SN/A * should be NULL using this predictor because it does not have any branch 572345SN/A * predictor state that needs to be recorded or updated; the update can be 582345SN/A * determined solely by the branch being taken or not taken. 592345SN/A */ 609480Snilay@cs.wisc.educlass LocalBP : public BPredUnit 611061SN/A{ 621061SN/A public: 631061SN/A /** 641061SN/A * Default branch predictor constructor. 651061SN/A */ 669480Snilay@cs.wisc.edu LocalBP(const Params *params); 679480Snilay@cs.wisc.edu 689480Snilay@cs.wisc.edu virtual void uncondBranch(void * &bp_history); 691061SN/A 701061SN/A /** 711061SN/A * Looks up the given address in the branch predictor and returns 721061SN/A * a true/false value as to whether it is taken. 731061SN/A * @param branch_addr The address of the branch to look up. 742345SN/A * @param bp_history Pointer to any bp history state. 751061SN/A * @return Whether or not the branch is taken. 761061SN/A */ 779480Snilay@cs.wisc.edu bool lookup(Addr branch_addr, void * &bp_history); 781061SN/A 791061SN/A /** 808842Smrinmoy.ghosh@arm.com * Updates the branch predictor to Not Taken if a BTB entry is 818842Smrinmoy.ghosh@arm.com * invalid or not found. 828842Smrinmoy.ghosh@arm.com * @param branch_addr The address of the branch to look up. 838842Smrinmoy.ghosh@arm.com * @param bp_history Pointer to any bp history state. 848842Smrinmoy.ghosh@arm.com * @return Whether or not the branch is taken. 858842Smrinmoy.ghosh@arm.com */ 869480Snilay@cs.wisc.edu void btbUpdate(Addr branch_addr, void * &bp_history); 878842Smrinmoy.ghosh@arm.com 888842Smrinmoy.ghosh@arm.com /** 891061SN/A * Updates the branch predictor with the actual result of a branch. 901061SN/A * @param branch_addr The address of the branch to update. 911061SN/A * @param taken Whether or not the branch was taken. 921061SN/A */ 939480Snilay@cs.wisc.edu void update(Addr branch_addr, bool taken, void *bp_history, bool squashed); 942345SN/A 952345SN/A void squash(void *bp_history) 962345SN/A { assert(bp_history == NULL); } 971061SN/A 982307SN/A void reset(); 992307SN/A 1001061SN/A private: 1012292SN/A /** 1022292SN/A * Returns the taken/not taken prediction given the value of the 1031684SN/A * counter. 1042292SN/A * @param count The value of the counter. 1052292SN/A * @return The prediction based on the counter value. 1061684SN/A */ 1071061SN/A inline bool getPrediction(uint8_t &count); 1081061SN/A 1091684SN/A /** Calculates the local index based on the PC. */ 1101061SN/A inline unsigned getLocalIndex(Addr &PC); 1111061SN/A 1121061SN/A /** Array of counters that make up the local predictor. */ 1132292SN/A std::vector<SatCounter> localCtrs; 1141061SN/A 1151061SN/A /** Size of the local predictor. */ 1161061SN/A unsigned localPredictorSize; 1171061SN/A 1182292SN/A /** Number of sets. */ 1192292SN/A unsigned localPredictorSets; 1202292SN/A 1211061SN/A /** Number of bits of the local predictor's counters. */ 1221061SN/A unsigned localCtrBits; 1231061SN/A 1241061SN/A /** Number of bits to shift the PC when calculating index. */ 1251061SN/A unsigned instShiftAmt; 1261061SN/A 1271061SN/A /** Mask to get index bits. */ 1281061SN/A unsigned indexMask; 1291061SN/A}; 1301061SN/A 1319480Snilay@cs.wisc.edu#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__ 132