00001 00002 #ifndef FUNCTIONALUNIT_H 00003 #define FUNCTIONALUNIT_H 00004 00005 #include <OpteronDefs.h> 00006 00007 //------------------------------------------------------------------- 00008 /// @brief Represents a functional unit in the CPU 00009 /// 00010 /// This keeps track of when a functional unit is occupied, and 00011 /// lets an instruction occupy it for a length of time. One object 00012 /// of this class will represent one functional unit. 00013 // 00014 // Basic idea: simulator will inspect instruction to see which FUs 00015 // it needs or can use, then will iterate functional units and for 00016 // each type that matches, it will check occupiedUntil() to find out 00017 // when it is available; if none are available then will hold that 00018 // instruction and try another (out of order); if no current 00019 // instructions can be satisfied, then stall. When an instruction 00020 // can be executed, sim will call occupy() on corresponding FUs to 00021 // occupy them for as long as needed. 00022 // 00023 // At end, FU will be able to report its duty cycle (cycles used vs. 00024 // idle) 00025 //------------------------------------------------------------------- 00026 class FunctionalUnit 00027 { 00028 public: 00029 FunctionalUnit(FunctionalUnitTypes type, const char *name, unsigned int id); 00030 ~FunctionalUnit(); 00031 void setNext(FunctionalUnit *other); 00032 FunctionalUnit* getNext(); 00033 FunctionalUnitTypes getType(); 00034 CycleCount occupiedUntil(CycleCount atCycle); 00035 int occupy(CycleCount atCycle, CycleCount numCycles); 00036 int updateStatus(CycleCount currentCycle); 00037 void flush(CycleCount atCycle); 00038 bool isAvailable(CycleCount atCycle); 00039 double dutyCycle(); 00040 private: 00041 const char *name; ///< Name of this unit 00042 FunctionalUnitTypes type; ///< Type of this unit 00043 unsigned int id; ///< Unique unit ID 00044 CycleCount occupiedUntilCycle; ///< Cycle that current insn is occupying this until 00045 bool occupied; ///< True if currently occupied 00046 CycleCount numOccupiedCycles; ///< Total # of occupied cycles 00047 CycleCount numFreeCycles; ///< Total # of free cycles 00048 CycleCount latestCycle; ///< Latest known cycle 00049 class FunctionalUnit *next; ///< Linked list ptr 00050 }; 00051 00052 #endif