113685Sjavier.bueno@metempsy.com/*
213685Sjavier.bueno@metempsy.com * Copyright (c) 2018 Metempsy Technology Consulting
313685Sjavier.bueno@metempsy.com * All rights reserved.
413685Sjavier.bueno@metempsy.com *
513685Sjavier.bueno@metempsy.com * Copyright (c) 2006 INRIA (Institut National de Recherche en
613685Sjavier.bueno@metempsy.com * Informatique et en Automatique  / French National Research Institute
713685Sjavier.bueno@metempsy.com * for Computer Science and Applied Mathematics)
813685Sjavier.bueno@metempsy.com *
913685Sjavier.bueno@metempsy.com * All rights reserved.
1013685Sjavier.bueno@metempsy.com *
1113685Sjavier.bueno@metempsy.com * Redistribution and use in source and binary forms, with or without
1213685Sjavier.bueno@metempsy.com * modification, are permitted provided that the following conditions are
1313685Sjavier.bueno@metempsy.com * met: redistributions of source code must retain the above copyright
1413685Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer;
1513685Sjavier.bueno@metempsy.com * redistributions in binary form must reproduce the above copyright
1613685Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer in the
1713685Sjavier.bueno@metempsy.com * documentation and/or other materials provided with the distribution;
1813685Sjavier.bueno@metempsy.com * neither the name of the copyright holders nor the names of its
1913685Sjavier.bueno@metempsy.com * contributors may be used to endorse or promote products derived from
2013685Sjavier.bueno@metempsy.com * this software without specific prior written permission.
2113685Sjavier.bueno@metempsy.com *
2213685Sjavier.bueno@metempsy.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2313685Sjavier.bueno@metempsy.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2413685Sjavier.bueno@metempsy.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2513685Sjavier.bueno@metempsy.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2613685Sjavier.bueno@metempsy.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2713685Sjavier.bueno@metempsy.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2813685Sjavier.bueno@metempsy.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2913685Sjavier.bueno@metempsy.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3013685Sjavier.bueno@metempsy.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3113685Sjavier.bueno@metempsy.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3213685Sjavier.bueno@metempsy.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3313685Sjavier.bueno@metempsy.com *
3413685Sjavier.bueno@metempsy.com * Author: André Seznec, Pau Cabre, Javier Bueno
3513685Sjavier.bueno@metempsy.com *
3613685Sjavier.bueno@metempsy.com */
3713685Sjavier.bueno@metempsy.com
3813685Sjavier.bueno@metempsy.com/*
3913685Sjavier.bueno@metempsy.com * TAGE-SC-L branch predictor base class (devised by Andre Seznec)
4013685Sjavier.bueno@metempsy.com * It consits of a TAGE + a statistical corrector (SC) + a loop predictor (L)
4113685Sjavier.bueno@metempsy.com */
4213685Sjavier.bueno@metempsy.com
4313685Sjavier.bueno@metempsy.com#ifndef __CPU_PRED_TAGE_SC_L
4413685Sjavier.bueno@metempsy.com#define __CPU_PRED_TAGE_SC_L
4513685Sjavier.bueno@metempsy.com
4613685Sjavier.bueno@metempsy.com#include "cpu/pred/ltage.hh"
4713685Sjavier.bueno@metempsy.com#include "cpu/pred/statistical_corrector.hh"
4813685Sjavier.bueno@metempsy.com#include "params/TAGE_SC_L.hh"
4913685Sjavier.bueno@metempsy.com#include "params/TAGE_SC_L_LoopPredictor.hh"
5013685Sjavier.bueno@metempsy.com#include "params/TAGE_SC_L_TAGE.hh"
5113685Sjavier.bueno@metempsy.com
5213685Sjavier.bueno@metempsy.comclass TAGE_SC_L_TAGE : public TAGEBase {
5313685Sjavier.bueno@metempsy.com    const unsigned firstLongTagTable;
5413685Sjavier.bueno@metempsy.com    const unsigned longTagsSize;
5513685Sjavier.bueno@metempsy.com    const unsigned shortTagsSize;
5613685Sjavier.bueno@metempsy.com
5713685Sjavier.bueno@metempsy.com    const unsigned logTagTableSize;
5813685Sjavier.bueno@metempsy.com
5913685Sjavier.bueno@metempsy.com    const unsigned shortTagsTageFactor;
6013685Sjavier.bueno@metempsy.com    const unsigned longTagsTageFactor;
6113685Sjavier.bueno@metempsy.com
6213685Sjavier.bueno@metempsy.com    const bool truncatePathHist;
6313685Sjavier.bueno@metempsy.com
6413685Sjavier.bueno@metempsy.com  public:
6513685Sjavier.bueno@metempsy.com    struct BranchInfo : public TAGEBase::BranchInfo {
6613685Sjavier.bueno@metempsy.com        bool lowConf;
6713685Sjavier.bueno@metempsy.com        bool highConf;
6813685Sjavier.bueno@metempsy.com        bool altConf;
6913685Sjavier.bueno@metempsy.com        bool medConf;
7013685Sjavier.bueno@metempsy.com        BranchInfo(TAGEBase &tage) : TAGEBase::BranchInfo(tage),
7113685Sjavier.bueno@metempsy.com            lowConf(false), highConf(false), altConf(false), medConf(false)
7213685Sjavier.bueno@metempsy.com        {}
7313685Sjavier.bueno@metempsy.com        virtual ~BranchInfo()
7413685Sjavier.bueno@metempsy.com        {}
7513685Sjavier.bueno@metempsy.com    };
7613685Sjavier.bueno@metempsy.com
7713685Sjavier.bueno@metempsy.com    virtual TAGEBase::BranchInfo *makeBranchInfo() override;
7813685Sjavier.bueno@metempsy.com
7913685Sjavier.bueno@metempsy.com    TAGE_SC_L_TAGE(const TAGE_SC_L_TAGEParams *p)
8013685Sjavier.bueno@metempsy.com      : TAGEBase(p),
8113685Sjavier.bueno@metempsy.com        firstLongTagTable(p->firstLongTagTable),
8213685Sjavier.bueno@metempsy.com        longTagsSize(p->longTagsSize),
8313685Sjavier.bueno@metempsy.com        shortTagsSize(p->shortTagsSize),
8413685Sjavier.bueno@metempsy.com        logTagTableSize(p->logTagTableSize),
8513685Sjavier.bueno@metempsy.com        shortTagsTageFactor(p->shortTagsTageFactor),
8613685Sjavier.bueno@metempsy.com        longTagsTageFactor(p->longTagsTageFactor),
8713685Sjavier.bueno@metempsy.com        truncatePathHist(p->truncatePathHist)
8813685Sjavier.bueno@metempsy.com    {}
8913685Sjavier.bueno@metempsy.com
9013685Sjavier.bueno@metempsy.com    void calculateParameters() override;
9113685Sjavier.bueno@metempsy.com
9213685Sjavier.bueno@metempsy.com    void buildTageTables() override;
9313685Sjavier.bueno@metempsy.com
9413685Sjavier.bueno@metempsy.com    void calculateIndicesAndTags(
9513685Sjavier.bueno@metempsy.com        ThreadID tid, Addr branch_pc, TAGEBase::BranchInfo* bi) override;
9613685Sjavier.bueno@metempsy.com
9714081Sjavier.bueno@metempsy.com    unsigned getUseAltIdx(TAGEBase::BranchInfo* bi, Addr branch_pc) override;
9813685Sjavier.bueno@metempsy.com
9913685Sjavier.bueno@metempsy.com    void updateHistories(
10013685Sjavier.bueno@metempsy.com        ThreadID tid, Addr branch_pc, bool taken, TAGEBase::BranchInfo* b,
10113685Sjavier.bueno@metempsy.com        bool speculative, const StaticInstPtr &inst,
10213685Sjavier.bueno@metempsy.com        Addr target) override;
10313685Sjavier.bueno@metempsy.com
10413685Sjavier.bueno@metempsy.com    int bindex(Addr pc_in) const override;
10513685Sjavier.bueno@metempsy.com    int gindex(ThreadID tid, Addr pc, int bank) const override;
10613685Sjavier.bueno@metempsy.com    virtual int gindex_ext(int index, int bank) const = 0;
10713685Sjavier.bueno@metempsy.com    int F(int phist, int size, int bank) const override;
10813685Sjavier.bueno@metempsy.com
10913685Sjavier.bueno@metempsy.com    virtual uint16_t gtag(ThreadID tid, Addr pc, int bank) const override = 0;
11013685Sjavier.bueno@metempsy.com
11113685Sjavier.bueno@metempsy.com    void squash(ThreadID tid, bool taken, TAGEBase::BranchInfo *bi,
11213685Sjavier.bueno@metempsy.com                Addr target) override;
11313685Sjavier.bueno@metempsy.com
11413685Sjavier.bueno@metempsy.com    void updatePathAndGlobalHistory(
11513685Sjavier.bueno@metempsy.com        ThreadHistory & tHist, int brtype, bool taken,
11613685Sjavier.bueno@metempsy.com        Addr branch_pc, Addr target);
11713685Sjavier.bueno@metempsy.com
11813685Sjavier.bueno@metempsy.com    void adjustAlloc(bool & alloc, bool taken, bool pred_taken) override;
11913685Sjavier.bueno@metempsy.com
12013685Sjavier.bueno@metempsy.com    virtual void handleAllocAndUReset(bool alloc, bool taken,
12113685Sjavier.bueno@metempsy.com        TAGEBase::BranchInfo* bi, int nrand) override = 0;
12213685Sjavier.bueno@metempsy.com
12313685Sjavier.bueno@metempsy.com    void handleUReset() override;
12413685Sjavier.bueno@metempsy.com
12513685Sjavier.bueno@metempsy.com    virtual void handleTAGEUpdate(
12613685Sjavier.bueno@metempsy.com        Addr branch_pc, bool taken, TAGEBase::BranchInfo* bi) override = 0;
12713685Sjavier.bueno@metempsy.com
12813685Sjavier.bueno@metempsy.com    int calcDep(TAGEBase::BranchInfo* bi);
12913685Sjavier.bueno@metempsy.com
13013685Sjavier.bueno@metempsy.com    bool getBimodePred(Addr branch_pc,
13113685Sjavier.bueno@metempsy.com                       TAGEBase::BranchInfo* tage_bi) const override;
13213685Sjavier.bueno@metempsy.com
13313685Sjavier.bueno@metempsy.com    void extraAltCalc(TAGEBase::BranchInfo* bi) override;
13413685Sjavier.bueno@metempsy.com
13513685Sjavier.bueno@metempsy.com};
13613685Sjavier.bueno@metempsy.com
13713685Sjavier.bueno@metempsy.comclass TAGE_SC_L_LoopPredictor : public LoopPredictor
13813685Sjavier.bueno@metempsy.com{
13913685Sjavier.bueno@metempsy.com  public:
14013685Sjavier.bueno@metempsy.com    TAGE_SC_L_LoopPredictor(TAGE_SC_L_LoopPredictorParams *p)
14113685Sjavier.bueno@metempsy.com      : LoopPredictor(p)
14213685Sjavier.bueno@metempsy.com    {}
14313685Sjavier.bueno@metempsy.com
14413685Sjavier.bueno@metempsy.com    virtual bool calcConf(int index) const override;
14513685Sjavier.bueno@metempsy.com    virtual bool optionalAgeInc() const override;
14613685Sjavier.bueno@metempsy.com};
14713685Sjavier.bueno@metempsy.com
14813685Sjavier.bueno@metempsy.comclass TAGE_SC_L: public LTAGE
14913685Sjavier.bueno@metempsy.com{
15013685Sjavier.bueno@metempsy.com    StatisticalCorrector *statisticalCorrector;
15113685Sjavier.bueno@metempsy.com  public:
15213685Sjavier.bueno@metempsy.com    TAGE_SC_L(const TAGE_SC_LParams *params);
15313685Sjavier.bueno@metempsy.com
15413685Sjavier.bueno@metempsy.com    bool predict(
15513685Sjavier.bueno@metempsy.com        ThreadID tid, Addr branch_pc, bool cond_branch, void* &b) override;
15613685Sjavier.bueno@metempsy.com
15713685Sjavier.bueno@metempsy.com    void regStats() override;
15813685Sjavier.bueno@metempsy.com
15913685Sjavier.bueno@metempsy.com    void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
16013685Sjavier.bueno@metempsy.com                bool squashed, const StaticInstPtr & inst,
16113685Sjavier.bueno@metempsy.com                Addr corrTarget = MaxAddr) override;
16213685Sjavier.bueno@metempsy.com
16313685Sjavier.bueno@metempsy.com  protected:
16413685Sjavier.bueno@metempsy.com
16513685Sjavier.bueno@metempsy.com    struct TageSCLBranchInfo : public LTageBranchInfo
16613685Sjavier.bueno@metempsy.com    {
16713685Sjavier.bueno@metempsy.com        StatisticalCorrector::BranchInfo *scBranchInfo;
16813685Sjavier.bueno@metempsy.com
16913685Sjavier.bueno@metempsy.com        TageSCLBranchInfo(TAGEBase &tage, StatisticalCorrector &sc,
17013685Sjavier.bueno@metempsy.com                          LoopPredictor &lp)
17113685Sjavier.bueno@metempsy.com          : LTageBranchInfo(tage, lp), scBranchInfo(sc.makeBranchInfo())
17213685Sjavier.bueno@metempsy.com        {}
17313685Sjavier.bueno@metempsy.com
17413685Sjavier.bueno@metempsy.com        virtual ~TageSCLBranchInfo()
17513685Sjavier.bueno@metempsy.com        {
17613685Sjavier.bueno@metempsy.com            delete scBranchInfo;
17713685Sjavier.bueno@metempsy.com        }
17813685Sjavier.bueno@metempsy.com    };
17913685Sjavier.bueno@metempsy.com
18013685Sjavier.bueno@metempsy.com    // more provider types
18113685Sjavier.bueno@metempsy.com    enum {
18213685Sjavier.bueno@metempsy.com        SC = LAST_LTAGE_PROVIDER_TYPE + 1
18313685Sjavier.bueno@metempsy.com    };
18413685Sjavier.bueno@metempsy.com
18513685Sjavier.bueno@metempsy.com};
18613685Sjavier.bueno@metempsy.com
18713685Sjavier.bueno@metempsy.com#endif // __CPU_PRED_TAGE_SC_L
18813685Sjavier.bueno@metempsy.com
189