decode.hh revision 1062
1// Todo: 2// Add a couple of the branch fields to DynInst. Figure out where DynInst 3// should try to compute the target of a PC-relative branch. Try to avoid 4// having so many returns within the code. 5// Fix up squashing too, as it's too 6// dependent upon the iew stage continually telling it to squash. 7 8#ifndef __SIMPLE_DECODE_HH__ 9#define __SIMPLE_DECODE_HH__ 10 11#include <queue> 12 13#include "base/timebuf.hh" 14 15template<class Impl> 16class SimpleDecode 17{ 18 private: 19 // Typedefs from the Impl. 20 typedef typename Impl::ISA ISA; 21 typedef typename Impl::FullCPU FullCPU; 22 typedef typename Impl::DynInstPtr DynInstPtr; 23 typedef typename Impl::Params Params; 24 typedef typename Impl::CPUPol CPUPol; 25 26 // Typedefs from the CPU policy. 27 typedef typename CPUPol::FetchStruct FetchStruct; 28 typedef typename CPUPol::DecodeStruct DecodeStruct; 29 typedef typename CPUPol::TimeStruct TimeStruct; 30 31 // Typedefs from the ISA. 32 typedef typename ISA::Addr Addr; 33 34 public: 35 // The only time decode will become blocked is if dispatch becomes 36 // blocked, which means IQ or ROB is probably full. 37 enum Status { 38 Running, 39 Idle, 40 Squashing, 41 Blocked, 42 Unblocking 43 }; 44 45 private: 46 // May eventually need statuses on a per thread basis. 47 Status _status; 48 49 public: 50 SimpleDecode(Params ¶ms); 51 52 void regStats(); 53 54 void setCPU(FullCPU *cpu_ptr); 55 56 void setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr); 57 58 void setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr); 59 60 void setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr); 61 62 void tick(); 63 64 void decode(); 65 66 // Might want to make squash a friend function. 67 void squash(); 68 69 private: 70 void block(); 71 72 inline void unblock(); 73 74 void squash(DynInstPtr &inst); 75 76 // Interfaces to objects outside of decode. 77 /** CPU interface. */ 78 FullCPU *cpu; 79 80 /** Time buffer interface. */ 81 TimeBuffer<TimeStruct> *timeBuffer; 82 83 /** Wire to get rename's output from backwards time buffer. */ 84 typename TimeBuffer<TimeStruct>::wire fromRename; 85 86 /** Wire to get iew's information from backwards time buffer. */ 87 typename TimeBuffer<TimeStruct>::wire fromIEW; 88 89 /** Wire to get commit's information from backwards time buffer. */ 90 typename TimeBuffer<TimeStruct>::wire fromCommit; 91 92 /** Wire to write information heading to previous stages. */ 93 // Might not be the best name as not only fetch will read it. 94 typename TimeBuffer<TimeStruct>::wire toFetch; 95 96 /** Decode instruction queue. */ 97 TimeBuffer<DecodeStruct> *decodeQueue; 98 99 /** Wire used to write any information heading to rename. */ 100 typename TimeBuffer<DecodeStruct>::wire toRename; 101 102 /** Fetch instruction queue interface. */ 103 TimeBuffer<FetchStruct> *fetchQueue; 104 105 /** Wire to get fetch's output from fetch queue. */ 106 typename TimeBuffer<FetchStruct>::wire fromFetch; 107 108 /** Skid buffer between fetch and decode. */ 109 std::queue<FetchStruct> skidBuffer; 110 111 private: 112 //Consider making these unsigned to avoid any confusion. 113 /** Rename to decode delay, in ticks. */ 114 unsigned renameToDecodeDelay; 115 116 /** IEW to decode delay, in ticks. */ 117 unsigned iewToDecodeDelay; 118 119 /** Commit to decode delay, in ticks. */ 120 unsigned commitToDecodeDelay; 121 122 /** Fetch to decode delay, in ticks. */ 123 unsigned fetchToDecodeDelay; 124 125 /** The width of decode, in instructions. */ 126 unsigned decodeWidth; 127 128 /** The instruction that decode is currently on. It needs to have 129 * persistent state so that when a stall occurs in the middle of a 130 * group of instructions, it can restart at the proper instruction. 131 */ 132 unsigned numInst; 133 134 Stats::Scalar<> decodeIdleCycles; 135 Stats::Scalar<> decodeBlockedCycles; 136 Stats::Scalar<> decodeUnblockCycles; 137 Stats::Scalar<> decodeSquashCycles; 138 Stats::Scalar<> decodeBranchMispred; 139 Stats::Scalar<> decodeControlMispred; 140 Stats::Scalar<> decodeDecodedInsts; 141 Stats::Scalar<> decodeSquashedInsts; 142}; 143 144#endif // __SIMPLE_DECODE_HH__ 145