ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
covBuild.c
Go to the documentation of this file.
1
20
21#include "cov.h"
22
24
25
29
33
45Abc_Obj_t * Abc_NtkCovDeriveCube( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pObj, Min_Cube_t * pCube, Vec_Int_t * vSupp, int fCompl )
46{
47 Vec_Int_t * vLits;
48 Abc_Obj_t * pNodeNew, * pFanin;
49 int i, iFanin, Lit;
50 // create empty cube
51 if ( pCube->nLits == 0 )
52 {
53 if ( fCompl )
54 return Abc_NtkCreateNodeConst0(pNtkNew);
55 return Abc_NtkCreateNodeConst1(pNtkNew);
56 }
57 // get the literals of this cube
58 vLits = Vec_IntAlloc( 10 );
59 Min_CubeGetLits( pCube, vLits );
60 assert( pCube->nLits == (unsigned)vLits->nSize );
61 // create special case when there is only one literal
62 if ( pCube->nLits == 1 )
63 {
64 iFanin = Vec_IntEntry(vLits,0);
65 pFanin = Abc_NtkObj( pObj->pNtk, Vec_IntEntry(vSupp, iFanin) );
66 Lit = Min_CubeGetVar(pCube, iFanin);
67 assert( Lit == 1 || Lit == 2 );
68 Vec_IntFree( vLits );
69 if ( (Lit == 1) ^ fCompl )// negative
70 return Abc_NtkCreateNodeInv( pNtkNew, pFanin->pCopy );
71 return pFanin->pCopy;
72 }
73 assert( pCube->nLits > 1 );
74 // create the AND cube
75 pNodeNew = Abc_NtkCreateNode( pNtkNew );
76 for ( i = 0; i < vLits->nSize; i++ )
77 {
78 iFanin = Vec_IntEntry(vLits,i);
79 pFanin = Abc_NtkObj( pObj->pNtk, Vec_IntEntry(vSupp, iFanin) );
80 Lit = Min_CubeGetVar(pCube, iFanin);
81 assert( Lit == 1 || Lit == 2 );
82 Vec_IntWriteEntry( vLits, i, Lit==1 );
83 Abc_ObjAddFanin( pNodeNew, pFanin->pCopy );
84 }
85 pNodeNew->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtkNew->pManFunc, vLits->nSize, vLits->pArray );
86 if ( fCompl )
87 Abc_SopComplement( (char *)pNodeNew->pData );
88 Vec_IntFree( vLits );
89 return pNodeNew;
90}
91
104{
105 Min_Cube_t * pCover = NULL, * pCube;
106 Abc_Obj_t * pFaninNew, * pNodeNew, * pFanin;
107 Vec_Int_t * vSupp;
108 int Entry, nCubes, i;
109
110 if ( Abc_ObjIsCi(pObj) )
111 return pObj->pCopy;
112 assert( Abc_ObjIsNode(pObj) );
113 // skip if already computed
114 if ( pObj->pCopy )
115 return pObj->pCopy;
116
117 // get the support and the cover
118 vSupp = Abc_ObjGetSupp( pObj );
119 pCover = Abc_ObjGetCover2( pObj );
120 assert( vSupp );
121/*
122 if ( pCover && pCover->nVars - Min_CoverSuppVarNum(p->pManMin, pCover) > 0 )
123 {
124 printf( "%d\n ", pCover->nVars - Min_CoverSuppVarNum(p->pManMin, pCover) );
125 Min_CoverWrite( stdout, pCover );
126 }
127*/
128/*
129 // print the support of this node
130 printf( "{ " );
131 Vec_IntForEachEntry( vSupp, Entry, i )
132 printf( "%d ", Entry );
133 printf( "} cubes = %d\n", Min_CoverCountCubes( pCover ) );
134*/
135 // process the fanins
136 Vec_IntForEachEntry( vSupp, Entry, i )
137 {
138 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
139 Abc_NtkCovDeriveNode_rec( p, pNtkNew, pFanin, Level+1 );
140 }
141
142 // for each cube, construct the node
143 nCubes = Min_CoverCountCubes( pCover );
144 if ( nCubes == 0 )
145 pNodeNew = Abc_NtkCreateNodeConst0(pNtkNew);
146 else if ( nCubes == 1 )
147 pNodeNew = Abc_NtkCovDeriveCube( pNtkNew, pObj, pCover, vSupp, 0 );
148 else
149 {
150 pNodeNew = Abc_NtkCreateNode( pNtkNew );
151 Min_CoverForEachCube( pCover, pCube )
152 {
153 pFaninNew = Abc_NtkCovDeriveCube( pNtkNew, pObj, pCube, vSupp, 0 );
154 Abc_ObjAddFanin( pNodeNew, pFaninNew );
155 }
156 pNodeNew->pData = Abc_SopCreateXorSpecial( (Mem_Flex_t *)pNtkNew->pManFunc, nCubes );
157 }
158/*
159 printf( "Created node %d(%d) at level %d: ", pNodeNew->Id, pObj->Id, Level );
160 Vec_IntForEachEntry( vSupp, Entry, i )
161 {
162 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
163 printf( "%d(%d) ", pFanin->pCopy->Id, pFanin->Id );
164 }
165 printf( "\n" );
166 Min_CoverWrite( stdout, pCover );
167*/
168 pObj->pCopy = pNodeNew;
169 return pNodeNew;
170}
171
184{
185 Abc_Ntk_t * pNtkNew;
186 Abc_Obj_t * pObj;
187 int i;
188 assert( Abc_NtkIsStrash(pNtk) );
189 // perform strashing
190 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
191 // reconstruct the network
192 Abc_NtkForEachCo( pNtk, pObj, i )
193 {
194 Abc_NtkCovDeriveNode_rec( p, pNtkNew, Abc_ObjFanin0(pObj), 0 );
195// printf( "*** CO %s : %d -> %d \n", Abc_ObjName(pObj), pObj->pCopy->Id, Abc_ObjFanin0(pObj)->pCopy->Id );
196 }
197 // add the COs
198 Abc_NtkFinalize( pNtk, pNtkNew );
199 Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
200 // make sure everything is okay
201 if ( !Abc_NtkCheck( pNtkNew ) )
202 {
203 printf( "Abc_NtkCovDerive: The network check has failed.\n" );
204 Abc_NtkDelete( pNtkNew );
205 return NULL;
206 }
207 return pNtkNew;
208}
209
210
211
212
224Abc_Obj_t * Abc_NtkCovDeriveInv( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pObj, int fCompl )
225{
226 assert( pObj->pCopy );
227 if ( !fCompl )
228 return pObj->pCopy;
229 if ( pObj->pCopy->pCopy == NULL )
230 pObj->pCopy->pCopy = Abc_NtkCreateNodeInv( pNtkNew, pObj->pCopy );
231 return pObj->pCopy->pCopy;
232 }
233
246{
247 Vec_Int_t * vLits;
248 Abc_Obj_t * pNodeNew, * pFanin;
249 int i, iFanin, Lit;
250 // create empty cube
251 if ( pCube->nLits == 0 )
252 return Abc_NtkCreateNodeConst1(pNtkNew);
253 // get the literals of this cube
254 vLits = Vec_IntAlloc( 10 );
255 Min_CubeGetLits( pCube, vLits );
256 assert( pCube->nLits == (unsigned)vLits->nSize );
257 // create special case when there is only one literal
258 if ( pCube->nLits == 1 )
259 {
260 iFanin = Vec_IntEntry(vLits,0);
261 pFanin = Abc_NtkObj( pObj->pNtk, Vec_IntEntry(vSupp, iFanin) );
262 Lit = Min_CubeGetVar(pCube, iFanin);
263 assert( Lit == 1 || Lit == 2 );
264 Vec_IntFree( vLits );
265// if ( Lit == 1 )// negative
266// return Abc_NtkCreateNodeInv( pNtkNew, pFanin->pCopy );
267// return pFanin->pCopy;
268 return Abc_NtkCovDeriveInv( pNtkNew, pFanin, Lit==1 );
269 }
270 assert( pCube->nLits > 1 );
271 // create the AND cube
272 pNodeNew = Abc_NtkCreateNode( pNtkNew );
273 for ( i = 0; i < vLits->nSize; i++ )
274 {
275 iFanin = Vec_IntEntry(vLits,i);
276 pFanin = Abc_NtkObj( pObj->pNtk, Vec_IntEntry(vSupp, iFanin) );
277 Lit = Min_CubeGetVar(pCube, iFanin);
278 assert( Lit == 1 || Lit == 2 );
279 Vec_IntWriteEntry( vLits, i, Lit==1 );
280// Abc_ObjAddFanin( pNodeNew, pFanin->pCopy );
281 Abc_ObjAddFanin( pNodeNew, Abc_NtkCovDeriveInv( pNtkNew, pFanin, Lit==1 ) );
282 }
283// pNodeNew->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtkNew->pManFunc, vLits->nSize, vLits->pArray );
284 pNodeNew->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtkNew->pManFunc, vLits->nSize, NULL );
285 Vec_IntFree( vLits );
286 return pNodeNew;
287}
288
301{
302 Min_Cube_t * pCover, * pCube;
303 Abc_Obj_t * pFaninNew, * pNodeNew, * pFanin;
304 Vec_Int_t * vSupp;
305 int Entry, nCubes, i;
306
307 // skip if already computed
308 if ( pObj->pCopy )
309 return Abc_NtkCovDeriveInv( pNtkNew, pObj, fCompl );
310 assert( Abc_ObjIsNode(pObj) );
311
312 // get the support and the cover
313 vSupp = Abc_ObjGetSupp( pObj );
314 pCover = Abc_ObjGetCover2( pObj );
315 assert( vSupp );
316
317 // process the fanins
318 Vec_IntForEachEntry( vSupp, Entry, i )
319 {
320 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
321 Abc_NtkCovDeriveNodeInv_rec( p, pNtkNew, pFanin, 0 );
322 }
323
324 // for each cube, construct the node
325 nCubes = Min_CoverCountCubes( pCover );
326 if ( nCubes == 0 )
327 pNodeNew = Abc_NtkCreateNodeConst0(pNtkNew);
328 else if ( nCubes == 1 )
329 pNodeNew = Abc_NtkCovDeriveCubeInv( pNtkNew, pObj, pCover, vSupp );
330 else
331 {
332 pNodeNew = Abc_NtkCreateNode( pNtkNew );
333 Min_CoverForEachCube( pCover, pCube )
334 {
335 pFaninNew = Abc_NtkCovDeriveCubeInv( pNtkNew, pObj, pCube, vSupp );
336 Abc_ObjAddFanin( pNodeNew, pFaninNew );
337 }
338 pNodeNew->pData = Abc_SopCreateXorSpecial( (Mem_Flex_t *)pNtkNew->pManFunc, nCubes );
339 }
340
341 pObj->pCopy = pNodeNew;
342 return Abc_NtkCovDeriveInv( pNtkNew, pObj, fCompl );
343}
344
358{
359 Abc_Ntk_t * pNtkNew;
360 Abc_Obj_t * pObj, * pNodeNew;
361 int i;
362 assert( Abc_NtkIsStrash(pNtk) );
363 // perform strashing
364 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
365 // reconstruct the network
366 Abc_NtkForEachCo( pNtk, pObj, i )
367 {
368 pNodeNew = Abc_NtkCovDeriveNodeInv_rec( p, pNtkNew, Abc_ObjFanin0(pObj), Abc_ObjFaninC0(pObj) );
369 Abc_ObjAddFanin( pObj->pCopy, pNodeNew );
370 }
371 // add the COs
372 Abc_NtkLogicMakeSimpleCos( pNtkNew, 0 );
373 // make sure everything is okay
374 if ( !Abc_NtkCheck( pNtkNew ) )
375 {
376 printf( "Abc_NtkCovDeriveInv: The network check has failed.\n" );
377 Abc_NtkDelete( pNtkNew );
378 return NULL;
379 }
380 return pNtkNew;
381}
382
383
384
397{
398 int fVerbose = 0;
399 Min_Cube_t * pCover, * pCovers[3];
400 Abc_Obj_t * pNodeNew, * pFanin;
401 Vec_Int_t * vSupp;
402 Vec_Str_t * vCover;
403 int i, Entry, nCubes, Type = 0;
404 // skip if already computed
405 if ( pObj->pCopy )
406 return pObj->pCopy;
407 assert( Abc_ObjIsNode(pObj) );
408 // get the support and the cover
409 vSupp = Abc_ObjGetSupp( pObj );
410 assert( vSupp );
411 // choose the cover to implement
412 pCovers[0] = Abc_ObjGetCover( pObj, 0 );
413 pCovers[1] = Abc_ObjGetCover( pObj, 1 );
414 pCovers[2] = Abc_ObjGetCover2( pObj );
415 // use positive polarity
416 if ( pCovers[0]
417 && (!pCovers[1] || Min_CoverCountCubes(pCovers[0]) <= Min_CoverCountCubes(pCovers[1]))
418 && (!pCovers[2] || Min_CoverCountCubes(pCovers[0]) <= Min_CoverCountCubes(pCovers[2])) )
419 {
420 pCover = pCovers[0];
421 Type = '1';
422 }
423 else
424 // use negative polarity
425 if ( pCovers[1]
426 && (!pCovers[0] || Min_CoverCountCubes(pCovers[1]) <= Min_CoverCountCubes(pCovers[0]))
427 && (!pCovers[2] || Min_CoverCountCubes(pCovers[1]) <= Min_CoverCountCubes(pCovers[2])) )
428 {
429 pCover = pCovers[1];
430 Type = '0';
431 }
432 else
433 // use XOR polarity
434 if ( pCovers[2]
435 && (!pCovers[0] || Min_CoverCountCubes(pCovers[2]) < Min_CoverCountCubes(pCovers[0]))
436 && (!pCovers[1] || Min_CoverCountCubes(pCovers[2]) < Min_CoverCountCubes(pCovers[1])) )
437 {
438 pCover = pCovers[2];
439 Type = 'x';
440 }
441 else
442 assert( 0 );
443 // print the support of this node
444 if ( fVerbose )
445 {
446 printf( "{ " );
447 Vec_IntForEachEntry( vSupp, Entry, i )
448 printf( "%d ", Entry );
449 printf( "} cubes = %d\n", Min_CoverCountCubes( pCover ) );
450 }
451 // process the fanins
452 Vec_IntForEachEntry( vSupp, Entry, i )
453 {
454 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
455 Abc_NtkCovDerive_rec( p, pNtkNew, pFanin );
456 }
457 // for each cube, construct the node
458 nCubes = Min_CoverCountCubes( pCover );
459 if ( nCubes == 0 )
460 pNodeNew = Abc_NtkCreateNodeConst0(pNtkNew);
461 else if ( nCubes == 1 )
462 pNodeNew = Abc_NtkCovDeriveCube( pNtkNew, pObj, pCover, vSupp, Type == '0' );
463 else
464 {
465 // create the node
466 pNodeNew = Abc_NtkCreateNode( pNtkNew );
467 Vec_IntForEachEntry( vSupp, Entry, i )
468 {
469 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
470 Abc_ObjAddFanin( pNodeNew, pFanin->pCopy );
471 }
472 // derive the function
473 vCover = Vec_StrAlloc( 100 );
474 Min_CoverCreate( vCover, pCover, (char)Type );
475 pNodeNew->pData = Abc_SopRegister((Mem_Flex_t *)pNtkNew->pManFunc, Vec_StrArray(vCover) );
476 Vec_StrFree( vCover );
477 }
478
479/*
480 printf( "Created node %d(%d) at level %d: ", pNodeNew->Id, pObj->Id, Level );
481 Vec_IntForEachEntry( vSupp, Entry, i )
482 {
483 pFanin = Abc_NtkObj(pObj->pNtk, Entry);
484 printf( "%d(%d) ", pFanin->pCopy->Id, pFanin->Id );
485 }
486 printf( "\n" );
487 Min_CoverWrite( stdout, pCover );
488*/
489 return pObj->pCopy = pNodeNew;
490}
491
504{
505 Abc_Ntk_t * pNtkNew;
506 Abc_Obj_t * pObj, * pNodeNew;
507 int i;
508 assert( Abc_NtkIsStrash(pNtk) );
509 // perform strashing
510 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
511 // reconstruct the network
512 if ( Abc_ObjFanoutNum(Abc_AigConst1(pNtk)) > 0 )
514 Abc_NtkForEachCo( pNtk, pObj, i )
515 {
516 pNodeNew = Abc_NtkCovDerive_rec( p, pNtkNew, Abc_ObjFanin0(pObj) );
517 if ( Abc_ObjFaninC0(pObj) )
518 {
519 if ( pNodeNew->pData && Abc_ObjFanoutNum(Abc_ObjFanin0(pObj)) == 1 )
520 Abc_SopComplement( (char *)pNodeNew->pData );
521 else
522 pNodeNew = Abc_NtkCreateNodeInv( pNtkNew, pNodeNew );
523 }
524 Abc_ObjAddFanin( pObj->pCopy, pNodeNew );
525 }
526 // add the COs
527 Abc_NtkLogicMakeSimpleCos( pNtkNew, 0 );
528 // make sure everything is okay
529 if ( !Abc_NtkCheck( pNtkNew ) )
530 {
531 printf( "Abc_NtkCovDerive: The network check has failed.\n" );
532 Abc_NtkDelete( pNtkNew );
533 return NULL;
534 }
535 return pNtkNew;
536}
537
541
542
544
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL char * Abc_SopCreateXorSpecial(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:297
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
ABC_DLL void Abc_SopComplement(char *pSop)
Definition abcSop.c:648
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition abcNtk.c:355
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL char * Abc_SopCreateAnd(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition abcSop.c:168
ABC_DLL int Abc_NtkLogicMakeSimpleCos(Abc_Ntk_t *pNtk, int fDuplicate)
Definition abcUtil.c:1080
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition abcObj.c:674
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL char * Abc_SopRegister(Mem_Flex_t *pMan, const char *pName)
DECLARATIONS ///.
Definition abcSop.c:62
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Abc_Obj_t * Abc_NtkCovDeriveNodeInv_rec(Cov_Man_t *p, Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCompl)
Definition covBuild.c:300
Abc_Ntk_t * Abc_NtkCovDeriveClean(Cov_Man_t *p, Abc_Ntk_t *pNtk)
Definition covBuild.c:357
Abc_Ntk_t * Abc_NtkCovDerive(Cov_Man_t *p, Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition covBuild.c:183
Abc_Obj_t * Abc_NtkCovDerive_rec(Cov_Man_t *p, Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj)
Definition covBuild.c:396
Abc_Ntk_t * Abc_NtkCovDeriveRegular(Cov_Man_t *p, Abc_Ntk_t *pNtk)
Definition covBuild.c:503
Abc_Obj_t * Abc_NtkCovDeriveCubeInv(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, Min_Cube_t *pCube, Vec_Int_t *vSupp)
Definition covBuild.c:245
Abc_Obj_t * Abc_NtkCovDeriveInv(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCompl)
Definition covBuild.c:224
Abc_Obj_t * Abc_NtkCovDeriveNode_rec(Cov_Man_t *p, Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int Level)
Definition covBuild.c:103
ABC_NAMESPACE_IMPL_START Abc_Obj_t * Abc_NtkCovDeriveCube(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, Min_Cube_t *pCube, Vec_Int_t *vSupp, int fCompl)
DECLARATIONS ///.
Definition covBuild.c:45
struct Min_Cube_t_ Min_Cube_t
Definition covInt.h:35
#define Min_CoverForEachCube(pCover, pCube)
Definition covInt.h:65
void Min_CoverCreate(Vec_Str_t *vCover, Min_Cube_t *pCover, char Type)
Definition covMinUtil.c:85
typedefABC_NAMESPACE_HEADER_START struct Cov_Man_t_ Cov_Man_t
DECLARATIONS ///.
Definition cov.h:34
Cube * p
Definition exorList.c:222
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned nLits
Definition covInt.h:59
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54