130 unsigned uTruths[4] = { 0xAAAA, 0xCCCC, 0xF0F0, 0xFF00 };
144 for ( i = 0; i < 4; i++ )
146 p->pObjs[i].fTerm = 1;
147 p->pObjs[i].Num = uTruths[i];
196 return s_DarLib->pMap[uTruth & 0xffff];
213 int Visits[222] = {0};
216 for ( i = k = 0; i < (1<<16); i++ )
220 pCanons[k++] = ((i<<16) | i);
246 pObj->
Num = 0xFFFF & (fCompl0? ~pFan0->
Num : pFan0->
Num) & (fCompl1? ~pFan1->
Num : pFan1->
Num);
262 if ( pObj->
fTerm || (
int)pObj->
Num == Class )
268 p->pNodes[Class][ p->nNodes[Class]++ ] = pObj-p->pObjs;
288 int nNodesTotal, uTruth, Class, Out, i, k;
289 assert( p->iObj == p->nObjs );
292 for ( i = 0; i < 222; i++ )
293 p->nSubgr[i] = p->nNodes[i] = 0;
298 Class = p->pMap[uTruth];
305 for ( i = 0; i < 222; i++ )
307 p->pSubgr[i] = p->pSubgrMem + p->nSubgrTotal;
308 p->pSubgr0[i] = p->pSubgr0Mem + p->nSubgrTotal;
309 p->nSubgrTotal += p->nSubgr[i];
318 Class = p->pMap[uTruth];
319 p->pSubgr[Class][ p->nSubgr[Class]++ ] = Out;
327 for ( i = 0; i < 222; i++ )
329 p->pPrios[i] = p->pPriosMem + p->nSubgrTotal;
330 p->nSubgrTotal += p->nSubgr[i];
331 for ( k = 0; k < p->nSubgr[i]; k++ )
340 for ( i = 0; i < 222; i++ )
342 p->pPlace[i] = p->pPlaceMem + p->nSubgrTotal;
343 p->nSubgrTotal += p->nSubgr[i];
344 for ( k = 0; k < p->nSubgr[i]; k++ )
353 for ( i = 0; i < 222; i++ )
355 p->pScore[i] = p->pScoreMem + p->nSubgrTotal;
356 p->nSubgrTotal += p->nSubgr[i];
357 for ( k = 0; k < p->nSubgr[i]; k++ )
369 for ( i = 0; i < 222; i++ )
371 p->pPrios[i] = p->pPriosMem + p->nSubgrTotal;
372 p->nSubgrTotal += p->nSubgr[i];
373 for ( k = 0; k < p->nSubgr[i]; k++ )
382 for ( i = 0; i < p->iObj; i++ )
385 for ( i = 0; i < 222; i++ )
386 for ( k = 0; k < p->nSubgr[i]; k++ )
390 for ( i = 0; i < 222; i++ )
391 p->nNodesTotal += p->nNodes[i];
393 p->pNodesMem =
ABC_ALLOC(
int, p->nNodesTotal );
394 p->pNodes0Mem =
ABC_ALLOC(
int, p->nNodesTotal );
396 for ( i = 0; i < 222; i++ )
398 p->pNodes[i] = p->pNodesMem + p->nNodesTotal;
399 p->pNodes0[i] = p->pNodes0Mem + p->nNodesTotal;
400 p->nNodesTotal += p->nNodes[i];
404 for ( i = 0; i < p->iObj; i++ )
408 for ( i = 0; i < 222; i++ )
410 for ( k = 0; k < p->nSubgr[i]; k++ )
412 nNodesTotal += p->nNodes[i];
415 assert( nNodesTotal == p->nNodesTotal );
417 for ( i = 0; i < 4; i++ )
434 if ( p->nDatas == nDatas )
456 if ( pObj->
fTerm || (
int)pObj->
Num == Class )
462 p->pNodes0[Class][ p->nNodes0[Class]++ ] = pObj-p->pObjs;
481 int i, k, nNodes0Total;
482 if ( p->nSubgraphs == nSubgraphs )
493 for ( i = 0; i < 222; i++ )
497 p->nSubgr0[i] = p->nSubgr[i];
499 p->nSubgr0[i] =
Abc_MinInt( p->nSubgr[i], nSubgraphs );
500 p->nSubgr0Total += p->nSubgr0[i];
501 for ( k = 0; k < p->nSubgr0[i]; k++ )
502 p->pSubgr0[i][k] = p->pSubgr[i][ p->pPrios[i][k] ];
507 for ( i = 0; i < 222; i++ )
510 for ( i = 0; i < p->iObj; i++ )
516 for ( i = 0; i < 222; i++ )
518 for ( k = 0; k < p->nSubgr0[i]; k++ )
520 p->nNodes0Total += p->nNodes0[i];
521 p->nNodes0Max =
Abc_MaxInt( p->nNodes0Max, p->nNodes0[i] );
525 for ( i = 0; i < 222; i++ )
528 for ( i = 0; i < p->iObj; i++ )
532 for ( i = 0; i < 222; i++ )
534 for ( k = 0; k < p->nSubgr0[i]; k++ )
536 nNodes0Total += p->nNodes0[i];
538 assert( nNodes0Total == p->nNodes0Total );
540 for ( i = 0; i < 4; i++ )
571 for ( i = 0; i < vObjs->nSize; i += 2 )
572 Dar_LibAddNode( p, vObjs->pArray[i] >> 1, vObjs->pArray[i+1] >> 1,
573 vObjs->pArray[i] & 1, vObjs->pArray[i+1] & 1 );
635 int * pPrios =
s_DarLib->pPrios[Class];
636 int * pPlace =
s_DarLib->pPlace[Class];
637 int * pScore =
s_DarLib->pScore[Class];
639 assert( Class >= 0 && Class < 222 );
640 assert( Out >= 0 && Out < s_DarLib->nSubgr[Class] );
641 assert( pPlace[pPrios[Out]] == Out );
645 while ( pPlace[Out] > 0 && pScore[Out] > pScore[ pPrios[pPlace[Out]-1] ] )
648 Out2 = pPrios[pPlace[Out]-1];
652 pPrios[pPlace[Out]] = Out;
653 pPrios[pPlace[Out2]] = Out2;
670 int i, k, Out, Out2,
Counter = 0, Printed = 0;
671 printf(
"\nOutput priorities (total = %d):\n",
s_DarLib->nSubgrTotal );
672 for ( i = 0; i < 222; i++ )
675 for ( k = 0; k <
s_DarLib->nSubgr[i]; k++ )
678 Out2 = k == 0 ? Out :
s_DarLib->pPrios[i][k-1];
681 printf(
"%d, ", Out );
683 if ( ++Counter == 15 )
720 if ( pFanin == NULL )
725 pFanin =
Aig_NotCond(pFanin, ((uPhase >> i) & 1) );
729 if ( p->pPars->fPower )
756 for ( i = 0; i < nLeaves; i++ )
761 for ( i = 0; i < nLeaves; i++ )
781 printf(
"%c",
'a' + (
int)(pObj -
s_DarLib->pObjs) );
812 for ( i = 0; i <
s_DarLib->nNodes0[Class]; i++ )
829 if ( pData0->
pFunc == NULL || pData1->
pFunc == NULL )
843 if ( p->pPars->fPower )
866 float Power0, Power1;
869 *pPower = (float)0.0;
871 if ( pData->
TravId == Out )
877 *pPower = pData->
dProb;
881 if ( pData->
Level > Required )
886 *pPower = pData->
dProb;
892 if ( Area > nNodesSaved )
895 if ( Area > nNodesSaved )
903 *pPower = Power0 + 2.0 * pData0->
dProb * (1.0 - pData0->
dProb) +
904 Power1 + 2.0 * pData1->
dProb * (1.0 - pData1->
dProb);
923 float PowerSaved, PowerAdded;
925 int Out, k, Class, nNodesSaved, nNodesAdded, nNodesGained;
938 p->nTotalSubgs +=
s_DarLib->nSubgr0[Class];
939 p->ClassSubgs[Class] +=
s_DarLib->nSubgr0[Class];
940 for ( Out = 0; Out <
s_DarLib->nSubgr0[Class]; Out++ )
945 nNodesAdded =
Dar_LibEval_rec( pObj, Out, nNodesSaved - !p->pPars->fUseZeros, Required, p->pPars->fPower? &PowerAdded : NULL );
946 nNodesGained = nNodesSaved - nNodesAdded;
947 if ( p->pPars->fPower && PowerSaved < PowerAdded )
949 if ( fTraining && nNodesGained >= 0 )
951 if ( nNodesGained < 0 || (nNodesGained == 0 && !p->pPars->fUseZeros) )
953 if ( nNodesGained < p->GainBest ||
954 (nNodesGained == p->GainBest &&
s_DarLib->pDatas[pObj->
Num].Level >= p->LevelBest) )
958 for ( k = 0; k < (int)pCut->
nLeaves; k++ )
960 p->OutBest =
s_DarLib->pSubgr0[Class][Out];
963 p->GainBest = nNodesGained;
964 p->ClassBest = Class;
965 assert( p->LevelBest <= Required );
966 *pnMffcSize = nNodesSaved;
969 p->ClassTimes[Class] += clk;
988 pObj->
Num = (*pCounter)++;
1010 return pData->
pFunc;
1017 return pData->
pFunc;
1034 for ( i = 0; i <
Vec_PtrSize(p->vLeavesBest); i++ )
1063 uPhase =
s_DarLib->pPhases[uTruth];
1092 int iFanin0, iFanin1, i, iLit;
1093 for ( i = 0; i <
s_DarLib->nNodes0[Class]; i++ )
1110 if ( pData0->
iGunc == -1 || pData1->
iGunc == -1 )
1115 if ( iFanin0 == 0 || iFanin1 == 0 || iFanin0 ==
Abc_LitNot(iFanin1) )
1117 else if ( iFanin0 == 1 || iFanin0 == iFanin1 )
1119 else if ( iFanin1 == 1 )
1127 pData->
iGunc = iLit;
1128 if ( pData->
iGunc >= 0 )
1154 if ( pData->
TravId == Out )
1160 if ( pData->
iGunc >= 0 )
1187 int p_OutNumBest = -1;
1188 int p_LevelBest = 1000000;
1189 int p_GainBest = -1000000;
1190 int p_ClassBest = -1;
1193 int Out, k, Class, nNodesSaved, nNodesAdded, nNodesGained;
1196 assert( (uTruth >> 16) == 0 );
1209 for ( Out = 0; Out <
s_DarLib->nSubgr0[Class]; Out++ )
1214 nNodesGained = nNodesSaved - nNodesAdded;
1217 if (
s_DarLib->pDatas[pObj->
Num].Level > p_LevelBest ||
1218 (
s_DarLib->pDatas[pObj->
Num].Level == p_LevelBest && nNodesGained <= p_GainBest) )
1223 if ( nNodesGained < p_GainBest ||
1224 (nNodesGained == p_GainBest &&
s_DarLib->pDatas[pObj->
Num].Level >= p_LevelBest) )
1231 p_OutBest =
s_DarLib->pSubgr0[Class][Out];
1234 p_GainBest = nNodesGained;
1235 p_ClassBest = Class;
1241 assert( p_OutBest != -1 );
1260 pObj->
Num = (*pCounter)++;
1281 int iFanin0, iFanin1;
1283 if ( pData->
iGunc >= 0 )
1284 return pData->
iGunc;
1294 return pData->
iGunc;
1331 int OutBest =
Dar2_LibEval( p, vCutLits, uTruth, fKeepLevel, vLeavesBest2 );
void Dar2_LibEvalAssignNums(Gia_Man_t *p, int Class)
typedefABC_NAMESPACE_IMPL_START struct Dar_Lib_t_ Dar_Lib_t
DECLARATIONS ///.
void Dar_LibObjPrint_rec(Dar_LibObj_t *pObj)
int Aig_NodeMffcLabel(Aig_Man_t *p, Aig_Obj_t *pNode, float *pPower)
Vec_Int_t * Dar_LibReadNodes()
void Dar_LibSetup(Dar_Lib_t *p, Vec_Int_t *vOuts, Vec_Int_t *vPrios)
void Dar_LibStart()
MACRO DEFINITIONS ///.
Aig_Obj_t * Dar_LibBuildBest_rec(Dar_Man_t *p, Dar_LibObj_t *pObj)
void Dar_LibCreateData(Dar_Lib_t *p, int nDatas)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
void Dar_Truth4VarNPN(unsigned short **puCanons, char **puPhases, char **puPerms, unsigned char **puMap)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
static Gia_Obj_t * Gia_Regular(Gia_Obj_t *p)
static int Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
static Gia_Obj_t * Gia_ObjFromLit(Gia_Man_t *p, int iLit)
static Dar_LibObj_t * Dar_LibObj(Dar_Lib_t *p, int Id)
unsigned short * puCanons
Vec_Int_t * Dar_LibReadOuts()
static int Aig_IsComplement(Aig_Obj_t *p)
int Dar2_LibBuildBest_rec(Gia_Man_t *p, Dar_LibObj_t *pObj)
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
#define ABC_ALLOC(type, num)
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
void Dar_LibSetup0_rec(Dar_Lib_t *p, Dar_LibObj_t *pObj, int Class, int fCollect)
static abctime Abc_Clock()
static int Abc_MaxInt(int a, int b)
static int Vec_PtrSize(Vec_Ptr_t *p)
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
static int Abc_LitNotCond(int Lit, int c)
for(p=first;p->value< newval;p=p->next)
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
void Dar_LibDumpPriorities()
void Dar_LibReturnCanonicals(unsigned *pCanons)
static int Abc_MinInt(int a, int b)
static int Gia_ObjLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
typedefABC_NAMESPACE_HEADER_START struct Dar_Man_t_ Dar_Man_t
INCLUDES ///.
int Dar_LibEval_rec(Dar_LibObj_t *pObj, int Out, int nNodesSaved, int Required, float *pPower)
void Dar_LibSetup_rec(Dar_Lib_t *p, Dar_LibObj_t *pObj, int Class, int fCollect)
int Dar_LibCutMarkMffc(Aig_Man_t *p, Aig_Obj_t *pRoot, int nLeaves, float *pPower)
void Dar_LibAddNode(Dar_Lib_t *p, int Id0, int Id1, int fCompl0, int fCompl1)
void Gia_ObjSetPhase(Gia_Man_t *p, Gia_Obj_t *pObj)
static void Gia_ObjSetAndLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
static int Vec_IntEntry(Vec_Int_t *p, int i)
void Dar_LibEval(Dar_Man_t *p, Aig_Obj_t *pRoot, Dar_Cut_t *pCut, int Required, int *pnMffcSize)
int Dar_LibReturnClass(unsigned uTruth)
#define ABC_NAMESPACE_IMPL_END
int Dar2_LibEval_rec(Dar_LibObj_t *pObj, int Out)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
void Dar_LibBuildClear_rec(Dar_LibObj_t *pObj, int *pCounter)
Aig_Obj_t * Aig_TableLookupTwo(Aig_Man_t *p, Aig_Obj_t *pFanin0, Aig_Obj_t *pFanin1)
void Dar_LibIncrementScore(int Class, int Out, int Gain)
int Dar_LibEvalBuild(Gia_Man_t *p, Vec_Int_t *vCutLits, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest2)
DECLARATIONS ///.
int Dar_LibCutMatch(Dar_Man_t *p, Dar_Cut_t *pCut)
char ** Dar_Permutations(int n)
#define ABC_NAMESPACE_IMPL_START
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
static int Abc_LitNot(int Lit)
static int Vec_IntSize(Vec_Int_t *p)
int Gia_ManHashLookup(Gia_Man_t *p, Gia_Obj_t *p0, Gia_Obj_t *p1)
void Dar_LibEvalAssignNums(Dar_Man_t *p, int Class, Aig_Obj_t *pRoot)
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
static Dar_Lib_t * s_DarLib
static int Abc_Lit2Var(int Lit)
static float Abc_Int2Float(int Num)
static int Aig_ObjId(Aig_Obj_t *pObj)
static void Vec_PtrClear(Vec_Ptr_t *p)
int Dar2_LibEval(Gia_Man_t *p, Vec_Int_t *vCutLits, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest2)
int Dar2_LibCutMatch(Gia_Man_t *p, Vec_Int_t *vCutLits, unsigned uTruth)
void Dar_LibPrepare(int nSubgraphs)
Dar_Lib_t * Dar_LibAlloc(int nObjs)
FUNCTION DEFINITIONS ///.
static int Dar_LibObjTruth(Dar_LibObj_t *pObj)
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
static void Vec_IntFree(Vec_Int_t *p)
Vec_Int_t * Dar_LibReadPrios()
static void Vec_IntClear(Vec_Int_t *p)
void Dar_LibFree(Dar_Lib_t *p)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
void Dar2_LibBuildClear_rec(Dar_LibObj_t *pObj, int *pCounter)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
int Dar2_LibBuildBest(Gia_Man_t *p, Vec_Int_t *vLeavesBest2, int OutBest)
Aig_Obj_t * Dar_LibBuildBest(Dar_Man_t *p)
Dar_Lib_t * Dar_LibRead()