ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcMiter.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "base/io/ioAbc.h"
23#include "sat/cnf/cnf.h"
24#include "sat/bsat/satStore.h"
25
27
28
32
33static Abc_Ntk_t * Abc_NtkMiterInt( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int fComb, int nPartSize, int fImplic, int fMulti );
34static void Abc_NtkMiterPrepare( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Abc_Ntk_t * pNtkMiter, int fComb, int nPartSize, int fMulti );
35static void Abc_NtkMiterAddOne( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkMiter );
36static void Abc_NtkMiterFinalize( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Abc_Ntk_t * pNtkMiter, int fComb, int nPartSize, int fImplic, int fMulti );
37static void Abc_NtkAddFrame( Abc_Ntk_t * pNetNew, Abc_Ntk_t * pNet, int iFrame );
38
39// to be exported
40typedef void (*AddFrameMapping)( Abc_Obj_t*, Abc_Obj_t*, int, void*);
41extern Abc_Ntk_t * Abc_NtkFrames2( Abc_Ntk_t * pNtk, int nFrames, int fInitial, AddFrameMapping addFrameMapping, void* arg );
42static void Abc_NtkAddFrame2( Abc_Ntk_t * pNtkFrames, Abc_Ntk_t * pNtk, int iFrame, Vec_Ptr_t * vNodes, AddFrameMapping addFrameMapping, void* arg );
43
47
59Abc_Ntk_t * Abc_NtkMiter( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int fComb, int nPartSize, int fImplic, int fMulti )
60{
61 Abc_Ntk_t * pTemp = NULL;
62 int fRemove1, fRemove2;
63 assert( Abc_NtkHasOnlyLatchBoxes(pNtk1) );
64 assert( Abc_NtkHasOnlyLatchBoxes(pNtk2) );
65 // check that the networks have the same PIs/POs/latches
66 if ( !Abc_NtkCompareSignals( pNtk1, pNtk2, fImplic, fComb ) )
67 return NULL;
68 // make sure the circuits are strashed
69 fRemove1 = (!Abc_NtkIsStrash(pNtk1) || Abc_NtkGetChoiceNum(pNtk1)) && (pNtk1 = Abc_NtkStrash(pNtk1, 0, 0, 0));
70 fRemove2 = (!Abc_NtkIsStrash(pNtk2) || Abc_NtkGetChoiceNum(pNtk2)) && (pNtk2 = Abc_NtkStrash(pNtk2, 0, 0, 0));
71 if ( pNtk1 && pNtk2 )
72 pTemp = Abc_NtkMiterInt( pNtk1, pNtk2, fComb, nPartSize, fImplic, fMulti );
73 if ( fRemove1 ) Abc_NtkDelete( pNtk1 );
74 if ( fRemove2 ) Abc_NtkDelete( pNtk2 );
75 return pTemp;
76}
77
89Abc_Ntk_t * Abc_NtkMiterInt( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int fComb, int nPartSize, int fImplic, int fMulti )
90{
91 char Buffer[1000];
92 Abc_Ntk_t * pNtkMiter;
93
94 assert( Abc_NtkIsStrash(pNtk1) );
95 assert( Abc_NtkIsStrash(pNtk2) );
96
97 // start the new network
98 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
99 sprintf( Buffer, "%s_%s_miter", pNtk1->pName, pNtk2->pName );
100 pNtkMiter->pName = Extra_UtilStrsav(Buffer);
101
102 // perform strashing
103 Abc_NtkMiterPrepare( pNtk1, pNtk2, pNtkMiter, fComb, nPartSize, fMulti );
104 Abc_NtkMiterAddOne( pNtk1, pNtkMiter );
105 Abc_NtkMiterAddOne( pNtk2, pNtkMiter );
106 Abc_NtkMiterFinalize( pNtk1, pNtk2, pNtkMiter, fComb, nPartSize, fImplic, fMulti );
107 Abc_AigCleanup((Abc_Aig_t *)pNtkMiter->pManFunc);
108
109 // make sure that everything is okay
110 if ( !Abc_NtkCheck( pNtkMiter ) )
111 {
112 printf( "Abc_NtkMiter: The network check has failed.\n" );
113 Abc_NtkDelete( pNtkMiter );
114 return NULL;
115 }
116 return pNtkMiter;
117}
118
130void Abc_NtkMiterPrepare( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Abc_Ntk_t * pNtkMiter, int fComb, int nPartSize, int fMulti )
131{
132 Abc_Obj_t * pObj, * pObjNew;
133 int i;
134 // clean the copy field in all objects
135// Abc_NtkCleanCopy( pNtk1 );
136// Abc_NtkCleanCopy( pNtk2 );
137 Abc_AigConst1(pNtk1)->pCopy = Abc_AigConst1(pNtkMiter);
138 Abc_AigConst1(pNtk2)->pCopy = Abc_AigConst1(pNtkMiter);
139
140 if ( fComb )
141 {
142 // create new PIs and remember them in the old PIs
143 Abc_NtkForEachCi( pNtk1, pObj, i )
144 {
145 pObjNew = Abc_NtkCreatePi( pNtkMiter );
146 // remember this PI in the old PIs
147 pObj->pCopy = pObjNew;
148 pObj = Abc_NtkCi(pNtk2, i);
149 pObj->pCopy = pObjNew;
150 // add name
151 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), NULL );
152 }
153 if ( nPartSize <= 0 )
154 {
155 // create POs
156 if ( fMulti )
157 {
158 Abc_NtkForEachCo( pNtk1, pObj, i )
159 {
160 pObjNew = Abc_NtkCreatePo( pNtkMiter );
161 Abc_ObjAssignName( pObjNew, "miter", Abc_ObjName(pObjNew) );
162 }
163
164 }
165 else
166 {
167 pObjNew = Abc_NtkCreatePo( pNtkMiter );
168 Abc_ObjAssignName( pObjNew, "miter", NULL );
169 }
170 }
171 }
172 else
173 {
174 // create new PIs and remember them in the old PIs
175 Abc_NtkForEachPi( pNtk1, pObj, i )
176 {
177 pObjNew = Abc_NtkCreatePi( pNtkMiter );
178 // remember this PI in the old PIs
179 pObj->pCopy = pObjNew;
180 pObj = Abc_NtkPi(pNtk2, i);
181 pObj->pCopy = pObjNew;
182 // add name
183 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), NULL );
184 }
185 if ( nPartSize <= 0 )
186 {
187 // create POs
188 if ( fMulti )
189 {
190 Abc_NtkForEachPo( pNtk1, pObj, i )
191 {
192 pObjNew = Abc_NtkCreatePo( pNtkMiter );
193 Abc_ObjAssignName( pObjNew, "miter", Abc_ObjName(pObjNew) );
194 }
195
196 }
197 else
198 {
199 pObjNew = Abc_NtkCreatePo( pNtkMiter );
200 Abc_ObjAssignName( pObjNew, "miter", NULL );
201 }
202 }
203 // create the latches
204 Abc_NtkForEachLatch( pNtk1, pObj, i )
205 {
206 pObjNew = Abc_NtkDupBox( pNtkMiter, pObj, 0 );
207 // add names
208 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), "_1" );
209 Abc_ObjAssignName( Abc_ObjFanin0(pObjNew), Abc_ObjName(Abc_ObjFanin0(pObj)), "_1" );
210 Abc_ObjAssignName( Abc_ObjFanout0(pObjNew), Abc_ObjName(Abc_ObjFanout0(pObj)), "_1" );
211 }
212 Abc_NtkForEachLatch( pNtk2, pObj, i )
213 {
214 pObjNew = Abc_NtkDupBox( pNtkMiter, pObj, 0 );
215 // add name
216 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), "_2" );
217 Abc_ObjAssignName( Abc_ObjFanin0(pObjNew), Abc_ObjName(Abc_ObjFanin0(pObj)), "_2" );
218 Abc_ObjAssignName( Abc_ObjFanout0(pObjNew), Abc_ObjName(Abc_ObjFanout0(pObj)), "_2" );
219 }
220 }
221}
222
234void Abc_NtkMiterAddOne( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkMiter )
235{
236 Abc_Obj_t * pNode;
237 int i;
239 Abc_AigForEachAnd( pNtk, pNode, i )
240 pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
241}
242
254void Abc_NtkMiterAddCone( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkMiter, Abc_Obj_t * pRoot )
255{
256 Vec_Ptr_t * vNodes;
257 Abc_Obj_t * pNode;
258 int i;
259 // map the constant nodes
260 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkMiter);
261 // perform strashing
262 vNodes = Abc_NtkDfsNodes( pNtk, &pRoot, 1 );
263 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
264 if ( Abc_AigNodeIsAnd(pNode) )
265 pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
266 Vec_PtrFree( vNodes );
267}
268
269
281void Abc_NtkMiterFinalize( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Abc_Ntk_t * pNtkMiter, int fComb, int nPartSize, int fImplic, int fMulti )
282{
283 Vec_Ptr_t * vPairs;
284 Abc_Obj_t * pMiter, * pNode;
285 int i;
286 assert( nPartSize == 0 || fMulti == 0 );
287 // collect the PO pairs from both networks
288 vPairs = Vec_PtrAlloc( 100 );
289 if ( fComb )
290 {
291 // collect the CO nodes for the miter
292 Abc_NtkForEachCo( pNtk1, pNode, i )
293 {
294 if ( fMulti )
295 {
296 pMiter = Abc_AigXor( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild0Copy(Abc_NtkCo(pNtk2, i)) );
297 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,i), pMiter );
298 }
299 else
300 {
301 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
302 pNode = Abc_NtkCo( pNtk2, i );
303 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
304 }
305 }
306 }
307 else
308 {
309 // collect the PO nodes for the miter
310 Abc_NtkForEachPo( pNtk1, pNode, i )
311 {
312 if ( fMulti )
313 {
314 pMiter = Abc_AigXor( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild0Copy(Abc_NtkCo(pNtk2, i)) );
315 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,i), pMiter );
316 }
317 else
318 {
319 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
320 pNode = Abc_NtkPo( pNtk2, i );
321 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
322 }
323 }
324 // connect new latches
325 Abc_NtkForEachLatch( pNtk1, pNode, i )
326 Abc_ObjAddFanin( Abc_ObjFanin0(pNode)->pCopy, Abc_ObjChild0Copy(Abc_ObjFanin0(pNode)) );
327 Abc_NtkForEachLatch( pNtk2, pNode, i )
328 Abc_ObjAddFanin( Abc_ObjFanin0(pNode)->pCopy, Abc_ObjChild0Copy(Abc_ObjFanin0(pNode)) );
329 }
330 // add the miter
331 if ( nPartSize <= 0 )
332 {
333 if ( !fMulti )
334 {
335 pMiter = Abc_AigMiter( (Abc_Aig_t *)pNtkMiter->pManFunc, vPairs, fImplic );
336 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pMiter );
337 }
338 }
339 else
340 {
341 char Buffer[1024];
342 Vec_Ptr_t * vPairsPart;
343 int nParts, i, k, iCur;
344 assert( Vec_PtrSize(vPairs) == 2 * Abc_NtkCoNum(pNtk1) );
345 // create partitions
346 nParts = Abc_NtkCoNum(pNtk1) / nPartSize + (int)((Abc_NtkCoNum(pNtk1) % nPartSize) > 0);
347 vPairsPart = Vec_PtrAlloc( nPartSize );
348 for ( i = 0; i < nParts; i++ )
349 {
350 Vec_PtrClear( vPairsPart );
351 for ( k = 0; k < nPartSize; k++ )
352 {
353 iCur = i * nPartSize + k;
354 if ( iCur >= Abc_NtkCoNum(pNtk1) )
355 break;
356 Vec_PtrPush( vPairsPart, Vec_PtrEntry(vPairs, 2*iCur ) );
357 Vec_PtrPush( vPairsPart, Vec_PtrEntry(vPairs, 2*iCur+1) );
358 }
359 pMiter = Abc_AigMiter( (Abc_Aig_t *)pNtkMiter->pManFunc, vPairsPart, fImplic );
360 pNode = Abc_NtkCreatePo( pNtkMiter );
361 Abc_ObjAddFanin( pNode, pMiter );
362 // assign the name to the node
363 if ( nPartSize == 1 )
364 sprintf( Buffer, "%s", Abc_ObjName(Abc_NtkCo(pNtk1,i)) );
365 else
366 sprintf( Buffer, "%d", i );
367 Abc_ObjAssignName( pNode, "miter_", Buffer );
368 }
369 Vec_PtrFree( vPairsPart );
370 }
371 Vec_PtrFree( vPairs );
372}
373
374
375
387Abc_Ntk_t * Abc_NtkMiterAnd( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int fOr, int fCompl2 )
388{
389 char Buffer[1000];
390 Abc_Ntk_t * pNtkMiter;
391 Abc_Obj_t * pOutput1, * pOutput2;
392 Abc_Obj_t * pRoot1, * pRoot2, * pMiter;
393
394 assert( Abc_NtkIsStrash(pNtk1) );
395 assert( Abc_NtkIsStrash(pNtk2) );
396 assert( 1 == Abc_NtkCoNum(pNtk1) );
397 assert( 1 == Abc_NtkCoNum(pNtk2) );
398 assert( 0 == Abc_NtkLatchNum(pNtk1) );
399 assert( 0 == Abc_NtkLatchNum(pNtk2) );
400 assert( Abc_NtkCiNum(pNtk1) == Abc_NtkCiNum(pNtk2) );
401 assert( Abc_NtkHasOnlyLatchBoxes(pNtk1) );
402 assert( Abc_NtkHasOnlyLatchBoxes(pNtk2) );
403
404 // start the new network
405 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
406// sprintf( Buffer, "%s_%s_miter", pNtk1->pName, pNtk2->pName );
407 sprintf( Buffer, "product" );
408 pNtkMiter->pName = Extra_UtilStrsav(Buffer);
409
410 // perform strashing
411 Abc_NtkMiterPrepare( pNtk1, pNtk2, pNtkMiter, 1, -1, 0 );
412 Abc_NtkMiterAddOne( pNtk1, pNtkMiter );
413 Abc_NtkMiterAddOne( pNtk2, pNtkMiter );
414// Abc_NtkMiterFinalize( pNtk1, pNtk2, pNtkMiter, 1 );
415 pRoot1 = Abc_NtkPo(pNtk1,0);
416 pRoot2 = Abc_NtkPo(pNtk2,0);
417 pOutput1 = Abc_ObjNotCond( Abc_ObjFanin0(pRoot1)->pCopy, Abc_ObjFaninC0(pRoot1) );
418 pOutput2 = Abc_ObjNotCond( Abc_ObjFanin0(pRoot2)->pCopy, (int)Abc_ObjFaninC0(pRoot2) ^ fCompl2 );
419
420 // create the miter of the two outputs
421 if ( fOr )
422 pMiter = Abc_AigOr( (Abc_Aig_t *)pNtkMiter->pManFunc, pOutput1, pOutput2 );
423 else
424 pMiter = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, pOutput1, pOutput2 );
425 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pMiter );
426
427 // make sure that everything is okay
428 if ( !Abc_NtkCheck( pNtkMiter ) )
429 {
430 printf( "Abc_NtkMiterAnd: The network check has failed.\n" );
431 Abc_NtkDelete( pNtkMiter );
432 return NULL;
433 }
434 return pNtkMiter;
435}
436
437
451{
452 char Buffer[1000];
453 Abc_Ntk_t * pNtkMiter;
454 Abc_Obj_t * pRoot, * pOutput1;
455 int Value, i;
456
457 assert( Abc_NtkIsStrash(pNtk) );
458 assert( 1 == Abc_NtkCoNum(pNtk) );
459 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
460
461 // start the new network
462 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
463 sprintf( Buffer, "%s_miter", pNtk->pName );
464 pNtkMiter->pName = Extra_UtilStrsav(Buffer);
465
466 // get the root output
467 pRoot = Abc_NtkCo( pNtk, 0 );
468
469 // perform strashing
470 Abc_NtkMiterPrepare( pNtk, pNtk, pNtkMiter, 1, -1, 0 );
471 // set the first cofactor
472 Vec_IntForEachEntry( vPiValues, Value, i )
473 {
474 if ( Value == -1 )
475 continue;
476 if ( Value == 0 )
477 {
478 Abc_NtkCi(pNtk, i)->pCopy = Abc_ObjNot( Abc_AigConst1(pNtkMiter) );
479 continue;
480 }
481 if ( Value == 1 )
482 {
483 Abc_NtkCi(pNtk, i)->pCopy = Abc_AigConst1(pNtkMiter);
484 continue;
485 }
486 assert( 0 );
487 }
488 // add the first cofactor
489 Abc_NtkMiterAddCone( pNtk, pNtkMiter, pRoot );
490
491 // save the output
492 pOutput1 = Abc_ObjNotCond( Abc_ObjFanin0(pRoot)->pCopy, Abc_ObjFaninC0(pRoot) );
493
494 // create the miter of the two outputs
495 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pOutput1 );
496
497 // make sure that everything is okay
498 if ( !Abc_NtkCheck( pNtkMiter ) )
499 {
500 printf( "Abc_NtkMiterCofactor: The network check has failed.\n" );
501 Abc_NtkDelete( pNtkMiter );
502 return NULL;
503 }
504 return pNtkMiter;
505}
506
517Abc_Ntk_t * Abc_NtkMiterForCofactors( Abc_Ntk_t * pNtk, int Out, int In1, int In2 )
518{
519 char Buffer[1000];
520 Abc_Ntk_t * pNtkMiter;
521 Abc_Obj_t * pRoot, * pOutput1, * pOutput2, * pMiter;
522
523 assert( Abc_NtkIsStrash(pNtk) );
524 assert( Out < Abc_NtkCoNum(pNtk) );
525 assert( In1 < Abc_NtkCiNum(pNtk) );
526 assert( In2 < Abc_NtkCiNum(pNtk) );
527 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
528
529 // start the new network
530 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
531 sprintf( Buffer, "%s_miter", Abc_ObjName(Abc_NtkCo(pNtk, Out)) );
532 pNtkMiter->pName = Extra_UtilStrsav(Buffer);
533
534 // get the root output
535 pRoot = Abc_NtkCo( pNtk, Out );
536
537 // perform strashing
538 Abc_NtkMiterPrepare( pNtk, pNtk, pNtkMiter, 1, -1, 0 );
539 // set the first cofactor
540 Abc_NtkCi(pNtk, In1)->pCopy = Abc_ObjNot( Abc_AigConst1(pNtkMiter) );
541 if ( In2 >= 0 )
542 Abc_NtkCi(pNtk, In2)->pCopy = Abc_AigConst1(pNtkMiter);
543 // add the first cofactor
544 Abc_NtkMiterAddCone( pNtk, pNtkMiter, pRoot );
545
546 // save the output
547 pOutput1 = Abc_ObjFanin0(pRoot)->pCopy;
548
549 // set the second cofactor
550 Abc_NtkCi(pNtk, In1)->pCopy = Abc_AigConst1(pNtkMiter);
551 if ( In2 >= 0 )
552 Abc_NtkCi(pNtk, In2)->pCopy = Abc_ObjNot( Abc_AigConst1(pNtkMiter) );
553 // add the second cofactor
554 Abc_NtkMiterAddCone( pNtk, pNtkMiter, pRoot );
555
556 // save the output
557 pOutput2 = Abc_ObjFanin0(pRoot)->pCopy;
558
559 // create the miter of the two outputs
560 pMiter = Abc_AigXor( (Abc_Aig_t *)pNtkMiter->pManFunc, pOutput1, pOutput2 );
561 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pMiter );
562
563 // make sure that everything is okay
564 if ( !Abc_NtkCheck( pNtkMiter ) )
565 {
566 printf( "Abc_NtkMiter: The network check has failed.\n" );
567 Abc_NtkDelete( pNtkMiter );
568 return NULL;
569 }
570 return pNtkMiter;
571}
572
573
585Abc_Ntk_t * Abc_NtkMiterQuantify( Abc_Ntk_t * pNtk, int In, int fExist )
586{
587 Abc_Ntk_t * pNtkMiter;
588 Abc_Obj_t * pRoot, * pOutput1, * pOutput2, * pMiter;
589
590 assert( Abc_NtkIsStrash(pNtk) );
591 assert( 1 == Abc_NtkCoNum(pNtk) );
592 assert( In < Abc_NtkCiNum(pNtk) );
593 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
594
595 // start the new network
596 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
597 pNtkMiter->pName = Extra_UtilStrsav( Abc_ObjName(Abc_NtkCo(pNtk, 0)) );
598
599 // get the root output
600 pRoot = Abc_NtkCo( pNtk, 0 );
601
602 // perform strashing
603 Abc_NtkMiterPrepare( pNtk, pNtk, pNtkMiter, 1, -1, 0 );
604 // set the first cofactor
605 Abc_NtkCi(pNtk, In)->pCopy = Abc_ObjNot( Abc_AigConst1(pNtkMiter) );
606 // add the first cofactor
607 Abc_NtkMiterAddCone( pNtk, pNtkMiter, pRoot );
608 // save the output
609// pOutput1 = Abc_ObjFanin0(pRoot)->pCopy;
610 pOutput1 = Abc_ObjNotCond( Abc_ObjFanin0(pRoot)->pCopy, Abc_ObjFaninC0(pRoot) );
611
612 // set the second cofactor
613 Abc_NtkCi(pNtk, In)->pCopy = Abc_AigConst1(pNtkMiter);
614 // add the second cofactor
615 Abc_NtkMiterAddCone( pNtk, pNtkMiter, pRoot );
616 // save the output
617// pOutput2 = Abc_ObjFanin0(pRoot)->pCopy;
618 pOutput2 = Abc_ObjNotCond( Abc_ObjFanin0(pRoot)->pCopy, Abc_ObjFaninC0(pRoot) );
619
620 // create the miter of the two outputs
621 if ( fExist )
622 pMiter = Abc_AigOr( (Abc_Aig_t *)pNtkMiter->pManFunc, pOutput1, pOutput2 );
623 else
624 pMiter = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, pOutput1, pOutput2 );
625 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pMiter );
626
627 // make sure that everything is okay
628 if ( !Abc_NtkCheck( pNtkMiter ) )
629 {
630 printf( "Abc_NtkMiter: The network check has failed.\n" );
631 Abc_NtkDelete( pNtkMiter );
632 return NULL;
633 }
634 return pNtkMiter;
635}
636
649{
650 Abc_Ntk_t * pNtkTemp;
651 Abc_Obj_t * pObj;
652 int i;
653 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
654
655 Abc_NtkForEachPi( pNtk, pObj, i )
656 {
657 if ( Abc_ObjFanoutNum(pObj) == 0 )
658 continue;
659 pNtk = Abc_NtkMiterQuantify( pNtkTemp = pNtk, i, 1 );
660 Abc_NtkDelete( pNtkTemp );
661 }
662
663 return pNtk;
664}
665
666
667
668
683{
684 Abc_Obj_t * pNodePo, * pChild;
685 int i;
686 assert( Abc_NtkIsStrash(pMiter) );
687 Abc_NtkForEachPo( pMiter, pNodePo, i )
688 {
689 pChild = Abc_ObjChild0( pNodePo );
690 // check if the output is constant 1
691 if ( Abc_AigNodeIsConst(pChild) )
692 {
693 assert( Abc_ObjRegular(pChild) == Abc_AigConst1(pMiter) );
694 if ( !Abc_ObjIsComplement(pChild) )
695 {
696 // if the miter is constant 1, return immediately
697// printf( "MITER IS CONSTANT 1!\n" );
698 return 0;
699 }
700 }
701/*
702 // check if the output is not constant 0
703 else if ( Abc_ObjRegular(pChild)->fPhase != (unsigned)Abc_ObjIsComplement(pChild) )
704 {
705 return 0;
706 }
707*/
708 // if the miter is undecided (or satisfiable), return immediately
709 else
710 return -1;
711 }
712 // return 1, meaning all outputs are constant zero
713 return 1;
714}
715
728{
729 Abc_Obj_t * pChild, * pNode;
730 int i;
731 if ( Abc_NtkPoNum(pMiter) == 1 )
732 {
733 pChild = Abc_ObjChild0( Abc_NtkPo(pMiter,0) );
734 if ( Abc_AigNodeIsConst(pChild) )
735 {
736 if ( Abc_ObjIsComplement(pChild) )
737 printf( "Unsatisfiable.\n" );
738 else
739 printf( "Satisfiable. (Constant 1).\n" );
740 }
741 else
742 printf( "Satisfiable.\n" );
743 }
744 else
745 {
746 Abc_NtkForEachPo( pMiter, pNode, i )
747 {
748 pChild = Abc_ObjChild0( Abc_NtkPo(pMiter,i) );
749 printf( "Output #%2d : ", i );
750 if ( Abc_AigNodeIsConst(pChild) )
751 {
752 if ( Abc_ObjIsComplement(pChild) )
753 printf( "Unsatisfiable.\n" );
754 else
755 printf( "Satisfiable. (Constant 1).\n" );
756 }
757 else
758 printf( "Satisfiable.\n" );
759 }
760 }
761}
762
763
775Abc_Ntk_t * Abc_NtkFrames( Abc_Ntk_t * pNtk, int nFrames, int fInitial, int fVerbose )
776{
777 char Buffer[1000];
778 ProgressBar * pProgress;
779 Abc_Ntk_t * pNtkFrames;
780 Abc_Obj_t * pLatch, * pLatchOut;
781 int i, Counter;
782 assert( nFrames > 0 );
783 assert( Abc_NtkIsStrash(pNtk) );
785 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
786 // start the new network
787 pNtkFrames = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
788 sprintf( Buffer, "%s_%d_frames", pNtk->pName, nFrames );
789 pNtkFrames->pName = Extra_UtilStrsav(Buffer);
790 // map the constant nodes
791 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkFrames);
792
793 // create new latches (or their initial values) and remember them in the new latches
794 if ( !fInitial )
795 {
796 Abc_NtkForEachLatch( pNtk, pLatch, i )
797 Abc_NtkDupBox( pNtkFrames, pLatch, 1 );
798 }
799 else
800 {
801 Counter = 0;
802 Abc_NtkForEachLatch( pNtk, pLatch, i )
803 {
804 pLatchOut = Abc_ObjFanout0(pLatch);
805 if ( Abc_LatchIsInitNone(pLatch) || Abc_LatchIsInitDc(pLatch) ) // don't-care initial value - create a new PI
806 {
807 pLatchOut->pCopy = Abc_NtkCreatePi(pNtkFrames);
808 Abc_ObjAssignName( pLatchOut->pCopy, Abc_ObjName(pLatchOut), NULL );
809 Counter++;
810 }
811 else
812 pLatchOut->pCopy = Abc_ObjNotCond( Abc_AigConst1(pNtkFrames), Abc_LatchIsInit0(pLatch) );
813 }
814 if ( Counter )
815 printf( "Warning: %d uninitialized latches are replaced by free PI variables.\n", Counter );
816 }
817
818 // create the timeframes
819 pProgress = Extra_ProgressBarStart( stdout, nFrames );
820 for ( i = 0; i < nFrames; i++ )
821 {
822 Extra_ProgressBarUpdate( pProgress, i, NULL );
823 Abc_NtkAddFrame( pNtkFrames, pNtk, i );
824 }
825 Extra_ProgressBarStop( pProgress );
826
827 // connect the new latches to the outputs of the last frame
828 if ( !fInitial )
829 {
830 // we cannot use pLatch->pCopy here because pLatch->pCopy is used for temporary storage of strashed values
831 Abc_NtkForEachLatch( pNtk, pLatch, i )
832 Abc_ObjAddFanin( Abc_ObjFanin0(pLatch)->pCopy, Abc_ObjFanout0(pLatch)->pCopy );
833 }
834
835 // remove dangling nodes
836 Abc_AigCleanup( (Abc_Aig_t *)pNtkFrames->pManFunc );
837 // reorder the latches
838 Abc_NtkOrderCisCos( pNtkFrames );
839 // make sure that everything is okay
840 if ( !Abc_NtkCheck( pNtkFrames ) )
841 {
842 printf( "Abc_NtkFrames: The network check has failed.\n" );
843 Abc_NtkDelete( pNtkFrames );
844 return NULL;
845 }
846 return pNtkFrames;
847}
848
863void Abc_NtkAddFrame( Abc_Ntk_t * pNtkFrames, Abc_Ntk_t * pNtk, int iFrame )
864{
865 int fVerbose = 0;
866 int NodeBef = Abc_NtkNodeNum(pNtkFrames);
867 char Buffer[16];
868 Abc_Obj_t * pNode, * pLatch;
869 int i;
870 // create the prefix to be added to the node names
871 sprintf( Buffer, "_%02d", iFrame );
872 // add the new PI nodes
873 Abc_NtkForEachPi( pNtk, pNode, i )
874 Abc_ObjAssignName( Abc_NtkDupObj(pNtkFrames, pNode, 0), Abc_ObjName(pNode), Buffer );
875 // add the internal nodes
876 Abc_AigForEachAnd( pNtk, pNode, i )
877 pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkFrames->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
878 // add the new POs
879 Abc_NtkForEachPo( pNtk, pNode, i )
880 {
881 Abc_ObjAssignName( Abc_NtkDupObj(pNtkFrames, pNode, 0), Abc_ObjName(pNode), Buffer );
882 Abc_ObjAddFanin( pNode->pCopy, Abc_ObjChild0Copy(pNode) );
883 }
884 // transfer the implementation of the latch inputs to the latch outputs
885 Abc_NtkForEachLatch( pNtk, pLatch, i )
886 pLatch->pCopy = Abc_ObjChild0Copy(Abc_ObjFanin0(pLatch));
887 Abc_NtkForEachLatch( pNtk, pLatch, i )
888 Abc_ObjFanout0(pLatch)->pCopy = pLatch->pCopy;
889 // nodes after
890 if ( fVerbose )
891 printf( "F = %4d : Total = %6d. Nodes = %6d. Prop = %s.\n",
892 iFrame, Abc_NtkNodeNum(pNtk), Abc_NtkNodeNum(pNtkFrames)-NodeBef,
893 Abc_AigNodeIsConst( Abc_ObjFanin0(Abc_NtkPo(pNtk,0))->pCopy ) ? "proof" : "unknown" );
894}
895
896
897
909Abc_Ntk_t * Abc_NtkFrames2( Abc_Ntk_t * pNtk, int nFrames, int fInitial, AddFrameMapping addFrameMapping, void* arg )
910{
911/*
912 char Buffer[1000];
913 ProgressBar * pProgress;
914 Abc_Ntk_t * pNtkFrames;
915 Vec_Ptr_t * vNodes;
916 Abc_Obj_t * pLatch, * pLatchNew;
917 int i, Counter;
918 assert( nFrames > 0 );
919 assert( Abc_NtkIsStrash(pNtk) );
920 // start the new network
921 pNtkFrames = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
922 sprintf( Buffer, "%s_%d_frames", pNtk->pName, nFrames );
923 pNtkFrames->pName = Extra_UtilStrsav(Buffer);
924 // create new latches (or their initial values) and remember them in the new latches
925 if ( !fInitial )
926 {
927 Abc_NtkForEachLatch( pNtk, pLatch, i ) {
928 Abc_NtkDupObj( pNtkFrames, pLatch );
929 if (addFrameMapping) addFrameMapping(pLatch->pCopy, pLatch, 0, arg);
930 }
931 }
932 else
933 {
934 Counter = 0;
935 Abc_NtkForEachLatch( pNtk, pLatch, i )
936 {
937 if ( Abc_LatchIsInitDc(pLatch) ) // don't-care initial value - create a new PI
938 {
939 pLatch->pCopy = Abc_NtkCreatePi(pNtkFrames);
940 Abc_ObjAssignName( pLatch->pCopy, Abc_ObjName(pLatch), NULL );
941 Counter++;
942 }
943 else {
944 pLatch->pCopy = Abc_ObjNotCond( Abc_AigConst1(pNtkFrames), Abc_LatchIsInit0(pLatch) );
945 }
946
947 if (addFrameMapping) addFrameMapping(pLatch->pCopy, pLatch, 0, arg);
948 }
949 if ( Counter )
950 printf( "Warning: %d uninitialized latches are replaced by free PI variables.\n", Counter );
951 }
952
953 // create the timeframes
954 vNodes = Abc_NtkDfs( pNtk, 0 );
955 pProgress = Extra_ProgressBarStart( stdout, nFrames );
956 for ( i = 0; i < nFrames; i++ )
957 {
958 Extra_ProgressBarUpdate( pProgress, i, NULL );
959 Abc_NtkAddFrame2( pNtkFrames, pNtk, i, vNodes, addFrameMapping, arg );
960 }
961 Extra_ProgressBarStop( pProgress );
962 Vec_PtrFree( vNodes );
963
964 // connect the new latches to the outputs of the last frame
965 if ( !fInitial )
966 {
967 Abc_NtkForEachLatch( pNtk, pLatch, i )
968 {
969 pLatchNew = Abc_NtkBox(pNtkFrames, i);
970 Abc_ObjAddFanin( pLatchNew, pLatch->pCopy );
971 Abc_ObjAssignName( pLatchNew, Abc_ObjName(pLatch), NULL );
972 }
973 }
974 Abc_NtkForEachLatch( pNtk, pLatch, i )
975 pLatch->pNext = NULL;
976
977 // remove dangling nodes
978 Abc_AigCleanup( pNtkFrames->pManFunc );
979
980 // reorder the latches
981 Abc_NtkOrderCisCos( pNtkFrames );
982
983 // make sure that everything is okay
984 if ( !Abc_NtkCheck( pNtkFrames ) )
985 {
986 printf( "Abc_NtkFrames: The network check has failed.\n" );
987 Abc_NtkDelete( pNtkFrames );
988 return NULL;
989 }
990 return pNtkFrames;
991*/
992 return NULL;
993}
994
1009void Abc_NtkAddFrame2( Abc_Ntk_t * pNtkFrames, Abc_Ntk_t * pNtk, int iFrame, Vec_Ptr_t * vNodes, AddFrameMapping addFrameMapping, void* arg )
1010{
1011/*
1012 char Buffer[16];
1013 Abc_Obj_t * pNode, * pNodeNew, * pLatch;
1014 Abc_Obj_t * pConst1, * pConst1New;
1015 int i;
1016 // get the constant nodes
1017 pConst1 = Abc_AigConst1(pNtk);
1018 pConst1New = Abc_AigConst1(pNtkFrames);
1019 // create the prefix to be added to the node names
1020 sprintf( Buffer, "_%02d", iFrame );
1021 // add the new PI nodes
1022 Abc_NtkForEachPi( pNtk, pNode, i )
1023 {
1024 pNodeNew = Abc_NtkDupObj( pNtkFrames, pNode );
1025 Abc_ObjAssignName( pNodeNew, Abc_ObjName(pNode), Buffer );
1026 if (addFrameMapping) addFrameMapping(pNodeNew, pNode, iFrame, arg);
1027 }
1028 // add the internal nodes
1029 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
1030 {
1031 if ( pNode == pConst1 )
1032 pNodeNew = pConst1New;
1033 else
1034 pNodeNew = Abc_AigAnd( pNtkFrames->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
1035 pNode->pCopy = pNodeNew;
1036 if (addFrameMapping) addFrameMapping(pNodeNew, pNode, iFrame, arg);
1037 }
1038 // add the new POs
1039 Abc_NtkForEachPo( pNtk, pNode, i )
1040 {
1041 pNodeNew = Abc_NtkDupObj( pNtkFrames, pNode );
1042 Abc_ObjAddFanin( pNodeNew, Abc_ObjChild0Copy(pNode) );
1043 Abc_ObjAssignName( pNodeNew, Abc_ObjName(pNode), Buffer );
1044 if (addFrameMapping) addFrameMapping(pNodeNew, pNode, iFrame, arg);
1045 }
1046 // transfer the implementation of the latch drivers to the latches
1047
1048 // it is important that these two steps are performed it two loops
1049 // and not in the same loop
1050 Abc_NtkForEachLatch( pNtk, pLatch, i )
1051 pLatch->pNext = Abc_ObjChild0Copy(pLatch);
1052 Abc_NtkForEachLatch( pNtk, pLatch, i )
1053 pLatch->pCopy = pLatch->pNext;
1054
1055 Abc_NtkForEachLatch( pNtk, pLatch, i )
1056 {
1057 if (addFrameMapping) {
1058 // don't give Mike complemented pointers because he doesn't like it
1059 if (Abc_ObjIsComplement(pLatch->pCopy)) {
1060 pNodeNew = Abc_NtkCreateNode( pNtkFrames );
1061 Abc_ObjAddFanin( pNodeNew, pLatch->pCopy );
1062 assert(Abc_ObjFaninNum(pNodeNew) == 1);
1063 pNodeNew->Level = 1 + Abc_ObjRegular(pLatch->pCopy)->Level;
1064
1065 pLatch->pNext = pNodeNew;
1066 pLatch->pCopy = pNodeNew;
1067 }
1068 addFrameMapping(pLatch->pCopy, pLatch, iFrame+1, arg);
1069 }
1070 }
1071*/
1072}
1073
1074
1075
1088{
1089 Abc_Obj_t * pNodeC, * pNodeA, * pNodeB, * pNode;
1090 Abc_Obj_t * pPoNew;
1091 Vec_Ptr_t * vNodes1, * vNodes2;
1092 int nCommon, i;
1093
1094 assert( Abc_NtkIsStrash(pNtk) );
1095 assert( Abc_NtkPoNum(pNtk) == 1 );
1096 if ( !Abc_NodeIsExorType(Abc_ObjFanin0(Abc_NtkPo(pNtk,0))) )
1097 {
1098 printf( "The root of the miter is not an EXOR gate.\n" );
1099 return 0;
1100 }
1101 pNodeC = Abc_NodeRecognizeMux( Abc_ObjFanin0(Abc_NtkPo(pNtk,0)), &pNodeA, &pNodeB );
1102 assert( Abc_ObjRegular(pNodeA) == Abc_ObjRegular(pNodeB) );
1103 if ( Abc_ObjFaninC0(Abc_NtkPo(pNtk,0)) )
1104 {
1105 pNodeA = Abc_ObjNot(pNodeA);
1106 pNodeB = Abc_ObjNot(pNodeB);
1107 }
1108
1109 // add the PO corresponding to control input
1110 pPoNew = Abc_NtkCreatePo( pNtk );
1111 Abc_ObjAddFanin( pPoNew, pNodeC );
1112 Abc_ObjAssignName( pPoNew, "addOut1", NULL );
1113
1114 // add the PO corresponding to other input
1115 pPoNew = Abc_NtkCreatePo( pNtk );
1116 Abc_ObjAddFanin( pPoNew, pNodeB );
1117 Abc_ObjAssignName( pPoNew, "addOut2", NULL );
1118
1119 // mark the nodes in the first cone
1120 pNodeB = Abc_ObjRegular(pNodeB);
1121 vNodes1 = Abc_NtkDfsNodes( pNtk, &pNodeC, 1 );
1122 vNodes2 = Abc_NtkDfsNodes( pNtk, &pNodeB, 1 );
1123
1124 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes1, pNode, i )
1125 pNode->fMarkA = 1;
1126 nCommon = 0;
1127 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes2, pNode, i )
1128 nCommon += pNode->fMarkA;
1129 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes1, pNode, i )
1130 pNode->fMarkA = 0;
1131
1132 printf( "First cone = %6d. Second cone = %6d. Common = %6d.\n", vNodes1->nSize, vNodes2->nSize, nCommon );
1133 Vec_PtrFree( vNodes1 );
1134 Vec_PtrFree( vNodes2 );
1135
1136 // reorder the latches
1137 Abc_NtkOrderCisCos( pNtk );
1138 // make sure that everything is okay
1139 if ( !Abc_NtkCheck( pNtk ) )
1140 printf( "Abc_NtkDemiter: The network check has failed.\n" );
1141 return 1;
1142}
1143
1155int Abc_NtkCombinePos( Abc_Ntk_t * pNtk, int fAnd, int fXor )
1156{
1157 Abc_Obj_t * pNode, * pMiter;
1158 int i;
1159 assert( Abc_NtkIsStrash(pNtk) );
1160// assert( Abc_NtkLatchNum(pNtk) == 0 );
1161 if ( Abc_NtkPoNum(pNtk) == 1 )
1162 return 1;
1163 // start the result
1164 if ( fAnd )
1165 pMiter = Abc_AigConst1(pNtk);
1166 else
1167 pMiter = Abc_ObjNot( Abc_AigConst1(pNtk) );
1168 // perform operations on the POs
1169 Abc_NtkForEachPo( pNtk, pNode, i )
1170 if ( fAnd )
1171 pMiter = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, pMiter, Abc_ObjChild0(pNode) );
1172 else if ( fXor )
1173 pMiter = Abc_AigXor( (Abc_Aig_t *)pNtk->pManFunc, pMiter, Abc_ObjChild0(pNode) );
1174 else
1175 pMiter = Abc_AigOr( (Abc_Aig_t *)pNtk->pManFunc, pMiter, Abc_ObjChild0(pNode) );
1176 // remove the POs and their names
1177 for ( i = Abc_NtkPoNum(pNtk) - 1; i >= 0; i-- )
1178 Abc_NtkDeleteObj( Abc_NtkPo(pNtk, i) );
1179 assert( Abc_NtkPoNum(pNtk) == 0 );
1180 // create the new PO
1181 pNode = Abc_NtkCreatePo( pNtk );
1182 Abc_ObjAddFanin( pNode, pMiter );
1183 Abc_ObjAssignName( pNode, "miter", NULL );
1184 Abc_NtkOrderCisCos( pNtk );
1185 // make sure that everything is okay
1186 if ( !Abc_NtkCheck( pNtk ) )
1187 {
1188 printf( "Abc_NtkOrPos: The network check has failed.\n" );
1189 return 0;
1190 }
1191 return 1;
1192}
1193
1205Vec_Ptr_t * Abc_NtkTryNewMiter( char * pFileName0, char * pFileName1 )
1206{
1207 extern void * Cnf_DataWriteIntoSolver2( Cnf_Dat_t * p, int nFrames, int fInit );
1208 int i, nVars, * pVars, iCiVarBeg, iCoVarBeg = 1, nBTLimit = 100000;
1209 sat_solver * pSat = NULL;
1210 Cnf_Dat_t * pCnf = NULL;
1211 Vec_Ptr_t * vCexes = NULL;
1212 Abc_Ntk_t * pNtk1 = Io_Read( pFileName0, IO_FILE_VERILOG, 1, 0 );
1213 Abc_Ntk_t * pNtk2 = Io_Read( pFileName1, IO_FILE_VERILOG, 1, 0 );
1214 Abc_Ntk_t * pNtk1_ = Abc_NtkStrash( pNtk1, 1, 1, 0 );
1215 Abc_Ntk_t * pNtk2_ = Abc_NtkStrash( pNtk2, 1, 1, 0 );
1216 Abc_Ntk_t * pMiter = Abc_NtkMiter( pNtk1_, pNtk2_, 1, 0, 0, 1 );
1217 Gia_Man_t * pGia = Abc_NtkClpGia( pMiter );
1218 assert( Abc_NtkCiNum(pNtk1) == Abc_NtkCiNum(pNtk2) );
1219 assert( Abc_NtkCoNum(pNtk1) == Abc_NtkCoNum(pNtk2) );
1220 Abc_NtkDelete( pNtk1 );
1221 Abc_NtkDelete( pNtk2 );
1222 Abc_NtkDelete( pNtk1_ );
1223 Abc_NtkDelete( pNtk2_ );
1224 Abc_NtkDelete( pMiter );
1225 vCexes = Vec_PtrStart( Gia_ManPoNum(pGia) );
1226 pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( pGia, 8, 0, 0, 0, 0 );
1227 nVars = Gia_ManPiNum(pGia);
1228 iCiVarBeg = pCnf->nVars - nVars;
1229 pVars = ABC_ALLOC( int, nVars );
1230 for ( i = 0; i < nVars; i++ )
1231 pVars[i] = iCiVarBeg + i;
1232 pSat = (sat_solver *)Cnf_DataWriteIntoSolver(pCnf, 1, 0);
1233 Cnf_DataFree( pCnf );
1234 for ( i = 0; i < Gia_ManPoNum(pGia); i++ )
1235 {
1236 int Lit = Abc_Var2Lit( iCoVarBeg + i, 0 );
1237 int status = sat_solver_solve( pSat, &Lit, &Lit + 1, nBTLimit, 0, 0, 0 );
1238 assert( status != l_Undef );
1239 if ( status == l_False )
1240 continue;
1241 Vec_PtrWriteEntry( vCexes, i, Sat_SolverGetModel(pSat, pVars, nVars) );
1242 printf( "Output %3d (out of %3d) is SAT.\n", i, Gia_ManPoNum(pGia) );
1243 }
1244 Gia_ManStop( pGia );
1245 sat_solver_delete( pSat );
1246 ABC_FREE( pVars );
1247 return vCexes;
1248}
1249
1261Vec_Ptr_t * Abc_NtkReadNodeNames( Abc_Ntk_t * pNtk, char * pFileName )
1262{
1263 char Buffer[1000];
1264 Vec_Ptr_t * vNodes = NULL;
1265 FILE * pFile = fopen( pFileName, "rb" );
1266 if ( pFile == NULL )
1267 {
1268 printf( "Cannot open node list \"%s\".\n", pFileName );
1269 return NULL;
1270 }
1271 vNodes = Vec_PtrAlloc( 100 );
1272 while ( fgets(Buffer, 1000, pFile) != NULL )
1273 {
1274 char * pToken = strtok( Buffer, " \n\r\t" );
1275 while ( pToken )
1276 {
1277 Abc_Obj_t * pObj = Abc_NtkFindNode( pNtk, pToken );
1278 if ( pObj == NULL )
1279 {
1280 printf( "Cannot find node \"%s\".\n", pToken );
1281 Vec_PtrFree( vNodes );
1282 fclose( pFile );
1283 return NULL;
1284 }
1285 Vec_PtrPush( vNodes, pObj );
1286 pToken = strtok( NULL, " \n\r\t" );
1287 }
1288 }
1289 fclose( pFile );
1290 return vNodes;
1291}
1292
1304Abc_Obj_t * Abc_NtkSpecialMuxTree_rec( Abc_Ntk_t * pNew, Abc_Obj_t ** pCtrl, int nCtrl, Abc_Obj_t ** pData, int Shift )
1305{
1306 Abc_Obj_t * pLit0, * pLit1;
1307 if ( nCtrl == 0 )
1308 return pData[Shift];
1309 pLit0 = Abc_NtkSpecialMuxTree_rec( pNew, pCtrl, nCtrl-1, pData, Shift );
1310 pLit1 = Abc_NtkSpecialMuxTree_rec( pNew, pCtrl, nCtrl-1, pData, Shift + (1<<(nCtrl-1)) );
1311 return Abc_NtkCreateNodeMux( pNew, pCtrl[nCtrl-1], pLit1, pLit0 );
1312}
1314{
1315 Abc_Ntk_t * pNtkNew;
1316 Abc_Obj_t * pObj, * pFanin, * pObjNew, * pPoNew; char * pName;
1317 Vec_Int_t * vFirsts = Vec_IntAlloc( Vec_PtrSize(vNodes) );
1318 Vec_Ptr_t * vNames = Vec_PtrAlloc( 100 );
1319 Vec_Ptr_t * vFanins = Vec_PtrAlloc( 100 );
1320 Vec_Ptr_t * vDatas = Vec_PtrAlloc( 100 );
1321 Vec_Ptr_t * vDfs = Abc_NtkDfs( pNtk, 1 );
1322 Vec_Ptr_t * vCopies = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
1323 int i, k, Index, First, nNewPis = 0;
1324 // count the number of additional inputs
1325 Abc_NtkCleanCopy( pNtk );
1326 Abc_NtkCleanMarkA( pNtk );
1327 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
1328 {
1329 char Buffer[1000];
1330 assert( Abc_ObjIsNode(pObj) );
1331 pObj->fMarkA = 1;
1332 Vec_IntPush( vFirsts, nNewPis );
1333 nNewPis += 1 << Abc_ObjFaninNum(pObj);
1334 for ( k = 0; k < (1 << Abc_ObjFaninNum(pObj)); k++ )
1335 {
1336 sprintf( Buffer, "pi_%s_%d", Abc_ObjName(pObj), k );
1337 Vec_PtrPush( vNames, Abc_UtilStrsav(Buffer) );
1338 }
1339 }
1340 // create new network with the additional PIs
1341 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
1342 pNtkNew->pName = Extra_UtilStrsav( "miter" );
1343 Vec_PtrForEachEntry( char *, vNames, pName, i )
1344 Abc_ObjAssignName( Abc_NtkCreatePi(pNtkNew), pName, NULL );
1345 // duplicate PIs
1346 Abc_NtkForEachCi( pNtk, pObj, i )
1347 pObj->pCopy = Abc_NtkDupObj( pNtkNew, pObj, 1 );
1348 // copy nodes
1349 Vec_PtrForEachEntry( Abc_Obj_t *, vDfs, pObj, i )
1350 {
1351 if ( !pObj->fMarkA )
1352 {
1353 Abc_NtkDupObj( pNtkNew, pObj, 1 );
1354 Abc_ObjForEachFanin( pObj, pFanin, k )
1355 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
1356 Vec_PtrWriteEntry( vCopies, pObj->Id, pObj->pCopy );
1357 continue;
1358 }
1359 Vec_PtrClear( vFanins );
1360 Abc_ObjForEachFanin( pObj, pFanin, k )
1361 Vec_PtrPush( vFanins, pFanin->pCopy );
1362 Index = Vec_PtrFind( vNodes, pObj );
1363 assert( Index >= 0 );
1364 First = Vec_IntEntry( vFirsts, Index );
1365 Vec_PtrClear( vDatas );
1366 for ( k = 0; k < (1 << Abc_ObjFaninNum(pObj)); k++ )
1367 Vec_PtrPush( vDatas, Abc_NtkCi(pNtkNew, First + k) );
1368 pObj->pCopy = Abc_NtkSpecialMuxTree_rec( pNtkNew,
1369 (Abc_Obj_t **)Vec_PtrArray(vFanins), Vec_PtrSize(vFanins),
1370 (Abc_Obj_t **)Vec_PtrArray(vDatas), 0 );
1371 Vec_PtrWriteEntry( vCopies, pObj->Id, pObj->pCopy );
1372 }
1373 Vec_PtrForEachEntry( Abc_Obj_t *, vDfs, pObj, i )
1374 {
1375 pObj->fMarkA = 0;
1376 Abc_NtkDupObj( pNtkNew, pObj, 0 );
1377 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), "_copy" );
1378 Abc_ObjForEachFanin( pObj, pFanin, k )
1379 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
1380 }
1381 // create miter
1382 Vec_PtrClear( vDatas );
1383 Abc_NtkForEachCo( pNtk, pObj, i )
1384 {
1385 Vec_PtrClear( vFanins );
1386 Vec_PtrPush( vFanins, Abc_ObjFanin0(pObj)->pCopy );
1387 Vec_PtrPush( vFanins, (Abc_Obj_t *)Vec_PtrEntry(vCopies, Abc_ObjId(Abc_ObjFanin0(pObj))) );
1388 Vec_PtrPush( vDatas, Abc_NtkCreateNodeExor(pNtkNew, vFanins) );
1389 }
1390 if ( Vec_PtrSize(vDatas) > 1 )
1391 pObjNew = Abc_NtkCreateNodeOr( pNtkNew, vDatas );
1392 else
1393 pObjNew = (Abc_Obj_t *)Vec_PtrEntry(vDatas, 0);
1394 Abc_ObjAddFanin( (pPoNew = Abc_NtkCreatePo(pNtkNew)), pObjNew );
1395 Abc_ObjAssignName( pPoNew, "miter_output", NULL );
1396 // cleanup
1397 Vec_IntFree( vFirsts );
1398 Vec_PtrFreeFree( vNames );
1399 Vec_PtrFree( vFanins );
1400 Vec_PtrFree( vDatas );
1401 Vec_PtrFree( vDfs );
1402 Vec_PtrFree( vCopies );
1403 return pNtkNew;
1404}
1405
1409
1410
1412
Abc_Ntk_t * Abc_NtkFrames2(Abc_Ntk_t *pNtk, int nFrames, int fInitial, AddFrameMapping addFrameMapping, void *arg)
Definition abcMiter.c:909
Abc_Ntk_t * Abc_NtkMiterQuantifyPis(Abc_Ntk_t *pNtk)
Definition abcMiter.c:648
Abc_Obj_t * Abc_NtkSpecialMuxTree_rec(Abc_Ntk_t *pNew, Abc_Obj_t **pCtrl, int nCtrl, Abc_Obj_t **pData, int Shift)
Definition abcMiter.c:1304
Abc_Ntk_t * Abc_NtkMiterCofactor(Abc_Ntk_t *pNtk, Vec_Int_t *vPiValues)
Definition abcMiter.c:450
Abc_Ntk_t * Abc_NtkMiterForCofactors(Abc_Ntk_t *pNtk, int Out, int In1, int In2)
Definition abcMiter.c:517
void Abc_NtkMiterAddCone(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkMiter, Abc_Obj_t *pRoot)
Definition abcMiter.c:254
Abc_Ntk_t * Abc_NtkMiterQuantify(Abc_Ntk_t *pNtk, int In, int fExist)
Definition abcMiter.c:585
Vec_Ptr_t * Abc_NtkTryNewMiter(char *pFileName0, char *pFileName1)
Definition abcMiter.c:1205
Abc_Ntk_t * Abc_NtkMiterAnd(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fOr, int fCompl2)
Definition abcMiter.c:387
Abc_Ntk_t * Abc_NtkFrames(Abc_Ntk_t *pNtk, int nFrames, int fInitial, int fVerbose)
Definition abcMiter.c:775
int Abc_NtkDemiter(Abc_Ntk_t *pNtk)
Definition abcMiter.c:1087
int Abc_NtkMiterIsConstant(Abc_Ntk_t *pMiter)
Definition abcMiter.c:682
Abc_Ntk_t * Abc_NtkSpecialMiter(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes)
Definition abcMiter.c:1313
int Abc_NtkCombinePos(Abc_Ntk_t *pNtk, int fAnd, int fXor)
Definition abcMiter.c:1155
void(* AddFrameMapping)(Abc_Obj_t *, Abc_Obj_t *, int, void *)
Definition abcMiter.c:40
void Abc_NtkMiterReport(Abc_Ntk_t *pMiter)
Definition abcMiter.c:727
Vec_Ptr_t * Abc_NtkReadNodeNames(Abc_Ntk_t *pNtk, char *pFileName)
Definition abcMiter.c:1261
Abc_Ntk_t * Abc_NtkMiter(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fComb, int nPartSize, int fImplic, int fMulti)
FUNCTION DEFINITIONS ///.
Definition abcMiter.c:59
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
Definition abcUtil.c:696
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Abc_Obj_t * Abc_NtkFindNode(Abc_Ntk_t *pNtk, char *pName)
Definition abcObj.c:464
ABC_DLL int Abc_NtkIsDfsOrdered(Abc_Ntk_t *pNtk)
Definition abcDfs.c:698
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Obj_t * Abc_AigXor(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:735
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition abcObj.c:170
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition abc.h:488
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition abcObj.c:342
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
ABC_DLL Gia_Man_t * Abc_NtkClpGia(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition abcUtil.c:463
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeOr(Abc_Ntk_t *pNtk, Vec_Ptr_t *vFanins)
Definition abcObj.c:770
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
@ ABC_NTK_STRASH
Definition abc.h:58
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition abcAig.c:194
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeMux(Abc_Ntk_t *pNtk, Abc_Obj_t *pNodeC, Abc_Obj_t *pNode1, Abc_Obj_t *pNode0)
Definition abcObj.c:834
ABC_DLL Abc_Obj_t * Abc_AigOr(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:719
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition abcStrash.c:265
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeExor(Abc_Ntk_t *pNtk, Vec_Ptr_t *vFanins)
Definition abcObj.c:802
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition abcDfs.c:151
ABC_DLL Abc_Obj_t * Abc_AigMiter(Abc_Aig_t *pMan, Vec_Ptr_t *vPairs, int fImplic)
Definition abcAig.c:789
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
@ ABC_FUNC_AIG
Definition abc.h:67
ABC_DLL int Abc_NtkCompareSignals(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fOnlyPis, int fComb)
Definition abcCheck.c:749
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
Definition abcUtil.c:1430
ABC_DLL void Abc_NtkOrderCisCos(Abc_Ntk_t *pNtk)
Definition abcUtil.c:76
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
ABC_DLL int Abc_NodeIsExorType(Abc_Obj_t *pNode)
Definition abcUtil.c:1300
ABC_DLL Abc_Obj_t * Abc_NtkDupBox(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pBox, int fCopyName)
Definition abcObj.c:415
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#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
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
void * Cnf_DataWriteIntoSolver2(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:595
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_UtilStrsav(const char *s)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
Definition giaMf.c:1877
@ IO_FILE_VERILOG
Definition ioAbc.h:67
Abc_Ntk_t * Io_Read(char *pFileName, Io_FileType_t FileType, int fCheck, int fBarBufs)
Definition ioUtil.c:241
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
Definition satUtil.c:270
Abc_NtkType_t ntkType
Definition abc.h:156
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
Abc_NtkFunc_t ntkFunc
Definition abc.h:157
int Id
Definition abc.h:132
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
int nVars
Definition cnf.h:59
#define assert(ex)
Definition util_old.h:213
char * sprintf()
char * strtok()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55