80 p->pHashC = Hsh_VecManStart( 1000 );
81 p->pHashM = Hsh_VecManStart( 1000 );
82 p->vQue = Vec_QueAlloc( 1000 );
83 p->vCounts = Vec_FltAlloc( 1000 );
84 p->vCoefs = Vec_IntAlloc( 1000 );
85 p->vTempC[0] = Vec_IntAlloc( 100 );
86 p->vTempC[1] = Vec_IntAlloc( 100 );
87 p->vTempM[0] = Vec_IntAlloc( 100 );
88 p->vTempM[1] = Vec_IntAlloc( 100 );
89 p->vTempM[2] = Vec_IntAlloc( 100 );
90 p->vTempM[3] = Vec_IntAlloc( 100 );
91 p->vOrder = vOrder ? Vec_IntDup(vOrder) : Vec_IntStartNatural( Gia_ManObjNum(pGia) );
92 assert( Vec_IntSize(
p->vOrder) == Gia_ManObjNum(pGia) );
93 Vec_QueSetPriority(
p->vQue, Vec_FltArrayP(
p->vCounts) );
95 Hsh_VecManAdd(
p->pHashC,
p->vTempC[0] );
96 Hsh_VecManAdd(
p->pHashM,
p->vTempM[0] );
97 Vec_FltPush(
p->vCounts, 0 );
98 Vec_IntPush(
p->vCoefs, 0 );
103 Hsh_VecManStop(
p->pHashC );
104 Hsh_VecManStop(
p->pHashM );
105 Vec_QueFree(
p->vQue );
106 Vec_FltFree(
p->vCounts );
107 Vec_IntFree(
p->vCoefs );
108 Vec_IntFree(
p->vTempC[0] );
109 Vec_IntFree(
p->vTempC[1] );
110 Vec_IntFree(
p->vTempM[0] );
111 Vec_IntFree(
p->vTempM[1] );
112 Vec_IntFree(
p->vTempM[2] );
113 Vec_IntFree(
p->vTempM[3] );
114 Vec_IntFree(
p->vOrder );
119 if ( pData0[0] < pData1[0] )
return -1;
120 if ( pData0[0] > pData1[0] )
return 1;
121 if ( pData0[1] < pData1[1] )
return -1;
122 if ( pData0[1] > pData1[1] )
return 1;
128 int i, k, Entry, iMono, iConst;
130 Vec_Int_t * vPairs = Vec_IntAlloc( 100 );
135 vArray = Hsh_VecReadEntry(
p->pHashC, iConst );
136 Vec_IntPush( vPairs, Vec_IntEntry(vArray, 0) );
137 vArray = Hsh_VecReadEntry(
p->pHashM, iMono );
138 Vec_IntPush( vPairs, Vec_IntSize(vArray) ? Vec_IntEntry(vArray, 0) : 0 );
139 Vec_IntPushTwo( vPairs, iConst, iMono );
142 qsort( Vec_IntArray(vPairs), (
size_t)(Vec_IntSize(vPairs)/4), 16, (
int (*)(
const void *,
const void *))
Pln_ManCompare3 );
149 printf(
"%-6d : ", i/4 );
150 vArray = Hsh_VecReadEntry(
p->pHashC, iConst );
152 printf(
"%s%d", Entry < 0 ?
"-" :
"+", (1 << (Abc_AbsInt(Entry)-1)) );
153 vArray = Hsh_VecReadEntry(
p->pHashM, iMono );
155 printf(
" * %d", Entry );
158 printf(
"HashC = %d. HashM = %d. Total = %d. Used = %d. ", Hsh_VecSize(
p->pHashC), Hsh_VecSize(
p->pHashM),
p->nBuilds, Vec_IntSize(vPairs)/4 );
159 Vec_IntFree( vPairs );
176 Vec_IntClear( vVec1 );
178 Vec_IntPush( vVec1, Entry > 0 ? -Entry-1 : -Entry+1 );
192static inline void Gia_PolynMergeConstOne(
Vec_Int_t * vConst,
int New )
201 Vec_IntDrop( vConst, i );
202 Gia_PolynMergeConstOne( vConst, New > 0 ? New + 1 : New - 1 );
205 if ( Abc_AbsInt(Old) == Abc_AbsInt(New) )
207 Vec_IntDrop( vConst, i );
210 if ( Old + New == 1 || Old + New == -1 )
212 int Value = Abc_MinInt( Abc_AbsInt(Old), Abc_AbsInt(New) );
213 Vec_IntDrop( vConst, i );
214 Gia_PolynMergeConstOne( vConst, (Old + New == 1) ? Value : -Value );
218 Vec_IntPushUniqueOrder( vConst, New );
223 Vec_Int_t * vConstAdd = Hsh_VecReadEntry(
p->pHashC, iConstAdd );
226 Gia_PolynMergeConstOne( vConst, New );
227 vConstAdd = Hsh_VecReadEntry(
p->pHashC, iConstAdd );
232 int iConst, iConstNew, iMono = vTempM ? Hsh_VecManAdd(
p->pHashM, vTempM) : 0;
234 if ( iMono == Vec_IntSize(
p->vCoefs) )
236 iConst = Hsh_VecManAdd(
p->pHashC, vTempC );
237 Vec_IntPush(
p->vCoefs, iConst );
239 Vec_FltPush(
p->vCounts, (
float)Vec_IntEntry(
p->vOrder, Vec_IntEntryLast(vTempM)) );
240 Vec_QuePush(
p->vQue, iMono );
247 iConst = Vec_IntEntry(
p->vCoefs, iMono );
249 Gia_PolynMergeConst( vTempC,
p, iConst );
250 iConstNew = Hsh_VecManAdd(
p->pHashC, vTempC );
251 Vec_IntWriteEntry(
p->vCoefs, iMono, iConstNew );
252 if ( iConst && !iConstNew )
254 else if ( !iConst && iConstNew )
263 int k, iConst, iDriver;
265 assert( Vec_IntSize(
p->vCoefs) == Hsh_VecSize(
p->pHashM) );
266 vArray = Hsh_VecReadEntry(
p->pHashM, iMono );
267 iDriver = Vec_IntEntryLast( vArray );
268 pObj = Gia_ManObj(
p->pGia, iDriver );
269 if ( !Gia_ObjIsAnd(pObj) )
271 assert( !Gia_ObjIsMux(
p->pGia, pObj) );
273 iConst = Vec_IntEntry(
p->vCoefs, iMono );
276 Vec_IntWriteEntry(
p->vCoefs, iMono, 0 );
279 iFan0 = Gia_ObjFaninId0p(
p->pGia, pObj);
280 iFan1 = Gia_ObjFaninId1p(
p->pGia, pObj);
281 for ( k = 0; k < 4; k++ )
283 Vec_IntClear(
p->vTempM[k] );
284 Vec_IntAppend(
p->vTempM[k], vArray );
285 Vec_IntPop(
p->vTempM[k] );
286 if ( k == 1 || k == 3 )
287 Vec_IntPushUniqueOrderCost(
p->vTempM[k], iFan0,
p->vOrder );
289 if ( k == 2 || k == 3 )
290 Vec_IntPushUniqueOrderCost(
p->vTempM[k], iFan1,
p->vOrder );
294 vConst = Hsh_VecReadEntry(
p->pHashC, iConst );
296 if ( !Gia_ObjIsXor(pObj) )
297 for ( k = 0; k < 2; k++ )
298 Vec_IntAppendMinus(
p->vTempC[k], vConst, k );
300 if ( Gia_ObjIsXor(pObj) )
302 vConst = Hsh_VecReadEntry(
p->pHashC, iConst );
303 Vec_IntAppendMinus(
p->vTempC[0], vConst, 0 );
304 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[1] );
306 vConst = Hsh_VecReadEntry(
p->pHashC, iConst );
307 Vec_IntAppendMinus(
p->vTempC[0], vConst, 0 );
308 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[2] );
312 vConst = Hsh_VecReadEntry(
p->pHashC, iConst );
313 Vec_IntAppendMinus2x(
p->vTempC[0], vConst );
314 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[3] );
317 else if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
319 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[0] );
320 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[1] );
321 vConst = Hsh_VecReadEntry(
p->pHashC, iConst );
322 for ( k = 0; k < 2; k++ )
323 Vec_IntAppendMinus(
p->vTempC[k], vConst, k );
324 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[2] );
325 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[3] );
327 else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
329 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[2] );
330 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[3] );
332 else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
334 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[1] );
335 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[3] );
338 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[3] );
344 Vec_Bit_t * vPres = Vec_BitStart( Gia_ManObjNum(pGia) );
345 int i, iMono, iDriver, LevPrev, LevCur, Iter, Line = 0;
349 Vec_IntFill(
p->vTempC[0], 1, i+1 );
350 Vec_IntFill(
p->vTempC[1], 1, -i-1 );
352 iDriver = Gia_ObjFaninId0p( pGia, pObj );
353 Vec_IntFill(
p->vTempM[0], 1, iDriver );
355 if ( fSigned && i == Gia_ManCoNum(pGia)-1 )
357 if ( Gia_ObjFaninC0(pObj) )
359 Gia_PolynBuildAdd(
p,
p->vTempC[1], NULL );
360 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[0] );
363 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[0] );
367 if ( Gia_ObjFaninC0(pObj) )
369 Gia_PolynBuildAdd(
p,
p->vTempC[0], NULL );
370 Gia_PolynBuildAdd(
p,
p->vTempC[1],
p->vTempM[0] );
373 Gia_PolynBuildAdd(
p,
p->vTempC[0],
p->vTempM[0] );
377 for ( Iter = 0; ; Iter++ )
381 if ( Vec_QueSize(
p->vQue) == 0 )
383 iMono = Vec_QuePop(
p->vQue);
386 vTempM = Hsh_VecReadEntry(
p->pHashM, iMono );
388 LevCur = Vec_IntEntryLast(vTempM);
389 if ( !Gia_ObjIsAnd(Gia_ManObj(pGia, LevCur)) )
392 if ( LevPrev != LevCur )
394 if ( Vec_BitEntry( vPres, LevCur ) && fVerbose )
395 printf(
"Repeating entry %d\n", LevCur );
397 Vec_BitSetEntry( vPres, LevCur, 1 );
400 printf(
"Line%5d Iter%10d : Obj =%6d. Order =%6d. HashC =%6d. HashM =%10d. Total =%10d. Used =%10d.\n",
401 Line++, Iter, LevCur, Vec_IntEntry(
p->vOrder, LevCur), Hsh_VecSize(
p->pHashC), Hsh_VecSize(
p->pHashM),
p->nBuilds,
p->nUsed );
410 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
412 Vec_BitFree( vPres );
434 Hsh_VecManStop( pHashC );
435 Hsh_VecManStop( pHashM );
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Pln_ManStop(Pln_Man_t *p)
void Pln_ManPrintFinal(Pln_Man_t *p, int fVerbose, int fVeryVerbose)
void Gia_PolynBuildOne(Pln_Man_t *p, int iMono)
int Pln_ManCompare3(int *pData0, int *pData1)
typedefABC_NAMESPACE_IMPL_START struct Pln_Man_t_ Pln_Man_t
DECLARATIONS ///.
Pln_Man_t * Pln_ManAlloc(Gia_Man_t *pGia, Vec_Int_t *vOrder)
FUNCTION DEFINITIONS ///.
void Gia_PolynBuild(Gia_Man_t *pGia, Vec_Int_t *vOrder, int fSigned, int fVerbose, int fVeryVerbose)
void Gia_PolynBuild2(Gia_Man_t *pGia, int fSigned, int fVerbose, int fVeryVerbose)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define Gia_ManForEachCoReverse(p, pObj, i)
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
struct Hsh_VecMan_t_ Hsh_VecMan_t
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Que_t_ Vec_Que_t
INCLUDES ///.