btb.hh revision 7720
11689SN/A/* 21689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Kevin Lim 291689SN/A */ 301689SN/A 312292SN/A#ifndef __CPU_O3_BTB_HH__ 322292SN/A#define __CPU_O3_BTB_HH__ 331061SN/A 347720Sgblack@eecs.umich.edu#include "arch/types.hh" 352669SN/A#include "base/misc.hh" 366214SN/A#include "base/types.hh" 377720Sgblack@eecs.umich.edu#include "config/the_isa.hh" 381061SN/A 391061SN/Aclass DefaultBTB 401061SN/A{ 411061SN/A private: 421061SN/A struct BTBEntry 431061SN/A { 441061SN/A BTBEntry() 451061SN/A : tag(0), target(0), valid(false) 467720Sgblack@eecs.umich.edu {} 471061SN/A 482292SN/A /** The entry's tag. */ 491061SN/A Addr tag; 502292SN/A 512292SN/A /** The entry's target. */ 527720Sgblack@eecs.umich.edu TheISA::PCState target; 532292SN/A 542292SN/A /** The entry's thread id. */ 556221SN/A ThreadID tid; 562292SN/A 572292SN/A /** Whether or not the entry is valid. */ 581061SN/A bool valid; 591061SN/A }; 601061SN/A 611061SN/A public: 622292SN/A /** Creates a BTB with the given number of entries, number of bits per 632292SN/A * tag, and instruction offset amount. 642292SN/A * @param numEntries Number of entries for the BTB. 652292SN/A * @param tagBits Number of bits for each tag in the BTB. 662292SN/A * @param instShiftAmt Offset amount for instructions to ignore alignment. 672292SN/A */ 681061SN/A DefaultBTB(unsigned numEntries, unsigned tagBits, 691061SN/A unsigned instShiftAmt); 701061SN/A 712307SN/A void reset(); 721061SN/A 732292SN/A /** Looks up an address in the BTB. Must call valid() first on the address. 742292SN/A * @param inst_PC The address of the branch to look up. 752292SN/A * @param tid The thread id. 762292SN/A * @return Returns the target of the branch. 772292SN/A */ 787720Sgblack@eecs.umich.edu TheISA::PCState lookup(Addr instPC, ThreadID tid); 791061SN/A 802292SN/A /** Checks if a branch is in the BTB. 812292SN/A * @param inst_PC The address of the branch to look up. 822292SN/A * @param tid The thread id. 832292SN/A * @return Whether or not the branch exists in the BTB. 842292SN/A */ 857720Sgblack@eecs.umich.edu bool valid(Addr instPC, ThreadID tid); 862130SN/A 872292SN/A /** Updates the BTB with the target of a branch. 882292SN/A * @param inst_PC The address of the branch being updated. 892292SN/A * @param target_PC The target address of the branch. 902292SN/A * @param tid The thread id. 912292SN/A */ 927720Sgblack@eecs.umich.edu void update(Addr instPC, const TheISA::PCState &targetPC, 936221SN/A ThreadID tid); 941061SN/A 951061SN/A private: 962292SN/A /** Returns the index into the BTB, based on the branch's PC. 972292SN/A * @param inst_PC The branch to look up. 982292SN/A * @return Returns the index into the BTB. 992292SN/A */ 1007720Sgblack@eecs.umich.edu inline unsigned getIndex(Addr instPC); 1011061SN/A 1022292SN/A /** Returns the tag bits of a given address. 1032292SN/A * @param inst_PC The branch's address. 1042292SN/A * @return Returns the tag bits. 1052292SN/A */ 1067720Sgblack@eecs.umich.edu inline Addr getTag(Addr instPC); 1071061SN/A 1082292SN/A /** The actual BTB. */ 1092292SN/A std::vector<BTBEntry> btb; 1101061SN/A 1112292SN/A /** The number of entries in the BTB. */ 1121061SN/A unsigned numEntries; 1131061SN/A 1142292SN/A /** The index mask. */ 1151061SN/A unsigned idxMask; 1161061SN/A 1172292SN/A /** The number of tag bits per entry. */ 1181061SN/A unsigned tagBits; 1191061SN/A 1202292SN/A /** The tag mask. */ 1211061SN/A unsigned tagMask; 1221061SN/A 1232292SN/A /** Number of bits to shift PC when calculating index. */ 1241061SN/A unsigned instShiftAmt; 1251061SN/A 1262292SN/A /** Number of bits to shift PC when calculating tag. */ 1271061SN/A unsigned tagShiftAmt; 1281061SN/A}; 1291061SN/A 1302292SN/A#endif // __CPU_O3_BTB_HH__ 131