btb.hh revision 9480
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright (c) 2004-2005 The Regents of The University of Michigan
312027Sjungma@eit.uni-kl.de * All rights reserved.
412027Sjungma@eit.uni-kl.de *
512027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
612027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
712027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
812027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
912027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
1012027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
1112027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
1212027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
1312027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
1412027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
1512027Sjungma@eit.uni-kl.de *
1612027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712027Sjungma@eit.uni-kl.de *
2812027Sjungma@eit.uni-kl.de * Authors: Kevin Lim
2912027Sjungma@eit.uni-kl.de */
3012027Sjungma@eit.uni-kl.de
3112027Sjungma@eit.uni-kl.de#ifndef __CPU_PRED_BTB_HH__
3212027Sjungma@eit.uni-kl.de#define __CPU_PRED_BTB_HH__
3312027Sjungma@eit.uni-kl.de
3412027Sjungma@eit.uni-kl.de#include "arch/types.hh"
3512027Sjungma@eit.uni-kl.de#include "base/misc.hh"
3612027Sjungma@eit.uni-kl.de#include "base/types.hh"
3712027Sjungma@eit.uni-kl.de#include "config/the_isa.hh"
3812027Sjungma@eit.uni-kl.de
3912027Sjungma@eit.uni-kl.declass DefaultBTB
4012027Sjungma@eit.uni-kl.de{
4112027Sjungma@eit.uni-kl.de  private:
4212027Sjungma@eit.uni-kl.de    struct BTBEntry
4312027Sjungma@eit.uni-kl.de    {
4412027Sjungma@eit.uni-kl.de        BTBEntry()
4512027Sjungma@eit.uni-kl.de            : tag(0), target(0), valid(false)
4612027Sjungma@eit.uni-kl.de        {}
4712027Sjungma@eit.uni-kl.de
4812027Sjungma@eit.uni-kl.de        /** The entry's tag. */
4912027Sjungma@eit.uni-kl.de        Addr tag;
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.de        /** The entry's target. */
5212027Sjungma@eit.uni-kl.de        TheISA::PCState target;
5312027Sjungma@eit.uni-kl.de
5412027Sjungma@eit.uni-kl.de        /** The entry's thread id. */
5512027Sjungma@eit.uni-kl.de        ThreadID tid;
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.de        /** Whether or not the entry is valid. */
5812027Sjungma@eit.uni-kl.de        bool valid;
5912027Sjungma@eit.uni-kl.de    };
6012027Sjungma@eit.uni-kl.de
6112027Sjungma@eit.uni-kl.de  public:
6212027Sjungma@eit.uni-kl.de    /** Creates a BTB with the given number of entries, number of bits per
6312027Sjungma@eit.uni-kl.de     *  tag, and instruction offset amount.
6412027Sjungma@eit.uni-kl.de     *  @param numEntries Number of entries for the BTB.
6512027Sjungma@eit.uni-kl.de     *  @param tagBits Number of bits for each tag in the BTB.
6612027Sjungma@eit.uni-kl.de     *  @param instShiftAmt Offset amount for instructions to ignore alignment.
6712027Sjungma@eit.uni-kl.de     */
6812027Sjungma@eit.uni-kl.de    DefaultBTB(unsigned numEntries, unsigned tagBits,
6912027Sjungma@eit.uni-kl.de               unsigned instShiftAmt);
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.de    void reset();
7212027Sjungma@eit.uni-kl.de
7312027Sjungma@eit.uni-kl.de    /** Looks up an address in the BTB. Must call valid() first on the address.
7412027Sjungma@eit.uni-kl.de     *  @param inst_PC The address of the branch to look up.
7512027Sjungma@eit.uni-kl.de     *  @param tid The thread id.
7612027Sjungma@eit.uni-kl.de     *  @return Returns the target of the branch.
7712027Sjungma@eit.uni-kl.de     */
7812027Sjungma@eit.uni-kl.de    TheISA::PCState lookup(Addr instPC, ThreadID tid);
7912027Sjungma@eit.uni-kl.de
8012027Sjungma@eit.uni-kl.de    /** Checks if a branch is in the BTB.
8112027Sjungma@eit.uni-kl.de     *  @param inst_PC The address of the branch to look up.
8212027Sjungma@eit.uni-kl.de     *  @param tid The thread id.
8312027Sjungma@eit.uni-kl.de     *  @return Whether or not the branch exists in the BTB.
8412027Sjungma@eit.uni-kl.de     */
8512027Sjungma@eit.uni-kl.de    bool valid(Addr instPC, ThreadID tid);
8612027Sjungma@eit.uni-kl.de
8712027Sjungma@eit.uni-kl.de    /** Updates the BTB with the target of a branch.
8812027Sjungma@eit.uni-kl.de     *  @param inst_PC The address of the branch being updated.
8912027Sjungma@eit.uni-kl.de     *  @param target_PC The target address of the branch.
9012027Sjungma@eit.uni-kl.de     *  @param tid The thread id.
9112027Sjungma@eit.uni-kl.de     */
9212027Sjungma@eit.uni-kl.de    void update(Addr instPC, const TheISA::PCState &targetPC,
9312027Sjungma@eit.uni-kl.de                ThreadID tid);
9412027Sjungma@eit.uni-kl.de
9512027Sjungma@eit.uni-kl.de  private:
9612027Sjungma@eit.uni-kl.de    /** Returns the index into the BTB, based on the branch's PC.
9712027Sjungma@eit.uni-kl.de     *  @param inst_PC The branch to look up.
9812027Sjungma@eit.uni-kl.de     *  @return Returns the index into the BTB.
9912027Sjungma@eit.uni-kl.de     */
10012027Sjungma@eit.uni-kl.de    inline unsigned getIndex(Addr instPC);
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de    /** Returns the tag bits of a given address.
10312027Sjungma@eit.uni-kl.de     *  @param inst_PC The branch's address.
10412027Sjungma@eit.uni-kl.de     *  @return Returns the tag bits.
10512027Sjungma@eit.uni-kl.de     */
10612027Sjungma@eit.uni-kl.de    inline Addr getTag(Addr instPC);
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de    /** The actual BTB. */
10912027Sjungma@eit.uni-kl.de    std::vector<BTBEntry> btb;
11012027Sjungma@eit.uni-kl.de
11112027Sjungma@eit.uni-kl.de    /** The number of entries in the BTB. */
11212027Sjungma@eit.uni-kl.de    unsigned numEntries;
11312027Sjungma@eit.uni-kl.de
11412027Sjungma@eit.uni-kl.de    /** The index mask. */
11512027Sjungma@eit.uni-kl.de    unsigned idxMask;
11612027Sjungma@eit.uni-kl.de
11712027Sjungma@eit.uni-kl.de    /** The number of tag bits per entry. */
11812027Sjungma@eit.uni-kl.de    unsigned tagBits;
11912027Sjungma@eit.uni-kl.de
12012027Sjungma@eit.uni-kl.de    /** The tag mask. */
12112027Sjungma@eit.uni-kl.de    unsigned tagMask;
12212027Sjungma@eit.uni-kl.de
12312027Sjungma@eit.uni-kl.de    /** Number of bits to shift PC when calculating index. */
12412027Sjungma@eit.uni-kl.de    unsigned instShiftAmt;
12512027Sjungma@eit.uni-kl.de
12612027Sjungma@eit.uni-kl.de    /** Number of bits to shift PC when calculating tag. */
12712027Sjungma@eit.uni-kl.de    unsigned tagShiftAmt;
12812027Sjungma@eit.uni-kl.de};
12912027Sjungma@eit.uni-kl.de
13012027Sjungma@eit.uni-kl.de#endif // __CPU_PRED_BTB_HH__
13112027Sjungma@eit.uni-kl.de