ruby: move stall and wakeup functions to AbstractController
[gem5.git] / src / cpu / static_inst.hh
index 5951ab1223988236f2570bb6d787af9c8608c36b..507decbdf51e37bb1661a6dd385def5135a4fbeb 100644 (file)
 #include <bitset>
 #include <string>
 
-#include "arch/isa_traits.hh"
-#include "arch/types.hh"
 #include "arch/registers.hh"
-#include "config/the_isa.hh"
-#include "base/hashmap.hh"
+#include "arch/types.hh"
 #include "base/misc.hh"
 #include "base/refcnt.hh"
 #include "base/types.hh"
+#include "config/the_isa.hh"
 #include "cpu/op_class.hh"
-#include "sim/fault.hh"
+#include "cpu/static_inst_fwd.hh"
+#include "cpu/thread_context.hh"
+#include "sim/fault_fwd.hh"
 
 // forward declarations
 struct AlphaSimpleImpl;
 struct OzoneImpl;
 struct SimpleImpl;
-class ThreadContext;
 class DynInst;
 class Packet;
 
-class O3CPUImpl;
+struct O3CPUImpl;
 template <class Impl> class BaseO3DynInst;
 typedef BaseO3DynInst<O3CPUImpl> O3DynInst;
 template <class Impl> class OzoneDynInst;
@@ -65,7 +64,6 @@ class AtomicSimpleCPU;
 class TimingSimpleCPU;
 class InorderCPU;
 class SymbolTable;
