2bit_local.hh revision 13626
110244Satgutier@umich.edu/*
210244Satgutier@umich.edu * Copyright (c) 2011, 2014 ARM Limited
310244Satgutier@umich.edu * All rights reserved
410244Satgutier@umich.edu *
510244Satgutier@umich.edu * The license below extends only to copyright in the software and shall
610244Satgutier@umich.edu * not be construed as granting a license to any other intellectual
710244Satgutier@umich.edu * property including but not limited to intellectual property relating
810244Satgutier@umich.edu * to a hardware implementation of the functionality of the software
910244Satgutier@umich.edu * licensed hereunder.  You may use the software subject to the license
1010244Satgutier@umich.edu * terms below provided that you ensure that this notice is replicated
1110244Satgutier@umich.edu * unmodified and in its entirety in all distributions of the software,
1210244Satgutier@umich.edu * modified or unmodified, in source code or in binary form.
1310244Satgutier@umich.edu *
1410244Satgutier@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
1510244Satgutier@umich.edu * All rights reserved.
1610244Satgutier@umich.edu *
1710244Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without
1810244Satgutier@umich.edu * modification, are permitted provided that the following conditions are
1910244Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
2010244Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
2110244Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
2210244Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
2310244Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
2410244Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
2510244Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
2610244Satgutier@umich.edu * this software without specific prior written permission.
2710244Satgutier@umich.edu *
2810244Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2910244Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3010244Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3110244Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3210244Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3310244Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3410244Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3510244Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3610244Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3710244Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3810244Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3910244Satgutier@umich.edu *
4010785Sgope@wisc.edu * Authors: Kevin Lim
4110244Satgutier@umich.edu *          Timothy M. Jones
4210244Satgutier@umich.edu */
4310244Satgutier@umich.edu
4410244Satgutier@umich.edu#ifndef __CPU_PRED_2BIT_LOCAL_PRED_HH__
4510244Satgutier@umich.edu#define __CPU_PRED_2BIT_LOCAL_PRED_HH__
4610244Satgutier@umich.edu
4710244Satgutier@umich.edu#include <vector>
4810244Satgutier@umich.edu
4910244Satgutier@umich.edu#include "base/types.hh"
5010244Satgutier@umich.edu#include "cpu/pred/bpred_unit.hh"
5110244Satgutier@umich.edu#include "cpu/pred/sat_counter.hh"
5210244Satgutier@umich.edu#include "params/LocalBP.hh"
5310244Satgutier@umich.edu
5410244Satgutier@umich.edu/**
5510244Satgutier@umich.edu * Implements a local predictor that uses the PC to index into a table of
5610244Satgutier@umich.edu * counters.  Note that any time a pointer to the bp_history is given, it
5710244Satgutier@umich.edu * should be NULL using this predictor because it does not have any branch
5810244Satgutier@umich.edu * predictor state that needs to be recorded or updated; the update can be
5910785Sgope@wisc.edu * determined solely by the branch being taken or not taken.
6011434Smitch.hayenga@arm.com */
6111434Smitch.hayenga@arm.comclass LocalBP : public BPredUnit
6211434Smitch.hayenga@arm.com{
6311434Smitch.hayenga@arm.com  public:
6411434Smitch.hayenga@arm.com    /**
6513626Sjairo.balart@metempsy.com     * Default branch predictor constructor.
6611434Smitch.hayenga@arm.com     */
6710244Satgutier@umich.edu    LocalBP(const LocalBPParams *params);
6810244Satgutier@umich.edu
6911434Smitch.hayenga@arm.com    virtual void uncondBranch(ThreadID tid, Addr pc, void * &bp_history);
7010244Satgutier@umich.edu
7110244Satgutier@umich.edu    /**
7210244Satgutier@umich.edu     * Looks up the given address in the branch predictor and returns
7310244Satgutier@umich.edu     * a true/false value as to whether it is taken.
7410244Satgutier@umich.edu     * @param branch_addr The address of the branch to look up.
7510244Satgutier@umich.edu     * @param bp_history Pointer to any bp history state.
7610244Satgutier@umich.edu     * @return Whether or not the branch is taken.
7710244Satgutier@umich.edu     */
7810244Satgutier@umich.edu    bool lookup(ThreadID tid, Addr branch_addr, void * &bp_history);
7910244Satgutier@umich.edu
8010244Satgutier@umich.edu    /**
8110244Satgutier@umich.edu     * Updates the branch predictor to Not Taken if a BTB entry is
8210244Satgutier@umich.edu     * invalid or not found.
8310244Satgutier@umich.edu     * @param branch_addr The address of the branch to look up.
8410244Satgutier@umich.edu     * @param bp_history Pointer to any bp history state.
8510244Satgutier@umich.edu     * @return Whether or not the branch is taken.
8610244Satgutier@umich.edu     */
8710244Satgutier@umich.edu    void btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history);
8810244Satgutier@umich.edu
8910244Satgutier@umich.edu    /**
9010244Satgutier@umich.edu     * Updates the branch predictor with the actual result of a branch.
9110244Satgutier@umich.edu     * @param branch_addr The address of the branch to update.
9210244Satgutier@umich.edu     * @param taken Whether or not the branch was taken.
9310244Satgutier@umich.edu     */
9410244Satgutier@umich.edu    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
9510244Satgutier@umich.edu                bool squashed, const StaticInstPtr & inst, Addr corrTarget);
9610244Satgutier@umich.edu
9710244Satgutier@umich.edu    void squash(ThreadID tid, void *bp_history)
9811434Smitch.hayenga@arm.com    { assert(bp_history == NULL); }
9910244Satgutier@umich.edu
10010244Satgutier@umich.edu    void reset();
10110244Satgutier@umich.edu
10210244Satgutier@umich.edu  private:
10310244Satgutier@umich.edu    /**
10410244Satgutier@umich.edu     *  Returns the taken/not taken prediction given the value of the
10510244Satgutier@umich.edu     *  counter.
10610244Satgutier@umich.edu     *  @param count The value of the counter.
10710244Satgutier@umich.edu     *  @return The prediction based on the counter value.
10810244Satgutier@umich.edu     */
10910244Satgutier@umich.edu    inline bool getPrediction(uint8_t &count);
11010244Satgutier@umich.edu
11110244Satgutier@umich.edu    /** Calculates the local index based on the PC. */
11210244Satgutier@umich.edu    inline unsigned getLocalIndex(Addr &PC);
11310244Satgutier@umich.edu
11410244Satgutier@umich.edu    /** Array of counters that make up the local predictor. */
115    std::vector<SatCounter> localCtrs;
116
117    /** Size of the local predictor. */
118    unsigned localPredictorSize;
119
120    /** Number of sets. */
121    unsigned localPredictorSets;
122
123    /** Number of bits of the local predictor's counters. */
124    unsigned localCtrBits;
125
126    /** Mask to get index bits. */
127    unsigned indexMask;
128};
129
130#endif // __CPU_PRED_2BIT_LOCAL_PRED_HH__
131