Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

oagFpgaMapper.h

Go to the documentation of this file.
00001 
00002 #if !defined(oagFpgaMapperTable_P)
00003 #define oagFpgaMapperTable_P
00004 
00005 #include "oaDesignDB.h"
00006 #include "oagFpga.h"
00007 #include "oagFpgaAiModGraph.h"
00008 #include "oagFpgaMapperUtils.h"
00009 #include <map>
00010 
00011 using namespace std;
00012 
00013 namespace oagFpga {
00014 
00015 // *****************************************************************************
00016 // FpgaMapper
00017 //
00038 // *****************************************************************************
00039 
00040     class FpgaMapper {
00041 
00042         static const int MAX_CUT_SIZE = 4;
00043 
00044         struct TableEntry {
00045             static const unsigned int MAX_WORDS = 1;
00046             // MAX_WORDS should be consistent with MAX_CUT_SIZE
00047             // basically 2^MAX_CUT_SIZE = 32*MAX_WORDS
00048             static const unsigned int BITS_PER_WORD = sizeof(unsigned int)*8;
00049 
00050             unsigned int         func[MAX_WORDS];
00051 
00052             inline void setBit(unsigned int bit, bool val) {
00053                 assert(bit/32 < MAX_WORDS);
00054                 func[bit/32] &= ~(0x1 << (bit%32)); // clear always
00055                 func[bit/32] |= ((val & 0x1) << (bit%32)); // set appropriately
00056             }
00057             inline bool getBit(unsigned int bit) {
00058                 assert(bit/32 < MAX_WORDS);
00059                 return (func[bit/32] >> (bit%32)) & 0x1;
00060             }
00061 
00062             // NOTE: there is no need to have N_input for LUT based map,
00063             // i keep it at present due to the reason that i'm too lazy to 
00064             // remove all its correspondat stuffs...
00065             unsigned char   N_input;      // bitfield of input inversions
00066 
00067 #ifdef CELL_MAPPING
00068             unsigned char   directInput;  // input number of direct connection
00069             unsigned char   directFlag;   // bit flag of direct connection
00070             unsigned char   constantFlag; // bit flag of constant function
00071             unsigned char   P;            // permutation ID of inputs
00072             oa::oaDesign   *cell;           // where the functional description lies
00073             oa::oaDesign   *implementCell;  // the cell to actually be implemented
00074 #else
00075             // For LUT based mapping, i assume that the implementation cells 
00076             // for all TableEntry are LUTs.
00077             // TODO: to extend the mapper to consider multiple types of LUTs, 
00078             // "implementCell" can be used
00079 
00080 #endif // #ifdef CELL_MAPPING
00081 
00082             float           cost;
00083 
00084             TableEntry() { 
00085                 N_input = 0; 
00086 #ifdef CELL_MAPPING
00087                 cell = NULL; 
00088 #else
00089                 // NOTE: i initiliaze the cost of the TableEntry as 1.0 which is 
00090                 // both area and delay cost of a LUT.
00091                 // TODO: extra routines need to be written for general cost
00092                 cost = 1.0; 
00093                 // none of inputs in a LUT is inverted
00094                 bzero(&N_input, sizeof(unsigned char));
00095 #endif
00096 
00097             }
00098             TableEntry(const TableEntry &copy) { memcpy(this, &copy, sizeof(TableEntry)); }
00099 
00100             inline bool match(const TableEntry & t) {
00101                 for(unsigned int i=0;i<MAX_WORDS;i++) {
00102                     if (func[i] != t.func[i]) {
00103                         return false;
00104                     }
00105                 }
00106                 return true;
00107             }
00108         };
00109 
00110     public:
00111 
00112         typedef enum{POSEDGE, NEGEDGE} TriggerType;
00113 
00116 
00117         FpgaMapper(int cutsPerNode);
00118 
00119 #ifdef CELL_MAPPING
00120         void                useAlternateView(const oa::oaScalarName &viewName);
00121         void                addLibraryGate(oa::oaDesign* design);
00122 #endif // #ifdef CELL_MAPPING
00123 
00124         void                techmapDelay(oa::oaModule *target);
00125         void                techmapArea(oa::oaModule *target);
00126 
00127         MapperUtils    mapUtils;
00128 
00129     protected:
00130 
00134 
00135         void                     addTrivialGates();
00136 
00137         int                      cutsPerNode;
00138 
00139 #ifdef CELL_MAPPING
00140         std::vector<TableEntry>  tables[MAX_CUT_SIZE+1];
00141 #endif //#ifdef CELL_MAPPING
00142 
00143         void                     initializeSimulation();
00144         void                     simulate(oa::oaDesign *design,
00145                                     TableEntry &outResult, AiModRef & out, 
00146                                     vector<AiModRef> cut);
00147         unsigned int             exhaustiveInputVectors[MAX_CUT_SIZE][TableEntry::MAX_WORDS];
00148 
00149 
00150 
00154 
00155         map<AiModRef,TableEntry *>            choice_p, choice_n;
00156         map<AiModRef,AiModGraph::Cut>           cut_p, cut_n;
00157         map<AiModRef,double>                  cost_p, cost_n;
00158         map<AiModRef,oa::oaModBitNet*>        mapped;
00159 
00160         double     totalArea, totalDelay;
00161         int        gateCount;
00162         int        seqCount;
00163 
00164         double getCumulativeAreaCost(AiModGraph::Cut *cut, TableEntry *choice);
00165         double getCumulativeDelayCost(AiModGraph::Cut *cut, TableEntry *choice);
00166 
00170     protected:
00171 
00172         void                implementAll(oa::oaModule *target);
00173         oa::oaModInst *     implementSeqNode(AiModRef x);
00174         oa::oaModBitNet *   implementNode(AiModRef x);
00175 
00179 #ifdef CELL_MAPPING
00180         std::list<oa::oaDesign*> libraryCells;
00181         oa::oaScalarName         alternateViewName;
00182         bool                     useAlternateViews;
00183         TableEntry              *notEntry;
00184 #else
00185         TableEntry              notEntry;
00186         TableEntry              constantZeroEntry;
00187 
00188 #endif // #ifdef CELL_MAPPING
00189 
00190         void   setAreaCosts();
00191         void   setDelayCosts();
00192 
00194 
00195     };
00196 
00197 }
00198 #endif

Generated on Mon Jul 9 14:17:19 2007 for OA Gear Fpga by  doxygen 1.3.9.1