types: clean up types, especially signed vs unsigned
[gem5.git] / src / cpu / inorder / inorder_dyn_inst.hh
index 55c61ffb98516a82532c7ef01cea16c683b18ac6..031d882eef12c6e12af5069963e49791c0d85b33 100644 (file)
 #include <list>
 #include <string>
 
+#include "arch/isa_traits.hh"
 #include "arch/faults.hh"
+#include "arch/types.hh"
+#include "arch/mt.hh"
 #include "base/fast_alloc.hh"
 #include "base/trace.hh"
 #include "cpu/inorder/inorder_trace.hh"
@@ -109,8 +112,8 @@ class InOrderDynInst : public FastAlloc, public RefCounted
      *  @param cpu Pointer to the instruction's CPU.
      *  NOTE: Must set Binary Instrution through Member Function
      */
-    InOrderDynInst(InOrderCPU *cpu, InOrderThreadState *state, InstSeqNum seq_num,
-                 unsigned tid);
+    InOrderDynInst(InOrderCPU *cpu, InOrderThreadState *state,
+                   InstSeqNum seq_num, ThreadID tid, unsigned asid = 0);
 
     /** BaseDynInst constructor given a StaticInst pointer.
      *  @param _staticInst The StaticInst for this BaseDynInst.
@@ -223,14 +226,28 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     /** An instruction src/dest has to be one of these types */
     union InstValue {
         uint64_t integer;
-        float fp;
         double dbl;
     };
 
+    //@TODO: Naming Convention for Enums?
+    enum ResultType {
+        None,
+        Integer,
+        Float,
+        Double
+    };
+
+
     /** Result of an instruction execution */
     struct InstResult {
+        ResultType type;
         InstValue val;
         Tick tick;
+        int width;
+
+        InstResult()
+            : type(None), tick(0), width(0)
+        {}
     };
 
     /** The source of the instruction; assumes for now that there's only one
@@ -261,6 +278,12 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     /** Predicted next PC. */
     Addr predPC;
 
+    /** Predicted next NPC. */
+    Addr predNPC;
+
+    /** Predicted next microPC */
+    Addr predMicroPC;
+
     /** Address to fetch from */
     Addr fetchAddr;
 
@@ -306,6 +329,9 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     //  BASE INSTRUCTION INFORMATION.
     //
     ////////////////////////////////////////////////////////////
+    std::string instName() { return staticInst->getName(); }
+
+
     void setMachInst(ExtMachInst inst);
 
     /** Sets the StaticInst. */
@@ -321,7 +347,7 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     short readTid() { return threadNumber; }
 
     /** Sets the thread id. */
-    void setTid(unsigned tid) { threadNumber = tid; }
+    void setTid(ThreadID tid) { threadNumber = tid; }
 
     void setVpn(int id) { virtProcNumber = id; }
 
@@ -394,11 +420,10 @@ class InOrderDynInst : public FastAlloc, public RefCounted
 
 
     /** Print Resource Schedule */
