00001 00021 #include "cswInt.h" 00022 00026 00030 00042 unsigned Csw_CutHash( Csw_Cut_t * pCut ) 00043 { 00044 static int s_FPrimes[128] = { 00045 1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459, 00046 1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997, 00047 2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543, 00048 2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089, 00049 3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671, 00050 3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243, 00051 4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871, 00052 4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471, 00053 5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073, 00054 6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689, 00055 6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309, 00056 7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933, 00057 8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147 00058 }; 00059 unsigned uHash; 00060 int i; 00061 assert( pCut->nFanins <= 16 ); 00062 uHash = 0; 00063 for ( i = 0; i < pCut->nFanins; i++ ) 00064 uHash ^= pCut->pFanins[i] * s_FPrimes[i]; 00065 return uHash; 00066 } 00067 00079 int Csw_TableCountCuts( Csw_Man_t * p ) 00080 { 00081 Csw_Cut_t * pEnt; 00082 int i, Counter = 0; 00083 for ( i = 0; i < p->nTableSize; i++ ) 00084 for ( pEnt = p->pTable[i]; pEnt; pEnt = pEnt->pNext ) 00085 Counter++; 00086 return Counter; 00087 } 00088 00100 void Csw_TableCutInsert( Csw_Man_t * p, Csw_Cut_t * pCut ) 00101 { 00102 int iEntry = Csw_CutHash(pCut) % p->nTableSize; 00103 pCut->pNext = p->pTable[iEntry]; 00104 p->pTable[iEntry] = pCut; 00105 } 00106 00118 Aig_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ) 00119 { 00120 Aig_Obj_t * pRes = NULL; 00121 Csw_Cut_t * pEnt; 00122 unsigned * pTruthNew, * pTruthOld; 00123 int iEntry = Csw_CutHash(pCut) % p->nTableSize; 00124 for ( pEnt = p->pTable[iEntry]; pEnt; pEnt = pEnt->pNext ) 00125 { 00126 if ( pEnt->nFanins != pCut->nFanins ) 00127 continue; 00128 if ( pEnt->uSign != pCut->uSign ) 00129 continue; 00130 if ( memcmp( pEnt->pFanins, pCut->pFanins, sizeof(int) * pCut->nFanins ) ) 00131 continue; 00132 pTruthOld = Csw_CutTruth(pEnt); 00133 pTruthNew = Csw_CutTruth(pCut); 00134 if ( (pTruthOld[0] & 1) == (pTruthNew[0] & 1) ) 00135 { 00136 if ( Kit_TruthIsEqual( pTruthOld, pTruthNew, pCut->nFanins ) ) 00137 { 00138 pRes = Aig_ManObj( p->pManRes, pEnt->iNode ); 00139 assert( pRes->fPhase == Aig_ManObj( p->pManRes, pCut->iNode )->fPhase ); 00140 break; 00141 } 00142 } 00143 else 00144 { 00145 if ( Kit_TruthIsOpposite( pTruthOld, pTruthNew, pCut->nFanins ) ) 00146 { 00147 pRes = Aig_Not( Aig_ManObj( p->pManRes, pEnt->iNode ) ); 00148 assert( Aig_Regular(pRes)->fPhase != Aig_ManObj( p->pManRes, pCut->iNode )->fPhase ); 00149 break; 00150 } 00151 } 00152 } 00153 return pRes; 00154 } 00155 00156 00160 00161