-class AddrDecodePage;
 
 namespace Trace {
     class InstRecord;
@@ -79,9 +77,18 @@ namespace Trace {
  * solely on these flags can process instructions without being
  * recompiled for multiple ISAs.
  */
-class StaticInstBase : public RefCounted
+class StaticInst : public RefCounted
 {
   public:
+    /// Binary extended machine instruction type.
+    typedef TheISA::ExtMachInst ExtMachInst;
+    /// Logical register index type.
+    typedef TheISA::RegIndex RegIndex;
+
+    enum {
+        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        //< Max source regs
+        MaxInstDestRegs = TheISA::MaxInstDestRegs       //< Max dest regs
+    };
 
     /// Set of boolean static instruction properties.
     ///
@@ -117,7 +124,6 @@ class StaticInstBase : public RefCounted
         IsIndexed,      ///< Accesses memory with an indexed address computation
         IsInstPrefetch, ///< Instruction-cache prefetch.
         IsDataPrefetch, ///< Data-cache prefetch.
-        IsCopy,         ///< Fast Cache block copy
 
         IsControl,              ///< Control transfer instruction.
         IsDirectControl,        ///< PC relative control transfer.
@@ -158,7 +164,7 @@ class StaticInstBase : public RefCounted
         //This flag doesn't do anything yet
         IsMicroBranch,  ///< This microop branches within the microcode for a macroop
         IsDspOp,
-
+        IsSquashAfter, ///< Squash all uncommitted state after executed
         NumFlags
     };
 
@@ -183,17 +189,6 @@ class StaticInstBase : public RefCounted
     int8_t _numIntDestRegs;
     //@}
 
-    /// Constructor.
-    /// It's important to initialize everything here to a sane
-    /// default, since the decoder generally only overrides
-    /// the fields that are meaningful for the particular
-    /// instruction.
-    StaticInstBase(OpClass __opClass)
-        : _opClass(__opClass), _numSrcRegs(0), _numDestRegs(0),
-          _numFPDestRegs(0), _numIntDestRegs(0)
-    {
-    }
-
   public:
 
     /// @name Register information.
@@ -214,7 +209,7 @@ class StaticInstBase : public RefCounted
 
     /// @name Flag accessors.
     /// These functions are used to access the values of the various
-    /// instruction property flags.  See StaticInstBase::Flags for descriptions
+    /// instruction property flags.  See StaticInst::Flags for descriptions
     /// of the individual flags.
     //@{
 
@@ -226,7 +221,8 @@ class StaticInstBase : public RefCounted
     bool isStoreConditional()     const { return flags[IsStoreConditional]; }
     bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
     bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
-    bool isCopy()         const { return flags[IsCopy];}
+    bool isPrefetch()     const { return isInstPrefetch() ||
+                                         isDataPrefetch(); }
 
     bool isInteger()      const { return flags[IsInteger]; }
     bool isFloating()     const { return flags[IsFloating]; }
@@ -246,6 +242,7 @@ class StaticInstBase : public RefCounted
                                       flags[IsSerializeAfter]; }
     bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
     bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
+    bool isSquashAfter() const { return flags[IsSquashAfter]; }
     bool isMemBarrier()   const { return flags[IsMemBarrier]; }
     bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
     bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
@@ -264,37 +261,10 @@ class StaticInstBase : public RefCounted
 
     void setLastMicroop() { flags[IsLastMicroop] = true; }
     void setDelayedCommit() { flags[IsDelayedCommit] = true; }
+    void setFlag(Flags f) { flags[f] = true; }
 
     /// Operation class.  Used to select appropriate function unit in issue.
     OpClass opClass()     const { return _opClass; }
-};
-
-
-// forward declaration
-class StaticInstPtr;
-
-/**
- * Generic yet ISA-dependent static instruction class.
- *
- * This class builds on StaticInstBase, defining fields and interfaces
- * that are generic across all ISAs but that differ in details
- * according to the specific ISA being used.
- */
-class StaticInst : public StaticInstBase
-{
-  public:
-
-    /// Binary machine instruction type.
-    typedef TheISA::MachInst MachInst;
-    /// Binary extended machine instruction type.
-    typedef TheISA::ExtMachInst ExtMachInst;
-    /// Logical register index type.
-    typedef TheISA::RegIndex RegIndex;
-
-    enum {
-        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        //< Max source regs
-        MaxInstDestRegs = TheISA::MaxInstDestRegs,      //< Max dest regs
-    };
 
 
     /// Return logical index (architectural reg num) of i'th destination reg.
@@ -359,8 +329,13 @@ class StaticInst : public StaticInstBase
     generateDisassembly(Addr pc, const SymbolTable *symtab) const = 0;
 
     /// Constructor.
+    /// It's important to initialize everything here to a sane
+    /// default, since the decoder generally only overrides
+    /// the fields that are meaningful for the particular
+    /// instruction.
     StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
-        : StaticInstBase(__opClass),
+        : _opClass(__opClass), _numSrcRegs(0), _numDestRegs(0),
+          _numFPDestRegs(0), _numIntDestRegs(0),
           machInst(_machInst), mnemonic(_mnemonic), cachedDisassembly(0)
     { }
 
@@ -414,231 +389,8 @@ class StaticInst : public StaticInstBase
     virtual const std::string &disassemble(Addr pc,
         const SymbolTable *symtab = 0) const;
 
-    /// Decoded instruction cache type.
-    /// For now we're using a generic hash_map; this seems to work
-    /// pretty well.
-    typedef m5::hash_map<ExtMachInst, StaticInstPtr> DecodeCache;
-
-    /// A cache of decoded instruction objects.
-    static DecodeCache decodeCache;
-
-    /**
-     * Dump some basic stats on the decode cache hash map.
-     * Only gets called if DECODE_CACHE_HASH_STATS is defined.
-     */
-    static void dumpDecodeCacheStats();
-
-    /// Decode a machine instruction.
-    /// @param mach_inst The binary instruction to decode.
-    /// @retval A pointer to the corresponding StaticInst object.
-    //This is defined as inlined below.
-    static StaticInstPtr decode(ExtMachInst mach_inst, Addr addr);
-
     /// Return name of machine instruction
     std::string getName() { return mnemonic; }
-
-    /// Decoded instruction cache type, for address decoding.
-    /// A generic hash_map is used.
-    typedef m5::hash_map<Addr, AddrDecodePage *> AddrDecodeCache;
-
-    /// A cache of decoded instruction objects from addresses.
-    static AddrDecodeCache addrDecodeCache;
-
-    struct cacheElement
-    {
-        Addr page_addr;
-        AddrDecodePage *decodePage;
-
-        cacheElement() : decodePage(NULL) { }
-    };
-
-    /// An array of recently decoded instructions.
-    // might not use an array if there is only two elements
-    static struct cacheElement recentDecodes[2];
-
-    /// Updates the recently decoded instructions entries
-    /// @param page_addr The page address recently used.
-    /// @param decodePage Pointer to decoding page containing the decoded
-    ///                   instruction.
-    static inline void
-    updateCache(Addr page_addr, AddrDecodePage *decodePage)
-    {
-        recentDecodes[1].page_addr = recentDecodes[0].page_addr;
-        recentDecodes[1].decodePage = recentDecodes[0].decodePage;
-        recentDecodes[0].page_addr = page_addr;
-        recentDecodes[0].decodePage = decodePage;
-    }
-
-    /// Searches the decoded instruction cache for instruction decoding.
-    /// If it is not found, then we decode the instruction.
-    /// Otherwise, we get the instruction from the cache and move it into
-    /// the address-to-instruction decoding page.
-    /// @param mach_inst The binary instruction to decode.
-    /// @param addr The address that contained the binary instruction.
-    /// @param decodePage Pointer to decoding page containing the instruction.
-    /// @retval A pointer to the corresponding StaticInst object.
-    //This is defined as inlined below.
-    static StaticInstPtr searchCache(ExtMachInst mach_inst, Addr addr,
-                                     AddrDecodePage *decodePage);
 };
 