+    /** @NOTE: DEBUG ONLY */
     void printSched()
     {
-        using namespace ThePipeline;
-
-        ResSchedule tempSched;
+        ThePipeline::ResSchedule tempSched;
         std::cerr << "\tInst. Res. Schedule: ";
         while (!resSched.empty()) {
             std::cerr << '\t' << resSched.top()->stageNum << "-"
@@ -481,8 +506,6 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     virtual void enableMultiThreading(unsigned vpe);
     virtual void disableMultiThreading(unsigned vpe);
 
-    virtual void setThreadRescheduleCondition(uint32_t cond);
-
     ////////////////////////////////////////////////////////////
     //
     //  PROGRAM COUNTERS - PC/NPC/NPC
@@ -505,7 +528,14 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     /** Returns the next NPC.  This could be the speculative next NPC if it is
      *  called prior to the actual branch target being calculated.
      */
-    Addr readNextNPC() { return nextNPC; }
+    Addr readNextNPC()
+    {
+#if ISA_HAS_DELAY_SLOT
+        return nextNPC;
+#else
+        return nextPC + sizeof(TheISA::MachInst);
+#endif
+    }
 
     /** Set the next PC of this instruction (its actual target). */
     void setNextNPC(uint64_t val) { nextNPC = val; }
@@ -521,19 +551,26 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     /** Returns the predicted target of the branch. */
     Addr readPredTarg() { return predPC; }
 
+    /** Returns the predicted PC immediately after the branch. */
+    Addr readPredPC() { return predPC; }
+
+    /** Returns the predicted PC two instructions after the branch */
+    Addr readPredNPC() { return predNPC; }
+
+    /** Returns the predicted micro PC after the branch */
+    Addr readPredMicroPC() { return predMicroPC; }
+
     /** Returns whether the instruction was predicted taken or not. */
     bool predTaken() { return predictTaken; }
 
     /** Returns whether the instruction mispredicted. */
     bool mispredicted()
     {
-        // Special case since a not-taken, cond. delay slot, effectively
-        // nullifies the delay slot instruction
-        if (isCondDelaySlot() && !predictTaken) {
-            return predPC != nextPC;
-        } else {
-            return predPC != nextNPC;
-        }
+#if ISA_HAS_DELAY_SLOT
+        return predPC != nextNPC;
+#else
+        return predPC != nextPC;
+#endif
     }
 
     /** Returns whether the instruction mispredicted. */
@@ -598,7 +635,8 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     /** Read Effective Address from instruction & do memory access */
     Fault memAccess();
 
-    RequestPtr memReq;
+    RequestPtr fetchMemReq;
+    RequestPtr dataMemReq;
 
     bool memAddrReady;
 
@@ -614,10 +652,6 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     Addr getMemAddr()
     { return memAddr; }
 
-    int getMemAccSize() { return staticInst->memAccSize(this); }
-
-    int getMemFlags() { return staticInst->memAccFlags(); }
-
     /** Sets the effective address. */
     void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
 
@@ -795,10 +829,10 @@ class InOrderDynInst : public FastAlloc, public RefCounted
      *  language (which is why the name isnt readIntSrc(...)) Note: That
      *  the source reg. value is set using the setSrcReg() function.
      */
-    IntReg readIntRegOperand(const StaticInst *si, int idx, unsigned tid=0);
+    IntReg readIntRegOperand(const StaticInst *si, int idx, ThreadID tid = 0);
     FloatReg readFloatRegOperand(const StaticInst *si, int idx,
                           int width = TheISA::SingleWidth);
-    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
+    TheISA::FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
                                   int width = TheISA::SingleWidth);
     MiscReg readMiscReg(int misc_reg);
     MiscReg readMiscRegNoEffect(int misc_reg);
@@ -806,9 +840,30 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx);
 
     /** Returns the result value instruction. */
-    uint64_t readIntResult(int idx) { return instResult[idx].val.integer; }
-    float readFloatResult(int idx) { return instResult[idx].val.fp; }
-    double readDoubleResult(int idx) { return instResult[idx].val.dbl; }
+    ResultType resultType(int idx)
+    {
+        return instResult[idx].type;
+    }
+
+    uint64_t readIntResult(int idx)
+    {
+        return instResult[idx].val.integer;
+    }
+
+    /** Depending on type, return Float or Double */
+    double readFloatResult(int idx)
+    {
+        //Should this function have a parameter for what width of return?x
+       return (instResult[idx].type == Float) ?
+           (float) instResult[idx].val.dbl : instResult[idx].val.dbl;
+    }
+
+    double readDoubleResult(int idx)
+    {
+        assert(instResult[idx].type == Double);
+        return instResult[idx].val.dbl;
+    }
+
     Tick readResultTime(int idx) { return instResult[idx].tick; }
 
     uint64_t* getIntResultPtr(int idx) { return &instResult[idx].val.integer; }
@@ -819,15 +874,21 @@ class InOrderDynInst : public FastAlloc, public RefCounted
     void setIntRegOperand(const StaticInst *si, int idx, IntReg val);
     void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
                      int width = TheISA::SingleWidth);
-    void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val,
+    void setFloatRegOperandBits(const StaticInst *si, int idx, TheISA::FloatRegBits val,
                          int width = TheISA::SingleWidth);
     void setMiscReg(int misc_reg, const MiscReg &val);
     void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
     void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val);
     void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val);
 
-    virtual uint64_t readRegOtherThread(unsigned idx, int tid = -1);
-    virtual void setRegOtherThread(unsigned idx, const uint64_t &val, int tid = -1);
+    virtual uint64_t readRegOtherThread(unsigned idx,
+                                        ThreadID tid = InvalidThreadID);
+    virtual void setRegOtherThread(unsigned idx, const uint64_t &val,
+                                   ThreadID tid = InvalidThreadID);
+
+    /** Sets the number of consecutive store conditional failures. */
+    void setStCondFailures(unsigned sc_failures)
+    { thread->storeCondFailures = sc_failures; }
 
     //////////////////////////////////////////////////////////////
     //