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 4913960Sodanrc@yahoo.com.br#include "base/sat_counter.hh" 506216SN/A#include "base/types.hh" 519480Snilay@cs.wisc.edu#include "cpu/pred/bpred_unit.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 6911434Smitch.hayenga@arm.com virtual void uncondBranch(ThreadID tid, 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 */ 7811434Smitch.hayenga@arm.com bool lookup(ThreadID tid, 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 */ 8711434Smitch.hayenga@arm.com void btbUpdate(ThreadID tid, 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 */ 9411434Smitch.hayenga@arm.com void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, 9513626Sjairo.balart@metempsy.com bool squashed, const StaticInstPtr & inst, Addr corrTarget); 962345SN/A 9711434Smitch.hayenga@arm.com void squash(ThreadID tid, void *bp_history) 982345SN/A { assert(bp_history == NULL); } 991061SN/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 11213959Sodanrc@yahoo.com.br /** Size of the local predictor. */ 11313959Sodanrc@yahoo.com.br const unsigned localPredictorSize; 11413959Sodanrc@yahoo.com.br 11513959Sodanrc@yahoo.com.br /** Number of bits of the local predictor's counters. */ 11613959Sodanrc@yahoo.com.br const unsigned localCtrBits; 11713959Sodanrc@yahoo.com.br 11813959Sodanrc@yahoo.com.br /** Number of sets. */ 11913959Sodanrc@yahoo.com.br const unsigned localPredictorSets; 12013959Sodanrc@yahoo.com.br 1211061SN/A /** Array of counters that make up the local predictor. */ 1222292SN/A std::vector<SatCounter> localCtrs; 1231061SN/A 1241061SN/A /** Mask to get index bits. */ 12513959Sodanrc@yahoo.com.br const unsigned indexMask; 1261061SN/A}; 1271061SN/A 1289480Snilay@cs.wisc.edu#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__ 129