-typedef RefCountingPtr<StaticInstBase> StaticInstBasePtr;
-
-/// Reference-counted pointer to a StaticInst object.
-/// This type should be used instead of "StaticInst *" so that
-/// StaticInst objects can be properly reference-counted.
-class StaticInstPtr : public RefCountingPtr<StaticInst>
-{
-  public:
-    /// Constructor.
-    StaticInstPtr()
-        : RefCountingPtr<StaticInst>()
-    {
-    }
-
-    /// Conversion from "StaticInst *".
-    StaticInstPtr(StaticInst *p)
-        : RefCountingPtr<StaticInst>(p)
-    {
-    }
-
-    /// Copy constructor.
-    StaticInstPtr(const StaticInstPtr &r)
-        : RefCountingPtr<StaticInst>(r)
-    {
-    }
-
-    /// Construct directly from machine instruction.
-    /// Calls StaticInst::decode().
-    explicit StaticInstPtr(TheISA::ExtMachInst mach_inst, Addr addr)
-        : RefCountingPtr<StaticInst>(StaticInst::decode(mach_inst, addr))
-    {
-    }
-
-    /// Convert to pointer to StaticInstBase class.
-    operator const StaticInstBasePtr()
-    {
-        return this->get();
-    }
-};
-
-/// A page of a list of decoded instructions from an address.
-class AddrDecodePage
-{
-  typedef TheISA::ExtMachInst ExtMachInst;
-  protected:
-    StaticInstPtr instructions[TheISA::PageBytes];
-    bool valid[TheISA::PageBytes];
-    Addr lowerMask;
-
-  public:
-    /// Constructor
-    AddrDecodePage()
-    {
-        lowerMask = TheISA::PageBytes - 1;
-        memset(valid, 0, TheISA::PageBytes);
-    }
-
-    /// Checks if the instruction is already decoded and the machine
-    /// instruction in the cache matches the current machine instruction
-    /// related to the address
-    /// @param mach_inst The binary instruction to check
-    /// @param addr The address containing the instruction
-    bool
-    decoded(ExtMachInst mach_inst, Addr addr)
-    {
-        return (valid[addr & lowerMask] &&
-                (instructions[addr & lowerMask]->machInst == mach_inst));
-    }
-
-    /// Returns the instruction object. decoded should be called first
-    /// to check if the instruction is valid.
-    /// @param addr The address of the instruction.
-    /// @retval A pointer to the corresponding StaticInst object.
-    StaticInstPtr
-    getInst(Addr addr)
-    {
-        return instructions[addr & lowerMask];
-    }
-
-    /// Inserts a pointer to a StaticInst object into the list of decoded
-    /// instructions on the page.
-    /// @param addr The address of the instruction.
-    /// @param si A pointer to the corresponding StaticInst object.
-    void
-    insert(Addr addr, StaticInstPtr &si)
-    {
-        instructions[addr & lowerMask] = si;
-        valid[addr & lowerMask] = true;
-    }
-};
-
-
-inline StaticInstPtr
-StaticInst::decode(StaticInst::ExtMachInst mach_inst, Addr addr)
-{
-#ifdef DECODE_CACHE_HASH_STATS
-    // Simple stats on decode hash_map.  Turns out the default
-    // hash function is as good as anything I could come up with.
-    const int dump_every_n = 10000000;
-    static int decodes_til_dump = dump_every_n;
-
-    if (--decodes_til_dump == 0) {
-        dumpDecodeCacheStats();
-        decodes_til_dump = dump_every_n;
-    }
-#endif
-
-    Addr page_addr = addr & ~(TheISA::PageBytes - 1);
-
-    // checks recently decoded addresses
-    if (recentDecodes[0].decodePage &&
-        page_addr == recentDecodes[0].page_addr) {
-        if (recentDecodes[0].decodePage->decoded(mach_inst, addr))
-            return recentDecodes[0].decodePage->getInst(addr);
-
-        return searchCache(mach_inst, addr, recentDecodes[0].decodePage);
-    }
-
-    if (recentDecodes[1].decodePage &&
-        page_addr == recentDecodes[1].page_addr) {
-        if (recentDecodes[1].decodePage->decoded(mach_inst, addr))
-            return recentDecodes[1].decodePage->getInst(addr);
-
-        return searchCache(mach_inst, addr, recentDecodes[1].decodePage);
-    }
-
-    // searches the page containing the address to decode
-    AddrDecodeCache::iterator iter = addrDecodeCache.find(page_addr);
-    if (iter != addrDecodeCache.end()) {
-        updateCache(page_addr, iter->second);
-        if (iter->second->decoded(mach_inst, addr))
-            return iter->second->getInst(addr);
-
-        return searchCache(mach_inst, addr, iter->second);
-    }
-
-    // creates a new object for a page of decoded instructions
-    AddrDecodePage *decodePage = new AddrDecodePage;
-    addrDecodeCache[page_addr] = decodePage;
-    updateCache(page_addr, decodePage);
-    return searchCache(mach_inst, addr, decodePage);
-}
-
-inline StaticInstPtr
-StaticInst::searchCache(ExtMachInst mach_inst, Addr addr,
-                        AddrDecodePage *decodePage)
-{
-    DecodeCache::iterator iter = decodeCache.find(mach_inst);
-    if (iter != decodeCache.end()) {
-        decodePage->insert(addr, iter->second);
-        return iter->second;
-    }
-
-    StaticInstPtr si = TheISA::decodeInst(mach_inst);
-    decodePage->insert(addr, si);
-    decodeCache[mach_inst] = si;
-    return si;
-}
-
 #endif // __CPU_STATIC_INST_HH__