2bit_local.hh revision 10785
16167SN/A/* 26167SN/A * Copyright (c) 2011, 2014 ARM Limited 36167SN/A * All rights reserved 48835SAli.Saidi@ARM.com * 57892SN/A * The license below extends only to copyright in the software and shall 67892SN/A * not be construed as granting a license to any other intellectual 77892SN/A * property including but not limited to intellectual property relating 86167SN/A * to a hardware implementation of the functionality of the software 96167SN/A * licensed hereunder. You may use the software subject to the license 106167SN/A * terms below provided that you ensure that this notice is replicated 118721SN/A * unmodified and in its entirety in all distributions of the software, 128835SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 139207Snilay@cs.wisc.edu * 148835SAli.Saidi@ARM.com * Copyright (c) 2004-2006 The Regents of The University of Michigan 158835SAli.Saidi@ARM.com * All rights reserved. 168835SAli.Saidi@ARM.com * 177077SN/A * Redistribution and use in source and binary forms, with or without 188673SN/A * modification, are permitted provided that the following conditions are 198721SN/A * met: redistributions of source code must retain the above copyright 208835SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 218835SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 227935SN/A * notice, this list of conditions and the following disclaimer in the 237935SN/A * documentation and/or other materials provided with the distribution; 247935SN/A * neither the name of the copyright holders nor the names of its 257935SN/A * contributors may be used to endorse or promote products derived from 267935SN/A * this software without specific prior written permission. 277935SN/A * 287935SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 298983Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 306167SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 316167SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 326167SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 338835SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 346167SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 356928SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 366167SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376167SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 386167SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 398835SAli.Saidi@ARM.com * 406167SN/A * Authors: Kevin Lim 416167SN/A * Timothy M. Jones 426167SN/A */ 436167SN/A 448835SAli.Saidi@ARM.com#ifndef __CPU_PRED_2BIT_LOCAL_PRED_HH__ 456167SN/A#define __CPU_PRED_2BIT_LOCAL_PRED_HH__ 466167SN/A 476167SN/A#include <vector> 486167SN/A 496167SN/A#include "base/types.hh" 506167SN/A#include "cpu/pred/bpred_unit.hh" 518835SAli.Saidi@ARM.com#include "cpu/pred/sat_counter.hh" 526167SN/A#include "params/LocalBP.hh" 536167SN/A 546167SN/A/** 556167SN/A * Implements a local predictor that uses the PC to index into a table of 568983Snate@binkert.org * counters. Note that any time a pointer to the bp_history is given, it 578983Snate@binkert.org * should be NULL using this predictor because it does not have any branch 586167SN/A * predictor state that needs to be recorded or updated; the update can be 596167SN/A * determined solely by the branch being taken or not taken. 606167SN/A */ 618835SAli.Saidi@ARM.comclass LocalBP : public BPredUnit 626167SN/A{ 638835SAli.Saidi@ARM.com public: 648835SAli.Saidi@ARM.com /** 658835SAli.Saidi@ARM.com * Default branch predictor constructor. 668835SAli.Saidi@ARM.com */ 679207Snilay@cs.wisc.edu LocalBP(const LocalBPParams *params); 688835SAli.Saidi@ARM.com 698983Snate@binkert.org virtual void uncondBranch(Addr pc, void * &bp_history); 708835SAli.Saidi@ARM.com 718835SAli.Saidi@ARM.com /** 728835SAli.Saidi@ARM.com * Looks up the given address in the branch predictor and returns 739207Snilay@cs.wisc.edu * a true/false value as to whether it is taken. 748835SAli.Saidi@ARM.com * @param branch_addr The address of the branch to look up. 758835SAli.Saidi@ARM.com * @param bp_history Pointer to any bp history state. 769213Snilay@cs.wisc.edu * @return Whether or not the branch is taken. 778835SAli.Saidi@ARM.com */ 788983Snate@binkert.org bool lookup(Addr branch_addr, void * &bp_history); 798983Snate@binkert.org 808983Snate@binkert.org /** 816167SN/A * Updates the branch predictor to Not Taken if a BTB entry is 826167SN/A * invalid or not found. 836167SN/A * @param branch_addr The address of the branch to look up. 848835SAli.Saidi@ARM.com * @param bp_history Pointer to any bp history state. 856167SN/A * @return Whether or not the branch is taken. 868835SAli.Saidi@ARM.com */ 878835SAli.Saidi@ARM.com void btbUpdate(Addr branch_addr, void * &bp_history); 888835SAli.Saidi@ARM.com 898835SAli.Saidi@ARM.com /** 909207Snilay@cs.wisc.edu * Updates the branch predictor with the actual result of a branch. 918835SAli.Saidi@ARM.com * @param branch_addr The address of the branch to update. 928983Snate@binkert.org * @param taken Whether or not the branch was taken. 936167SN/A */ 946167SN/A void update(Addr branch_addr, bool taken, void *bp_history, bool squashed); 956167SN/A 966167SN/A void retireSquashed(void *bp_history) 976167SN/A { assert(bp_history == NULL); } 986167SN/A 996167SN/A void squash(void *bp_history) 1006167SN/A { assert(bp_history == NULL); } 1016167SN/A 1026167SN/A void reset(); 1036167SN/A 1046167SN/A private: 1059207Snilay@cs.wisc.edu /** 1066167SN/A * Returns the taken/not taken prediction given the value of the 1076167SN/A * counter. 1086167SN/A * @param count The value of the counter. 1096167SN/A * @return The prediction based on the counter value. 1106167SN/A */ 1116167SN/A inline bool getPrediction(uint8_t &count); 1126167SN/A 1136167SN/A /** Calculates the local index based on the PC. */ 1146167SN/A inline unsigned getLocalIndex(Addr &PC); 1156167SN/A 1167892SN/A /** Array of counters that make up the local predictor. */ 1176928SN/A std::vector<SatCounter> localCtrs; 1186928SN/A 1196928SN/A /** Size of the local predictor. */ 1208673SN/A unsigned localPredictorSize; 1217892SN/A 1226928SN/A /** Number of sets. */ 1237892SN/A unsigned localPredictorSets; 1246928SN/A 1256928SN/A /** Number of bits of the local predictor's counters. */ 1268673SN/A unsigned localCtrBits; 1276928SN/A 1286928SN/A /** Mask to get index bits. */ 1296928SN/A unsigned indexMask; 1307892SN/A}; 1316928SN/A 1327077SN/A#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__ 1339373Snilay@cs.wisc.edu