store_set.hh revision 2348
12292SN/A/*
22329SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
32292SN/A * All rights reserved.
42292SN/A *
52292SN/A * Redistribution and use in source and binary forms, with or without
62292SN/A * modification, are permitted provided that the following conditions are
72292SN/A * met: redistributions of source code must retain the above copyright
82292SN/A * notice, this list of conditions and the following disclaimer;
92292SN/A * redistributions in binary form must reproduce the above copyright
102292SN/A * notice, this list of conditions and the following disclaimer in the
112292SN/A * documentation and/or other materials provided with the distribution;
122292SN/A * neither the name of the copyright holders nor the names of its
132292SN/A * contributors may be used to endorse or promote products derived from
142292SN/A * this software without specific prior written permission.
152292SN/A *
162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu */
282689Sktlim@umich.edu
292689Sktlim@umich.edu#ifndef __CPU_O3_STORE_SET_HH__
302292SN/A#define __CPU_O3_STORE_SET_HH__
312292SN/A
322292SN/A#include <list>
332292SN/A#include <map>
342292SN/A#include <utility>
352329SN/A#include <vector>
362292SN/A
372292SN/A#include "arch/isa_traits.hh"
382292SN/A#include "cpu/inst_seq.hh"
392329SN/A
402292SN/Astruct ltseqnum {
412292SN/A    bool operator()(const InstSeqNum &lhs, const InstSeqNum &rhs) const
422292SN/A    {
432669Sktlim@umich.edu        return lhs > rhs;
442669Sktlim@umich.edu    }
452292SN/A};
462292SN/A
472329SN/A/**
482329SN/A * Implements a store set predictor for determining if memory
492329SN/A * instructions are dependent upon each other.  See paper "Memory
502329SN/A * Dependence Prediction using Store Sets" by Chrysos and Emer.  SSID
512329SN/A * stands for Store Set ID, SSIT stands for Store Set ID Table, and
522329SN/A * LFST is Last Fetched Store Table.
532329SN/A */
542329SN/Aclass StoreSet
552329SN/A{
562329SN/A  public:
572292SN/A    typedef unsigned SSID;
582292SN/A
592292SN/A  public:
602292SN/A    /** Default constructor.  init() must be called prior to use. */
612292SN/A    StoreSet() { };
622292SN/A
632292SN/A    /** Creates store set predictor with given table sizes. */
642733Sktlim@umich.edu    StoreSet(int SSIT_size, int LFST_size);
652292SN/A
662292SN/A    /** Default destructor. */
672292SN/A    ~StoreSet();
682292SN/A
692292SN/A    /** Initializes the store set predictor with the given table sizes. */
702292SN/A    void init(int SSIT_size, int LFST_size);
712292SN/A
722292SN/A    /** Records a memory ordering violation between the younger load
732292SN/A     * and the older store. */
742292SN/A    void violation(Addr store_PC, Addr load_PC);
752292SN/A
762292SN/A    /** Inserts a load into the store set predictor.  This does nothing but
772292SN/A     * is included in case other predictors require a similar function.
782292SN/A     */
792292SN/A    void insertLoad(Addr load_PC, InstSeqNum load_seq_num);
802727Sktlim@umich.edu
812727Sktlim@umich.edu    /** Inserts a store into the store set predictor.  Updates the
822727Sktlim@umich.edu     * LFST if the store has a valid SSID. */
832292SN/A    void insertStore(Addr store_PC, InstSeqNum store_seq_num,
842733Sktlim@umich.edu                     unsigned tid);
852292SN/A
862292SN/A    /** Checks if the instruction with the given PC is dependent upon
872292SN/A     * any store.  @return Returns the sequence number of the store
882292SN/A     * instruction this PC is dependent upon.  Returns 0 if none.
892292SN/A     */
902348SN/A    InstSeqNum checkInst(Addr PC);
912307SN/A
922307SN/A    /** Records this PC/sequence number as issued. */
932348SN/A    void issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store);
942307SN/A
952307SN/A    /** Squashes for a specific thread until the given sequence number. */
962348SN/A    void squash(InstSeqNum squashed_num, unsigned tid);
972307SN/A
982307SN/A    /** Resets all tables. */
992292SN/A    void clear();
1002292SN/A
1012292SN/A    /** Debug function to dump the contents of the store list. */
1022292SN/A    void dump();
1032292SN/A
1042292SN/A  private:
1052292SN/A    /** Calculates the index into the SSIT based on the PC. */
1062292SN/A    inline int calcIndex(Addr PC)
1072292SN/A    { return (PC >> offsetBits) & indexMask; }
1082292SN/A
1092292SN/A    /** Calculates a Store Set ID based on the PC. */
1102292SN/A    inline SSID calcSSID(Addr PC)
1112292SN/A    { return ((PC ^ (PC >> 10)) % LFSTSize); }
1122292SN/A
1132292SN/A    /** The Store Set ID Table. */
1142292SN/A    std::vector<SSID> SSIT;
1152292SN/A
1162329SN/A    /** Bit vector to tell if the SSIT has a valid entry. */
1172292SN/A    std::vector<bool> validSSIT;
1182292SN/A
1192292SN/A    /** Last Fetched Store Table. */
1202292SN/A    std::vector<InstSeqNum> LFST;
1212292SN/A
1222292SN/A    /** Bit vector to tell if the LFST has a valid entry. */
1232292SN/A    std::vector<bool> validLFST;
1242292SN/A
1252292SN/A    /** Map of stores that have been inserted into the store set, but
1262292SN/A     * not yet issued or squashed.
1272292SN/A     */
1282292SN/A    std::map<InstSeqNum, int, ltseqnum> storeList;
1292292SN/A
1302292SN/A    typedef std::map<InstSeqNum, int, ltseqnum>::iterator SeqNumMapIt;
1312669Sktlim@umich.edu
1322669Sktlim@umich.edu    /** Store Set ID Table size, in entries. */
1332292SN/A    int SSITSize;
1342292SN/A
1352292SN/A    /** Last Fetched Store Table size, in entries. */
1362292SN/A    int LFSTSize;
1372292SN/A
1382292SN/A    /** Mask to obtain the index. */
1392292SN/A    int indexMask;
1402292SN/A
1412292SN/A    // HACK: Hardcoded for now.
1422292SN/A    int offsetBits;
1432292SN/A};
1442292SN/A
1452292SN/A#endif // __CPU_O3_STORE_SET_HH__
1462292SN/A