btb.hh revision 6214
12SN/A/* 214047Snikos.nikoleris@arm.com * Copyright (c) 2004-2005 The Regents of The University of Michigan 39235Sandreas.hansson@arm.com * All rights reserved. 49235Sandreas.hansson@arm.com * 59235Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 69235Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 79235Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 89235Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 99235Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 109235Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 119235Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 129235Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 139235Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 141762SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A * 282SN/A * Authors: Kevin Lim 292SN/A */ 302SN/A 312SN/A#ifndef __CPU_O3_BTB_HH__ 322SN/A#define __CPU_O3_BTB_HH__ 332SN/A 342SN/A#include "base/misc.hh" 352SN/A#include "base/types.hh" 362SN/A 372SN/Aclass DefaultBTB 382SN/A{ 392665SN/A private: 402665SN/A struct BTBEntry 412665SN/A { 429235Sandreas.hansson@arm.com BTBEntry() 432SN/A : tag(0), target(0), valid(false) 442SN/A { 459235Sandreas.hansson@arm.com } 469235Sandreas.hansson@arm.com 472SN/A /** The entry's tag. */ 4812977Snikos.nikoleris@arm.com Addr tag; 4910481Sandreas.hansson@arm.com 509412Sandreas.hansson@arm.com /** The entry's target. */ 519412Sandreas.hansson@arm.com Addr target; 529411Sandreas.hansson@arm.com 539405Sandreas.hansson@arm.com /** The entry's thread id. */ 5412334Sgabeblack@google.com unsigned tid; 559235Sandreas.hansson@arm.com 569235Sandreas.hansson@arm.com /** Whether or not the entry is valid. */ 5710676Sandreas.hansson@arm.com bool valid; 5810676Sandreas.hansson@arm.com }; 5910676Sandreas.hansson@arm.com 6010676Sandreas.hansson@arm.com public: 6110676Sandreas.hansson@arm.com /** Creates a BTB with the given number of entries, number of bits per 6210676Sandreas.hansson@arm.com * tag, and instruction offset amount. 6310676Sandreas.hansson@arm.com * @param numEntries Number of entries for the BTB. 6410676Sandreas.hansson@arm.com * @param tagBits Number of bits for each tag in the BTB. 6510676Sandreas.hansson@arm.com * @param instShiftAmt Offset amount for instructions to ignore alignment. 6614047Snikos.nikoleris@arm.com */ 6714047Snikos.nikoleris@arm.com DefaultBTB(unsigned numEntries, unsigned tagBits, 6810676Sandreas.hansson@arm.com unsigned instShiftAmt); 6910676Sandreas.hansson@arm.com 7010676Sandreas.hansson@arm.com void reset(); 7110676Sandreas.hansson@arm.com 729235Sandreas.hansson@arm.com /** Looks up an address in the BTB. Must call valid() first on the address. 732SN/A * @param inst_PC The address of the branch to look up. 742SN/A * @param tid The thread id. 759405Sandreas.hansson@arm.com * @return Returns the target of the branch. 769405Sandreas.hansson@arm.com */ 779411Sandreas.hansson@arm.com Addr lookup(const Addr &inst_PC, unsigned tid); 7810435Snilay@cs.wisc.edu 799405Sandreas.hansson@arm.com /** Checks if a branch is in the BTB. 809405Sandreas.hansson@arm.com * @param inst_PC The address of the branch to look up. 819405Sandreas.hansson@arm.com * @param tid The thread id. 8214047Snikos.nikoleris@arm.com * @return Whether or not the branch exists in the BTB. 8314047Snikos.nikoleris@arm.com */ 8414047Snikos.nikoleris@arm.com bool valid(const Addr &inst_PC, unsigned tid); 8514047Snikos.nikoleris@arm.com 8614047Snikos.nikoleris@arm.com /** Updates the BTB with the target of a branch. 8714047Snikos.nikoleris@arm.com * @param inst_PC The address of the branch being updated. 889411Sandreas.hansson@arm.com * @param target_PC The target address of the branch. 8914047Snikos.nikoleris@arm.com * @param tid The thread id. 909411Sandreas.hansson@arm.com */ 919411Sandreas.hansson@arm.com void update(const Addr &inst_PC, const Addr &target_PC, 929235Sandreas.hansson@arm.com unsigned tid); 932SN/A 949235Sandreas.hansson@arm.com private: 9514047Snikos.nikoleris@arm.com /** Returns the index into the BTB, based on the branch's PC. 969411Sandreas.hansson@arm.com * @param inst_PC The branch to look up. 979411Sandreas.hansson@arm.com * @return Returns the index into the BTB. 9814047Snikos.nikoleris@arm.com */ 9914047Snikos.nikoleris@arm.com inline unsigned getIndex(const Addr &inst_PC); 10014047Snikos.nikoleris@arm.com 10114047Snikos.nikoleris@arm.com /** Returns the tag bits of a given address. 10214047Snikos.nikoleris@arm.com * @param inst_PC The branch's address. 10314047Snikos.nikoleris@arm.com * @return Returns the tag bits. 10414047Snikos.nikoleris@arm.com */ 10514047Snikos.nikoleris@arm.com inline Addr getTag(const Addr &inst_PC); 10614047Snikos.nikoleris@arm.com 10714047Snikos.nikoleris@arm.com /** The actual BTB. */ 10814047Snikos.nikoleris@arm.com std::vector<BTBEntry> btb; 10914047Snikos.nikoleris@arm.com 11014047Snikos.nikoleris@arm.com /** The number of entries in the BTB. */ 11114047Snikos.nikoleris@arm.com unsigned numEntries; 11214047Snikos.nikoleris@arm.com 11314047Snikos.nikoleris@arm.com /** The index mask. */ 11414047Snikos.nikoleris@arm.com unsigned idxMask; 11514047Snikos.nikoleris@arm.com 11614047Snikos.nikoleris@arm.com /** The number of tag bits per entry. */ 11714047Snikos.nikoleris@arm.com unsigned tagBits; 11814047Snikos.nikoleris@arm.com 11914047Snikos.nikoleris@arm.com /** The tag mask. */ 12014047Snikos.nikoleris@arm.com unsigned tagMask; 12114047Snikos.nikoleris@arm.com 12214047Snikos.nikoleris@arm.com /** Number of bits to shift PC when calculating index. */ 12314047Snikos.nikoleris@arm.com unsigned instShiftAmt; 12414047Snikos.nikoleris@arm.com 12514047Snikos.nikoleris@arm.com /** Number of bits to shift PC when calculating tag. */ 12614047Snikos.nikoleris@arm.com unsigned tagShiftAmt; 12714047Snikos.nikoleris@arm.com}; 12814047Snikos.nikoleris@arm.com 12914047Snikos.nikoleris@arm.com#endif // __CPU_O3_BTB_HH__ 13014047Snikos.nikoleris@arm.com