29 #define MAP_CUTS_MAX_COMPUTE 1000
31 #define MAP_CUTS_MAX_USE 250
47 static int s_HashPrimes[10] = { 109, 499, 557, 619, 631, 709, 797, 881, 907, 991 };
74 #define Map_ListForEachCut( pList, pCut ) \
78 #define Map_ListForEachCutSafe( pList, pCut, pCut2 ) \
80 pCut2 = pCut? pCut->pNext: NULL; \
83 pCut2 = pCut? pCut->pNext: NULL )
108 for ( i = 0; i < pMan->nBins; i++ )
109 for ( pNode = pMan->pBins[i]; pNode; pNode = pNode->
pNext )
110 for ( pCut = pNode->
pCuts; pCut; pCut = pCut->
pNext )
168 pCut->
uTruth = 0xAAAAAAAA;
177 int nCuts, nNodes, i;
180 assert( p->nVarsMax > 1 && p->nVarsMax < 7 );
181 for ( i = 0; i < p->nInputs; i++ )
185 nNodes = p->vMapObjs->nSize;
188 for ( i = 0; i < nNodes; i++ )
190 pNode = p->vMapObjs->pArray[i];
205 printf(
"Nodes = %6d. Total %d-feasible cuts = %10d. Per node = %.1f. ",
206 p->nNodes, p->nVarsMax, nCuts, ((
float)nCuts)/p->nNodes );
244 if ( pNode->
pRepr == NULL )
246 for ( pTemp = pNode->
pNextE; pTemp; pTemp = pTemp->
pNextE )
258 pCut->
uTruth = 0xAAAAAAAA;
297 Map_Cut_t * pTemp, * pPrev, * pCut, * pCut2;
301 pPrev = pNode->
pCuts;
305 for ( pTemp = pNode->
pCuts->
pNext; pTemp != pCut; pTemp = pTemp->
pNext )
308 for ( i = 0; i < pTemp->
nLeaves; i++ )
310 for ( k = 0; k < pCut->
nLeaves; k++ )
349 Map_Cut_t * pListNew, ** ppListNew, * pLists[7] = { NULL };
350 Map_Cut_t * pCut, * pPrev, * pTemp1, * pTemp2;
352 Map_Cut_t ** ppArray1, ** ppArray2, ** ppArray3;
353 int nCuts1, nCuts2, nCuts3, k, fComp3;
355 ppArray1 = pTable->
pCuts1;
356 ppArray2 = pTable->
pCuts2;
360 if ( nCuts1 > nCuts2 )
382 for ( i = 0; i < nCuts1; i++ )
384 for ( k = 0; k <= i; k++ )
386 pTemp1 = ppArray1[i];
387 pTemp2 = ppArray2[k];
389 if ( pTemp1->
nLeaves == p->nVarsMax && pTemp2->
nLeaves == p->nVarsMax )
412 pLists[(
int)pCut->
nLeaves] = pCut;
418 for ( k = 0; k < i; k++ )
420 pTemp1 = ppArray1[k];
421 pTemp2 = ppArray2[i];
423 if ( pTemp1->
nLeaves == p->nVarsMax && pTemp2->
nLeaves == p->nVarsMax )
446 pLists[(
int)pCut->
nLeaves] = pCut;
454 for ( i = nCuts1; i < nCuts2; i++ )
455 for ( k = 0; k < nCuts1; k++ )
457 pTemp1 = ppArray1[k];
458 pTemp2 = ppArray2[i];
460 if ( pTemp1->
nLeaves == p->nVarsMax && pTemp2->
nLeaves == p->nVarsMax )
483 pLists[(
int)pCut->
nLeaves] = pCut;
492 ppListNew = &pListNew;
493 for ( i = 1; i <= p->nVarsMax; i++ )
495 if ( pLists[i] == NULL )
498 for ( pPrev = pLists[i], pCut = pPrev->
pNext; pCut;
499 pPrev = pCut, pCut = pCut->
pNext );
501 *ppListNew = pLists[i];
502 ppListNew = &pPrev->
pNext;
526 Map_Cut_t * pListNew, ** ppListNew, * pLists[7] = { NULL };
527 Map_Cut_t * pCut, * pPrev, * pTemp1, * pTemp2;
534 for ( pTemp1 = pList1; pTemp1; pTemp1 = pTemp1->
pNext )
535 for ( pTemp2 = pList2; pTemp2; pTemp2 = pTemp2->
pNext )
550 pLists[(
int)pCut->
nLeaves] = pCut;
559 ppListNew = &pListNew;
560 for ( i = 1; i <= p->nVarsMax; i++ )
562 if ( pLists[i] == NULL )
565 for ( pPrev = pLists[i], pCut = pPrev->
pNext; pCut;
566 pPrev = pCut, pCut = pCut->
pNext );
568 *ppListNew = pLists[i];
569 ppListNew = &pPrev->
pNext;
592 int nTotal, i, k, min, fMismatch;
595 if ( pCut1->
nLeaves == nNodesMax )
597 if ( pCut2->
nLeaves == nNodesMax )
600 for ( i = 0; i < nNodesMax; i++ )
604 for ( i = 0; i < nNodesMax; i++ )
608 else if ( pCut2->
nLeaves == nNodesMax - 1 )
612 for ( i = 0; i < nNodesMax; i++ )
615 if ( fMismatch == 1 )
620 for ( i = 0; i < nNodesMax; i++ )
625 else if ( pCut1->
nLeaves == nNodesMax - 1 && pCut2->
nLeaves == nNodesMax )
629 for ( i = 0; i < nNodesMax; i++ )
632 if ( fMismatch == 1 )
637 for ( i = 0; i < nNodesMax; i++ )
644 for ( i = 0; i < pCut2->
nLeaves; i++ )
647 for ( k = 0; k < pCut1->
nLeaves; k++ )
650 if ( k < pCut1->nLeaves )
653 if ( nTotal == nNodesMax )
655 ppNodes[nTotal++] = pCut2->
ppLeaves[i];
660 for ( k = 0; k < pCut1->
nLeaves; k++ )
664 for ( i = 0; i < nTotal - 1; i++ )
667 for ( k = i+1; k <
nTotal; k++ )
669 if ( ppNodes[k]->Num < ppNodes[min]->Num )
671 pNodeTemp = ppNodes[i];
672 ppNodes[i] = ppNodes[min];
673 ppNodes[min] = pNodeTemp;
700 pList2->
pNext = NULL;
721 for ( pTemp = pList; pTemp; pTemp = pTemp->
pNext )
723 for ( i = 0; i < nNodes; i++ )
724 if ( pTemp->
ppLeaves[i] != ppNodes[i] )
748 for ( Counter = 0, pTemp = pRoot->
pCuts; pTemp; pTemp = pTemp->
pNext, Counter++ )
750 printf(
"%2d : ", Counter + 1 );
770 for ( Counter = 0, pTemp = pRoot->
pCuts; pTemp; pTemp = pTemp->
pNext, Counter++ )
772 printf(
"%2d : ", Counter + 1 );
791 printf(
"(%3d) {", pRoot->
Num );
792 for ( i = 0; i < pMan->nVarsMax; i++ )
869 for ( i = 0; i < nNodes; i++ )
893 for ( b = Key; p->
pBins[b]; b = (b+1) % p->
nBins )
898 for ( i = 0; i < nNodes; i++ )
899 if ( pCut->
ppLeaves[i] != ppNodes[i] )
934 for ( i = 0; i < nNodes; i++ )
938 p->
pBins[Place] = pCut;
959 for ( i = 0; i < p->
nCuts; i++ )
982 if ( (*pC1)->nLeaves < (*pC2)->nLeaves )
984 if ( (*pC1)->nLeaves > (*pC2)->nLeaves )
1040 for ( i = 0; pList; pList = pList->
pNext, i++ )
1061 ppListNew = &pListNew;
1062 for ( i = 0; i < nCuts; i++ )
1065 *ppListNew = pArray[i];
1066 ppListNew = &pArray[i]->
pNext;
1088 static unsigned ** pPerms53 = NULL;
1089 static unsigned ** pPerms54 = NULL;
1091 unsigned uPhase, uTruth, uTruth0, uTruth1;
1094 if ( pPerms53 == NULL )
1102 uTruth0 = pTemp0->
uTruth;
1107 for ( i = 0; i < (int)pTemp0->
nLeaves; i++ )
1109 for ( k = 0; k < pCut->
nLeaves; k++ )
1117 if ( uPhase == 31-16 )
1118 uTruth0 = pTemp0->
uTruth;
1119 else if ( uPhase == 31-8 )
1120 uTruth0 = pPerms54[pTemp0->
uTruth & 0xFFFF][0];
1121 else if ( uPhase == 31-4 )
1122 uTruth0 = pPerms54[pTemp0->
uTruth & 0xFFFF][1];
1123 else if ( uPhase == 31-2 )
1124 uTruth0 = pPerms54[pTemp0->
uTruth & 0xFFFF][2];
1125 else if ( uPhase == 31-1 )
1126 uTruth0 = pPerms54[pTemp0->
uTruth & 0xFFFF][3];
1131 uTruth0 = pPerms53[pTemp0->
uTruth & 0xFF][uPhase];
1133 uTruth0 = fComp0? ~uTruth0: uTruth0;
1137 uTruth1 = pTemp1->
uTruth;
1142 for ( i = 0; i < (int)pTemp1->
nLeaves; i++ )
1144 for ( k = 0; k < pCut->
nLeaves; k++ )
1152 if ( uPhase == 31-16 )
1153 uTruth1 = pTemp1->
uTruth;
1154 else if ( uPhase == 31-8 )
1155 uTruth1 = pPerms54[pTemp1->
uTruth & 0xFFFF][0];
1156 else if ( uPhase == 31-4 )
1157 uTruth1 = pPerms54[pTemp1->
uTruth & 0xFFFF][1];
1158 else if ( uPhase == 31-2 )
1159 uTruth1 = pPerms54[pTemp1->
uTruth & 0xFFFF][2];
1160 else if ( uPhase == 31-1 )
1161 uTruth1 = pPerms54[pTemp1->
uTruth & 0xFFFF][3];
1166 uTruth1 = pPerms53[pTemp1->
uTruth & 0xFF][uPhase];
1168 uTruth1 = fComp1? ~uTruth1: uTruth1;
1169 uTruth = uTruth0 & uTruth1;
static int Abc_PrimeCudd(unsigned int p)
static Map_Cut_t * Map_CutSortCuts(Map_Man_t *pMan, Map_CutTable_t *p, Map_Cut_t *pList)
int Map_NodeIsAnd(Map_Node_t *p)
int Map_MappingCountAllCuts(Map_Man_t *pMan)
FUNCTION DEFINITIONS ///.
static Map_Cut_t * Map_CutCompute(Map_Man_t *p, Map_CutTable_t *pTable, Map_Node_t *pNode)
Map_Cut_t * Map_CutAlloc(Map_Man_t *p)
DECLARATIONS ///.
#define Map_ListForEachCutSafe(pList, pCut, pCut2)
static int Map_CutMergeTwo(Map_Cut_t *pCut1, Map_Cut_t *pCut2, Map_Node_t *ppNodes[], int nNodesMax)
static unsigned Map_CutComputeTruth(Map_Man_t *p, Map_Cut_t *pCut, Map_Cut_t *pTemp0, Map_Cut_t *pTemp1, int fComp0, int fComp1)
static Map_CutTable_t * Map_CutTableStart(Map_Man_t *pMan)
int Map_NodeIsBuf(Map_Node_t *p)
static void Map_CutTableRestart(Map_CutTable_t *p)
#define MAP_CUTS_MAX_COMPUTE
DECLARATIONS ///.
int Map_CutSortCutsCompare(Map_Cut_t **pC1, Map_Cut_t **pC2)
static int Map_CutTableLookup(Map_CutTable_t *p, Map_Node_t *ppNodes[], int nNodes)
int Map_NodeComparePhase(Map_Node_t *p1, Map_Node_t *p2)
#define ABC_ALLOC(type, num)
static abctime Abc_Clock()
#define Map_CutNotCond(p, c)
static void Map_CutListPrint(Map_Man_t *pMan, Map_Node_t *pRoot)
static int Map_CutList2Array(Map_Cut_t **pArray, Map_Cut_t *pList)
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
for(p=first;p->value< newval;p=p->next)
static Map_Cut_t * Map_CutUnionLists(Map_Cut_t *pList1, Map_Cut_t *pList2)
static void Map_CutListPrint2(Map_Man_t *pMan, Map_Node_t *pRoot)
static void Map_CutFilter(Map_Man_t *p, Map_Node_t *pNode)
#define ABC_NAMESPACE_IMPL_END
int Map_NodeIsVar(Map_Node_t *p)
static void Map_CutPrint_(Map_Man_t *pMan, Map_Cut_t *pCut, Map_Node_t *pRoot)
Map_Cut_t * Map_CutMergeLists2(Map_Man_t *p, Map_CutTable_t *pTable, Map_Cut_t *pList1, Map_Cut_t *pList2, int fComp1, int fComp2)
static Map_Cut_t * Map_CutTableConsider(Map_Man_t *pMan, Map_CutTable_t *p, Map_Node_t *ppNodes[], int nNodes)
static Map_Cut_t * Map_CutArray2List(Map_Cut_t **pArray, int nCuts)
#define Map_ListForEachCut(pList, pCut)
#define ABC_NAMESPACE_IMPL_START
typedefABC_NAMESPACE_HEADER_START struct Map_ManStruct_t_ Map_Man_t
INCLUDES ///.
static unsigned Map_CutTableHash(Map_Node_t *ppNodes[], int nNodes)
void Map_MappingCuts(Map_Man_t *p)
GLOBAL VARIABLES ///.
static void Map_CutTableStop(Map_CutTable_t *p)
static int Map_CutBelongsToList(Map_Cut_t *pList, Map_Node_t *ppNodes[], int nNodes)
static int s_HashPrimes[10]
void Map_MappingCutsInput(Map_Man_t *p, Map_Node_t *pNode)
static Map_Cut_t * Map_CutMergeLists(Map_Man_t *p, Map_CutTable_t *pTable, Map_Cut_t *pList1, Map_Cut_t *pList2, int fComp1, int fComp2)
int nTotal
DECLARATIONS ///.
void Map_CutFree(Map_Man_t *p, Map_Cut_t *pCut)