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
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
00047
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));
00055 func[bit/32] |= ((val & 0x1) << (bit%32));
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
00063
00064
00065 unsigned char N_input;
00066
00067 #ifdef CELL_MAPPING
00068 unsigned char directInput;
00069 unsigned char directFlag;
00070 unsigned char constantFlag;
00071 unsigned char P;
00072 oa::oaDesign *cell;
00073 oa::oaDesign *implementCell;
00074 #else
00075
00076
00077
00078
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
00090
00091
00092 cost = 1.0;
00093
00094 bzero(&N_input, sizeof(unsigned char));
00095 #endif
00096
00097 }
00098 TableEntry(const TableEntry ©) { memcpy(this, ©, 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