ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
saigPhase.c
Go to the documentation of this file.
1
20
21#include "saig.h"
22
24
25
26/*
27 The algorithm is described in the paper: Per Bjesse and Jim Kukula,
28 "Automatic Phase Abstraction for Formal Verification", ICCAD 2005
29 http://www.iccad.com/data2/iccad/iccad_05acceptedpapers.nsf/9cfb1ebaaf59043587256a6a00031f78/1701ecf34b149e958725702f00708828?OpenDocument
30*/
31
32// the maximum number of cycles of termiry simulation
33#define TSIM_MAX_ROUNDS 10000
34#define TSIM_ONE_SERIES 3000
35
36#define SAIG_XVS0 1
37#define SAIG_XVS1 2
38#define SAIG_XVSX 3
39
40static inline int Saig_XsimConvertValue( int v ) { return v == 0? SAIG_XVS0 : (v == 1? SAIG_XVS1 : (v == 2? SAIG_XVSX : -1)); }
41
42static inline void Saig_ObjSetXsim( Aig_Obj_t * pObj, int Value ) { pObj->nCuts = Value; }
43static inline int Saig_ObjGetXsim( Aig_Obj_t * pObj ) { return pObj->nCuts; }
44static inline int Saig_XsimInv( int Value )
45{
46 if ( Value == SAIG_XVS0 )
47 return SAIG_XVS1;
48 if ( Value == SAIG_XVS1 )
49 return SAIG_XVS0;
50 assert( Value == SAIG_XVSX );
51 return SAIG_XVSX;
52}
53static inline int Saig_XsimAnd( int Value0, int Value1 )
54{
55 if ( Value0 == SAIG_XVS0 || Value1 == SAIG_XVS0 )
56 return SAIG_XVS0;
57 if ( Value0 == SAIG_XVSX || Value1 == SAIG_XVSX )
58 return SAIG_XVSX;
59 assert( Value0 == SAIG_XVS1 && Value1 == SAIG_XVS1 );
60 return SAIG_XVS1;
61}
62static inline int Saig_XsimRand2()
63{
64 return (Aig_ManRandom(0) & 1) ? SAIG_XVS1 : SAIG_XVS0;
65}
66static inline int Saig_XsimRand3()
67{
68 int RetValue;
69 do {
70 RetValue = Aig_ManRandom(0) & 3;
71 } while ( RetValue == 0 );
72 return RetValue;
73}
74static inline int Saig_ObjGetXsimFanin0( Aig_Obj_t * pObj )
75{
76 int RetValue;
77 RetValue = Saig_ObjGetXsim(Aig_ObjFanin0(pObj));
78 return Aig_ObjFaninC0(pObj)? Saig_XsimInv(RetValue) : RetValue;
79}
80static inline int Saig_ObjGetXsimFanin1( Aig_Obj_t * pObj )
81{
82 int RetValue;
83 RetValue = Saig_ObjGetXsim(Aig_ObjFanin1(pObj));
84 return Aig_ObjFaninC1(pObj)? Saig_XsimInv(RetValue) : RetValue;
85}
86static inline void Saig_XsimPrint( FILE * pFile, int Value )
87{
88 if ( Value == SAIG_XVS0 )
89 {
90 fprintf( pFile, "0" );
91 return;
92 }
93 if ( Value == SAIG_XVS1 )
94 {
95 fprintf( pFile, "1" );
96 return;
97 }
98 assert( Value == SAIG_XVSX );
99 fprintf( pFile, "x" );
100}
101
102// simulation manager
105{
106 Aig_Man_t * pAig; // the original AIG manager
107 int nWords; // the number of words in the states
108 // ternary state representation
109 Vec_Ptr_t * vStates; // the collection of ternary states
110 Aig_MmFixed_t * pMem; // memory for ternary states
111 int nPrefix; // prefix of the ternary state space
112 int nCycle; // cycle of the ternary state space
113 int nNonXRegs; // the number of candidate registers
114 Vec_Int_t * vNonXRegs; // the candidate registers
115 // hash table for terminary states
116 unsigned ** pBins;
117 int nBins;
118};
119
120static inline unsigned * Saig_TsiNext( unsigned * pState, int nWords ) { return *((unsigned **)(pState + nWords)); }
121static inline void Saig_TsiSetNext( unsigned * pState, int nWords, unsigned * pNext ) { *((unsigned **)(pState + nWords)) = pNext; }
122
126
130
143{
144 Saig_Tsim_t * p;
145 p = (Saig_Tsim_t *)ABC_ALLOC( char, sizeof(Saig_Tsim_t) );
146 memset( p, 0, sizeof(Saig_Tsim_t) );
147 p->pAig = pAig;
148 p->nWords = Abc_BitWordNum( 2*Aig_ManRegNum(pAig) );
149 p->vStates = Vec_PtrAlloc( 1000 );
150 p->pMem = Aig_MmFixedStart( sizeof(unsigned) * p->nWords + sizeof(unsigned *), 10000 );
151 p->nBins = Abc_PrimeCudd(TSIM_MAX_ROUNDS/2);
152 p->pBins = ABC_ALLOC( unsigned *, p->nBins );
153 memset( p->pBins, 0, sizeof(unsigned *) * p->nBins );
154 return p;
155}
156
169{
170 if ( p->vNonXRegs )
171 Vec_IntFree( p->vNonXRegs );
172 Aig_MmFixedStop( p->pMem, 0 );
173 Vec_PtrFree( p->vStates );
174 ABC_FREE( p->pBins );
175 ABC_FREE( p );
176}
177
189int Saig_TsiStateHash( unsigned * pState, int nWords, int nTableSize )
190{
191 static int s_FPrimes[128] = {
192 1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
193 1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997,
194 2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543,
195 2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089,
196 3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671,
197 3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243,
198 4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871,
199 4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471,
200 5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073,
201 6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689,
202 6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309,
203 7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933,
204 8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
205 };
206 unsigned uHash;
207 int i;
208 uHash = 0;
209 for ( i = 0; i < nWords; i++ )
210 uHash ^= pState[i] * s_FPrimes[i & 0x7F];
211 return uHash % nTableSize;
212}
213
226{
227 unsigned * pState;
228 int nRegs = p->pAig->nRegs;
229 int Value, i, k;
230 assert( p->vNonXRegs == NULL );
231 p->vNonXRegs = Vec_IntAlloc( 10 );
232 for ( i = 0; i < nRegs; i++ )
233 {
234 Vec_PtrForEachEntryStart( unsigned *, p->vStates, pState, k, nPref )
235 {
236 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
237 assert( Value != 0 );
238 if ( Value == SAIG_XVSX )
239 break;
240 }
241 if ( k == Vec_PtrSize(p->vStates) )
242 Vec_IntPush( p->vNonXRegs, i );
243 }
244 return Vec_IntSize(p->vNonXRegs);
245}
246
259{
260 Vec_Int_t * vCounters;
261 unsigned * pState;
262 int ValueThis = -1, ValuePrev = -1, StepPrev = -1;
263 int i, k, nRegs = p->pAig->nRegs;
264 vCounters = Vec_IntStart( nPref );
265 for ( i = 0; i < nRegs; i++ )
266 {
267 Vec_PtrForEachEntry( unsigned *, p->vStates, pState, k )
268 {
269 ValueThis = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
270//printf( "%s", (ValueThis == 1)? "0" : ((ValueThis == 2)? "1" : "x") );
271 assert( ValueThis != 0 );
272 if ( ValuePrev != ValueThis )
273 {
274 ValuePrev = ValueThis;
275 StepPrev = k;
276 }
277 }
278//printf( "\n" );
279 if ( ValueThis == SAIG_XVSX )
280 continue;
281 if ( StepPrev >= nPref )
282 continue;
283 Vec_IntAddToEntry( vCounters, StepPrev, 1 );
284 }
285 Vec_IntForEachEntry( vCounters, ValueThis, i )
286 {
287 if ( ValueThis == 0 )
288 continue;
289// printf( "%3d : %3d\n", i, ValueThis );
290 }
291 return vCounters;
292}
293
305void Saig_TsiPrintTraces( Saig_Tsim_t * p, int nWords, int nPrefix, int nLoop )
306{
307 unsigned * pState;
308 int nRegs = p->pAig->nRegs;
309 int Value, i, k, Counter = 0;
310 printf( "Ternary traces for each flop:\n" );
311 printf( " : " );
312 for ( i = 0; i < Vec_PtrSize(p->vStates) - nLoop - 1; i++ )
313 printf( "%d", i%10 );
314 printf( " " );
315 for ( i = 0; i < nLoop; i++ )
316 printf( "%d", i%10 );
317 printf( "\n" );
318 for ( i = 0; i < nRegs; i++ )
319 {
320/*
321 Vec_PtrForEachEntry( unsigned *, p->vStates, pState, k )
322 {
323 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
324 if ( Value == SAIG_XVSX )
325 break;
326 }
327 if ( k == Vec_PtrSize(p->vStates) )
328 Counter++;
329 else
330 continue;
331*/
332
333 // print trace
334// printf( "%5d : %5d %5d ", Counter, i, Saig_ManLo(p->pAig, i)->Id );
335 printf( "%5d : ", Counter++ );
336 Vec_PtrForEachEntryStop( unsigned *, p->vStates, pState, k, Vec_PtrSize(p->vStates)-1 )
337 {
338 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
339 if ( Value == SAIG_XVS0 )
340 printf( "0" );
341 else if ( Value == SAIG_XVS1 )
342 printf( "1" );
343 else if ( Value == SAIG_XVSX )
344 printf( "x" );
345 else
346 assert( 0 );
347 if ( k == nPrefix - 1 )
348 printf( " " );
349 }
350 printf( "\n" );
351 }
352}
353
365int Saig_TsiComputePrefix( Saig_Tsim_t * p, unsigned * pState, int nWords )
366{
367 unsigned * pEntry, * pPrev;
368 int Hash, i;
369 Hash = Saig_TsiStateHash( pState, nWords, p->nBins );
370 for ( pEntry = p->pBins[Hash]; pEntry; pEntry = Saig_TsiNext(pEntry, nWords) )
371 if ( !memcmp( pEntry, pState, sizeof(unsigned) * nWords ) )
372 {
373 Vec_PtrForEachEntry( unsigned *, p->vStates, pPrev, i )
374 {
375 if ( pPrev == pEntry )
376 return i;
377 }
378 assert( 0 );
379 return -1;
380 }
381 return -1;
382}
383
395int Saig_TsiStateLookup( Saig_Tsim_t * p, unsigned * pState, int nWords )
396{
397 unsigned * pEntry;
398 int Hash;
399 Hash = Saig_TsiStateHash( pState, nWords, p->nBins );
400 for ( pEntry = p->pBins[Hash]; pEntry; pEntry = Saig_TsiNext(pEntry, nWords) )
401 if ( !memcmp( pEntry, pState, sizeof(unsigned) * nWords ) )
402 return 1;
403 return 0;
404}
405
417void Saig_TsiStateInsert( Saig_Tsim_t * p, unsigned * pState, int nWords )
418{
419 int Hash = Saig_TsiStateHash( pState, nWords, p->nBins );
420 assert( !Saig_TsiStateLookup( p, pState, nWords ) );
421 Saig_TsiSetNext( pState, nWords, p->pBins[Hash] );
422 p->pBins[Hash] = pState;
423}
424
437{
438 unsigned * pState;
439 pState = (unsigned *)Aig_MmFixedEntryFetch( p->pMem );
440 memset( pState, 0, sizeof(unsigned) * p->nWords );
441 Vec_PtrPush( p->vStates, pState );
442 return pState;
443}
444
456void Saig_TsiStatePrint( Saig_Tsim_t * p, unsigned * pState )
457{
458 int i, Value, nZeros = 0, nOnes = 0, nDcs = 0;
459 for ( i = 0; i < Aig_ManRegNum(p->pAig); i++ )
460 {
461 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
462 if ( Value == SAIG_XVS0 )
463 printf( "0" ), nZeros++;
464 else if ( Value == SAIG_XVS1 )
465 printf( "1" ), nOnes++;
466 else if ( Value == SAIG_XVSX )
467 printf( "x" ), nDcs++;
468 else
469 assert( 0 );
470 }
471 printf( " (0=%5d, 1=%5d, x=%5d)\n", nZeros, nOnes, nDcs );
472}
473
485int Saig_TsiStateCount( Saig_Tsim_t * p, unsigned * pState )
486{
487 Aig_Obj_t * pObjLi, * pObjLo;
488 int i, Value, nCounter = 0;
489 Aig_ManForEachLiLoSeq( p->pAig, pObjLi, pObjLo, i )
490 {
491 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
492 nCounter += (Value == SAIG_XVS0 || Value == SAIG_XVS1);
493 }
494 return nCounter;
495}
496
508void Saig_TsiStateOrAll( Saig_Tsim_t * pTsi, unsigned * pState )
509{
510 unsigned * pPrev;
511 int i, k;
512 Vec_PtrForEachEntry( unsigned *, pTsi->vStates, pPrev, i )
513 {
514 for ( k = 0; k < pTsi->nWords; k++ )
515 pState[k] |= pPrev[k];
516 }
517}
518
532{
533 Saig_Tsim_t * pTsi;
534 Aig_Obj_t * pObj, * pObjLi, * pObjLo;
535 unsigned * pState;
536 int i, f, Value, nCounter;
537 // allocate the simulation manager
538 pTsi = Saig_TsiStart( p );
539 // initialize the values
540 Saig_ObjSetXsim( Aig_ManConst1(p), SAIG_XVS1 );
541 Saig_ManForEachPi( p, pObj, i )
542 Saig_ObjSetXsim( pObj, SAIG_XVSX );
543 if ( vInits )
544 {
545 Saig_ManForEachLo( p, pObj, i )
546 Saig_ObjSetXsim( pObj, Saig_XsimConvertValue(Vec_IntEntry(vInits, i)) );
547 }
548 else
549 {
550 Saig_ManForEachLo( p, pObj, i )
551 Saig_ObjSetXsim( pObj, SAIG_XVS0 );
552 }
553 // simulate for the given number of timeframes
554 for ( f = 0; f < TSIM_MAX_ROUNDS; f++ )
555 {
556 // collect this state
557 pState = Saig_TsiStateNew( pTsi );
558 Saig_ManForEachLiLo( p, pObjLi, pObjLo, i )
559 {
560 Value = Saig_ObjGetXsim(pObjLo);
561 if ( Value & 1 )
562 Abc_InfoSetBit( pState, 2 * i );
563 if ( Value & 2 )
564 Abc_InfoSetBit( pState, 2 * i + 1 );
565 }
566// printf( "%d ", Saig_TsiStateCount(pTsi, pState) );
567// Saig_TsiStatePrint( pTsi, pState );
568 // check if this state exists
569 if ( Saig_TsiStateLookup( pTsi, pState, pTsi->nWords ) )
570 {
571 if ( fVerbose )
572 printf( "Ternary simulation converged after %d iterations.\n", f );
573 return pTsi;
574 }
575 // insert this state
576 Saig_TsiStateInsert( pTsi, pState, pTsi->nWords );
577 // simulate internal nodes
578 Aig_ManForEachNode( p, pObj, i )
579 Saig_ObjSetXsim( pObj, Saig_XsimAnd(Saig_ObjGetXsimFanin0(pObj), Saig_ObjGetXsimFanin1(pObj)) );
580 // transfer the latch values
581 Saig_ManForEachLi( p, pObj, i )
582 Saig_ObjSetXsim( pObj, Saig_ObjGetXsimFanin0(pObj) );
583 nCounter = 0;
584 Saig_ManForEachLiLo( p, pObjLi, pObjLo, i )
585 {
586 if ( f < TSIM_ONE_SERIES )
587 Saig_ObjSetXsim( pObjLo, Saig_ObjGetXsim(pObjLi) );
588 else
589 {
590 if ( Saig_ObjGetXsim(pObjLi) != Saig_ObjGetXsim(pObjLo) )
591 Saig_ObjSetXsim( pObjLo, SAIG_XVSX );
592 }
593 nCounter += (Saig_ObjGetXsim(pObjLo) == SAIG_XVS0);
594 }
595 }
596 printf( "Saig_ManReachableTernary(): Did not reach a fixed point after %d iterations (not a bug).\n", TSIM_MAX_ROUNDS );
597 Saig_TsiStop( pTsi );
598 return NULL;
599}
600
613{
614 Aig_Obj_t * pObj, * pReg, * pCtrl, * pAnd;
615 int i;
616 pReg = Saig_ManLo( p, Reg );
617 pCtrl = Saig_ManLo( p, Saig_ManRegNum(p)-1 );
618 assert( pReg->Id < pCtrl->Id );
619 // find a node pointing to both
620 pAnd = NULL;
621 Aig_ManForEachNode( p, pObj, i )
622 {
623 if ( Aig_ObjFanin0(pObj) == pReg && Aig_ObjFanin1(pObj) == pCtrl )
624 {
625 pAnd = pObj;
626 break;
627 }
628 }
629 if ( pAnd == NULL )
630 {
631 printf( "Register is not found.\n" );
632 return;
633 }
634 printf( "Clock-like register: \n" );
635 Aig_ObjPrint( p, pReg );
636 printf( "\n" );
637 printf( "Control register: \n" );
638 Aig_ObjPrint( p, pCtrl );
639 printf( "\n" );
640 printf( "Their fanout: \n" );
641 Aig_ObjPrint( p, pAnd );
642 printf( "\n" );
643
644 // find the fanouts of pAnd
645 printf( "Fanouts of the fanout: \n" );
646 Aig_ManForEachObj( p, pObj, i )
647 if ( Aig_ObjFanin0(pObj) == pAnd || Aig_ObjFanin1(pObj) == pAnd )
648 {
649 Aig_ObjPrint( p, pObj );
650 printf( "\n" );
651 }
652 printf( "\n" );
653}
654
666int Saig_ManFindRegisters( Saig_Tsim_t * pTsi, int nFrames, int fIgnore, int fVerbose )
667{
668 int Values[257] = {0};
669 unsigned * pState;
670 int r, i, k, Reg, Value;
671 int nTests = pTsi->nPrefix + 2 * pTsi->nCycle;
672 assert( nFrames <= 256 );
673 r = 0;
674 Vec_IntForEachEntry( pTsi->vNonXRegs, Reg, i )
675 {
676 for ( k = 0; k < nTests; k++ )
677 {
678 if ( k < pTsi->nPrefix + pTsi->nCycle )
679 pState = (unsigned *)Vec_PtrEntry( pTsi->vStates, k );
680 else
681 pState = (unsigned *)Vec_PtrEntry( pTsi->vStates, k - pTsi->nCycle );
682 Value = (Abc_InfoHasBit( pState, 2 * Reg + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * Reg );
683 assert( Value == SAIG_XVS0 || Value == SAIG_XVS1 );
684 if ( k < nFrames || (fIgnore && k == nFrames) )
685 Values[k % nFrames] = Value;
686 else if ( Values[k % nFrames] != Value )
687 break;
688 }
689 if ( k < nTests )
690 continue;
691 // skip stuck at
692 if ( fIgnore )
693 {
694 for ( k = 1; k < nFrames; k++ )
695 if ( Values[k] != Values[0] )
696 break;
697 if ( k == nFrames )
698 continue;
699 }
700 // report useful register
701 Vec_IntWriteEntry( pTsi->vNonXRegs, r++, Reg );
702 if ( fVerbose )
703 {
704 printf( "Register %5d has generator: [", Reg );
705 for ( k = 0; k < nFrames; k++ )
706 Saig_XsimPrint( stdout, Values[k] );
707 printf( "]\n" );
708
709 if ( fVerbose )
710 Saig_ManAnalizeControl( pTsi->pAig, Reg );
711 }
712 }
713 Vec_IntShrink( pTsi->vNonXRegs, r );
714 if ( fVerbose )
715 printf( "Found %3d useful registers.\n", Vec_IntSize(pTsi->vNonXRegs) );
716 return Vec_IntSize(pTsi->vNonXRegs);
717}
718
719
731static inline Aig_Obj_t * Saig_ObjFrames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return pObjMap[nFs*pObj->Id + i]; }
732static inline void Saig_ObjSetFrames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i, Aig_Obj_t * pNode ) { pObjMap[nFs*pObj->Id + i] = pNode; }
733
734static inline Aig_Obj_t * Saig_ObjChild0Frames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return Aig_ObjFanin0(pObj)? Aig_NotCond(Saig_ObjFrames(pObjMap,nFs,Aig_ObjFanin0(pObj),i), Aig_ObjFaninC0(pObj)) : NULL; }
735static inline Aig_Obj_t * Saig_ObjChild1Frames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return Aig_ObjFanin1(pObj)? Aig_NotCond(Saig_ObjFrames(pObjMap,nFs,Aig_ObjFanin1(pObj),i), Aig_ObjFaninC1(pObj)) : NULL; }
736
748Aig_Man_t * Saig_ManPerformAbstraction( Saig_Tsim_t * pTsi, int nFrames, int fVerbose )
749{
750 Aig_Man_t * pFrames, * pAig = pTsi->pAig;
751 Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew;
752 Aig_Obj_t ** pObjMap;
753 unsigned * pState;
754 int i, f, Reg, Value;
755
756 assert( Vec_IntSize(pTsi->vNonXRegs) > 0 );
757
758 // create mapping for the frames nodes
759 pObjMap = ABC_ALLOC( Aig_Obj_t *, nFrames * Aig_ManObjNumMax(pAig) );
760 memset( pObjMap, 0, sizeof(Aig_Obj_t *) * nFrames * Aig_ManObjNumMax(pAig) );
761
762 // start the fraig package
763 pFrames = Aig_ManStart( Aig_ManObjNumMax(pAig) * nFrames );
764 pFrames->pName = Abc_UtilStrsav( pAig->pName );
765 pFrames->pSpec = Abc_UtilStrsav( pAig->pSpec );
766 // map constant nodes
767 for ( f = 0; f < nFrames; f++ )
768 Saig_ObjSetFrames( pObjMap, nFrames, Aig_ManConst1(pAig), f, Aig_ManConst1(pFrames) );
769 // create PI nodes for the frames
770 for ( f = 0; f < nFrames; f++ )
771 Aig_ManForEachPiSeq( pAig, pObj, i )
772 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, Aig_ObjCreateCi(pFrames) );
773 // create the latches
774 Aig_ManForEachLoSeq( pAig, pObj, i )
775 Saig_ObjSetFrames( pObjMap, nFrames, pObj, 0, Aig_ObjCreateCi(pFrames) );
776
777 // add timeframes
778 for ( f = 0; f < nFrames; f++ )
779 {
780 // replace abstracted registers by constants
781 Vec_IntForEachEntry( pTsi->vNonXRegs, Reg, i )
782 {
783 pObj = Saig_ManLo( pAig, Reg );
784 pState = (unsigned *)Vec_PtrEntry( pTsi->vStates, f );
785 Value = (Abc_InfoHasBit( pState, 2 * Reg + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * Reg );
786 assert( Value == SAIG_XVS0 || Value == SAIG_XVS1 );
787 pObjNew = (Value == SAIG_XVS1)? Aig_ManConst1(pFrames) : Aig_ManConst0(pFrames);
788 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, pObjNew );
789 }
790 // add internal nodes of this frame
791 Aig_ManForEachNode( pAig, pObj, i )
792 {
793 pObjNew = Aig_And( pFrames, Saig_ObjChild0Frames(pObjMap,nFrames,pObj,f), Saig_ObjChild1Frames(pObjMap,nFrames,pObj,f) );
794 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, pObjNew );
795 }
796 // set the latch inputs and copy them into the latch outputs of the next frame
797 Aig_ManForEachLiLoSeq( pAig, pObjLi, pObjLo, i )
798 {
799 pObjNew = Saig_ObjChild0Frames(pObjMap,nFrames,pObjLi,f);
800 if ( f < nFrames - 1 )
801 Saig_ObjSetFrames( pObjMap, nFrames, pObjLo, f+1, pObjNew );
802 }
803 }
804 for ( f = 0; f < nFrames; f++ )
805 {
806 Aig_ManForEachPoSeq( pAig, pObj, i )
807 {
808 pObjNew = Aig_ObjCreateCo( pFrames, Saig_ObjChild0Frames(pObjMap,nFrames,pObj,f) );
809 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, pObjNew );
810 }
811 }
812 pFrames->nRegs = pAig->nRegs;
813 pFrames->nTruePis = Aig_ManCiNum(pFrames) - Aig_ManRegNum(pFrames);
814 pFrames->nTruePos = Aig_ManCoNum(pFrames) - Aig_ManRegNum(pFrames);
815 Aig_ManForEachLiSeq( pAig, pObj, i )
816 {
817 pObjNew = Aig_ObjCreateCo( pFrames, Saig_ObjChild0Frames(pObjMap,nFrames,pObj,nFrames-1) );
818 Saig_ObjSetFrames( pObjMap, nFrames, pObj, nFrames-1, pObjNew );
819 }
820//Aig_ManPrintStats( pFrames );
821 Aig_ManSeqCleanup( pFrames );
822//Aig_ManPrintStats( pFrames );
823// Aig_ManCiCleanup( pFrames );
824//Aig_ManPrintStats( pFrames );
825 ABC_FREE( pObjMap );
826 return pFrames;
827}
828
829
842{
843 Saig_Tsim_t * pTsi;
844 int nFrames, nPrefix;
845 assert( Saig_ManRegNum(p) );
846 assert( Saig_ManPiNum(p) );
847 assert( Saig_ManPoNum(p) );
848 // perform terminary simulation
849 pTsi = Saig_ManReachableTernary( p, vInits, 0 );
850 if ( pTsi == NULL )
851 return 1;
852 // derive information
853 nPrefix = Saig_TsiComputePrefix( pTsi, (unsigned *)Vec_PtrEntryLast(pTsi->vStates), pTsi->nWords );
854 nFrames = Vec_PtrSize(pTsi->vStates) - 1 - nPrefix;
855 Saig_TsiStop( pTsi );
856 // potentially, may need to reduce nFrames if nPrefix is less than nFrames
857 return nFrames;
858}
859
871int Saig_ManPhasePrefixLength( Aig_Man_t * p, int fVerbose, int fVeryVerbose, Vec_Int_t ** pvTrans )
872{
873 Saig_Tsim_t * pTsi;
874 int nFrames, nPrefix, nNonXRegs;
875 assert( Saig_ManRegNum(p) );
876 assert( Saig_ManPiNum(p) );
877 assert( Saig_ManPoNum(p) );
878 // perform terminary simulation
879 pTsi = Saig_ManReachableTernary( p, NULL, 0 );
880 if ( pTsi == NULL )
881 return 0;
882 // derive information
883 nPrefix = Saig_TsiComputePrefix( pTsi, (unsigned *)Vec_PtrEntryLast(pTsi->vStates), pTsi->nWords );
884 nFrames = Vec_PtrSize(pTsi->vStates) - 1 - nPrefix;
885 nNonXRegs = Saig_TsiCountNonXValuedRegisters( pTsi, nPrefix );
886
887 if ( pvTrans )
888 *pvTrans = Saig_TsiComputeTransient( pTsi, nPrefix );
889
890 // print statistics
891 if ( fVerbose )
892 printf( "Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n", nPrefix, nFrames, p->nRegs, nNonXRegs );
893 if ( fVeryVerbose )
894 Saig_TsiPrintTraces( pTsi, pTsi->nWords, nPrefix, nFrames );
895 Saig_TsiStop( pTsi );
896 // potentially, may need to reduce nFrames if nPrefix is less than nFrames
897 return nPrefix;
898}
899
911Aig_Man_t * Saig_ManPhaseAbstract( Aig_Man_t * p, Vec_Int_t * vInits, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose )
912{
913 Aig_Man_t * pNew = NULL;
914 Saig_Tsim_t * pTsi;
915 assert( Saig_ManRegNum(p) );
916 assert( Saig_ManPiNum(p) );
917 assert( Saig_ManPoNum(p) );
918 // perform terminary simulation
919 pTsi = Saig_ManReachableTernary( p, vInits, fVerbose );
920 if ( pTsi == NULL )
921 return NULL;
922 // derive information
923 pTsi->nPrefix = Saig_TsiComputePrefix( pTsi, (unsigned *)Vec_PtrEntryLast(pTsi->vStates), pTsi->nWords );
924 pTsi->nCycle = Vec_PtrSize(pTsi->vStates) - 1 - pTsi->nPrefix;
925 pTsi->nNonXRegs = Saig_TsiCountNonXValuedRegisters(pTsi, Abc_MinInt(pTsi->nPrefix,nPref));
926 // print statistics
927 if ( fVerbose )
928 {
929 printf( "Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n",
930 pTsi->nPrefix, pTsi->nCycle, p->nRegs, pTsi->nNonXRegs );
931 if ( pTsi->nNonXRegs < 100 && Vec_PtrSize(pTsi->vStates) < 80 )
932 Saig_TsiPrintTraces( pTsi, pTsi->nWords, pTsi->nPrefix, pTsi->nCycle );
933 }
934 if ( fPrint )
935 printf( "Print-out finished. Phase assignment is not performed.\n" );
936 else if ( nFrames < 2 )
937 printf( "The number of frames is less than 2. Phase assignment is not performed.\n" );
938 else if ( nFrames > 256 )
939 printf( "The number of frames is more than 256. Phase assignment is not performed.\n" );
940 else if ( pTsi->nCycle == 1 )
941 printf( "The cycle of ternary states is trivial. Phase abstraction cannot be done.\n" );
942 else if ( pTsi->nCycle % nFrames != 0 )
943 printf( "The cycle (%d) is not modulo the number of frames (%d). Phase abstraction cannot be done.\n", pTsi->nCycle, nFrames );
944 else if ( pTsi->nNonXRegs == 0 )
945 printf( "All registers have X-valued states. Phase abstraction cannot be done.\n" );
946 else if ( !Saig_ManFindRegisters( pTsi, nFrames, fIgnore, fVerbose ) )
947 printf( "There is no registers to abstract with %d frames.\n", nFrames );
948 else
949 pNew = Saig_ManPerformAbstraction( pTsi, nFrames, fVerbose );
950 Saig_TsiStop( pTsi );
951 return pNew;
952}
953
966{
967 Aig_Man_t * pNew = NULL;
968 Saig_Tsim_t * pTsi;
969 int fPrint = 0;
970 int nFrames;
971 assert( Saig_ManRegNum(p) );
972 assert( Saig_ManPiNum(p) );
973 assert( Saig_ManPoNum(p) );
974 // perform terminary simulation
975 pTsi = Saig_ManReachableTernary( p, NULL, fVerbose );
976 if ( pTsi == NULL )
977 return NULL;
978 // derive information
979 pTsi->nPrefix = Saig_TsiComputePrefix( pTsi, (unsigned *)Vec_PtrEntryLast(pTsi->vStates), pTsi->nWords );
980 pTsi->nCycle = Vec_PtrSize(pTsi->vStates) - 1 - pTsi->nPrefix;
982 // print statistics
983 if ( fVerbose )
984 {
985 printf( "Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n",
986 pTsi->nPrefix, pTsi->nCycle, p->nRegs, pTsi->nNonXRegs );
987 if ( pTsi->nNonXRegs < 100 && Vec_PtrSize(pTsi->vStates) < 80 )
988 Saig_TsiPrintTraces( pTsi, pTsi->nWords, pTsi->nPrefix, pTsi->nCycle );
989 }
990 nFrames = pTsi->nCycle;
991 if ( fPrint )
992 {
993 printf( "Print-out finished. Phase assignment is not performed.\n" );
994 }
995 else if ( nFrames < 2 )
996 {
997// printf( "The number of frames is less than 2. Phase assignment is not performed.\n" );
998 }
999 else if ( nFrames > 256 )
1000 {
1001// printf( "The number of frames is more than 256. Phase assignment is not performed.\n" );
1002 }
1003 else if ( pTsi->nCycle == 1 )
1004 {
1005// printf( "The cycle of ternary states is trivial. Phase abstraction cannot be done.\n" );
1006 }
1007 else if ( pTsi->nCycle % nFrames != 0 )
1008 {
1009// printf( "The cycle (%d) is not modulo the number of frames (%d). Phase abstraction cannot be done.\n", pTsi->nCycle, nFrames );
1010 }
1011 else if ( pTsi->nNonXRegs == 0 )
1012 {
1013// printf( "All registers have X-valued states. Phase abstraction cannot be done.\n" );
1014 }
1015 else if ( !Saig_ManFindRegisters( pTsi, nFrames, 0, fVerbose ) )
1016 {
1017// printf( "There is no registers to abstract with %d frames.\n", nFrames );
1018 }
1019 else
1020 pNew = Saig_ManPerformAbstraction( pTsi, nFrames, fVerbose );
1021 Saig_TsiStop( pTsi );
1022 if ( pNew == NULL )
1023 pNew = Aig_ManDupSimple( p );
1024 if ( Aig_ManCiNum(pNew) == Aig_ManRegNum(pNew) )
1025 {
1026 Aig_ManStop( pNew);
1027 pNew = Aig_ManDupSimple( p );
1028 }
1029 return pNew;
1030}
1031
1032
1046{
1047 Abc_Cex_t * pNew;
1048 int i, k, iFrame, nFrames;
1049 // make sure the PI count of the AIG is a multiple of the PI count of the CEX
1050 // if this is not true, the CEX is not derived as the result of unrolling of pAig
1051 // or the unrolled CEX went through transformations that change the PI count
1052 if ( pCex->nPis % Saig_ManPiNum(p) != 0 )
1053 {
1054 printf( "The PI count in the AIG and in the CEX do not match.\n" );
1055 return NULL;
1056 }
1057 // get the number of unrolled frames
1058 nFrames = pCex->nPis / Saig_ManPiNum(p);
1059 // get the frame where it fails
1060 iFrame = pCex->iFrame * nFrames + pCex->iPo / Saig_ManPoNum(p);
1061 // start a new CEX (assigns: p->nRegs, p->nPis, p->nBits)
1062 pNew = Abc_CexAlloc( Saig_ManRegNum(p), Saig_ManPiNum(p), iFrame+1 );
1063 assert( pNew->nBits == pNew->nPis * (iFrame + 1) + pNew->nRegs );
1064 // now assign the failed frame and the failed PO (p->iFrame and p->iPo)
1065 pNew->iFrame = iFrame;
1066 pNew->iPo = pCex->iPo % Saig_ManPoNum(p);
1067 // copy the bit data
1068 for ( i = pCex->nRegs, k = pNew->nRegs; k < pNew->nBits; k++, i++ )
1069 if ( Abc_InfoHasBit( pCex->pData, i ) )
1070 Abc_InfoSetBit( pNew->pData, k );
1071 assert( i <= pCex->nBits );
1072 return pNew;
1073}
1074
1078
1079
1081
int nWords
Definition abcNpn.c:127
#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
int Aig_ManSeqCleanup(Aig_Man_t *p)
Definition aigScl.c:158
Aig_Man_t * Aig_ManDupSimple(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigDup.c:46
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
Definition aigMem.c:161
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
#define Aig_ManForEachLiSeq(p, pObj, i)
Definition aig.h:447
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition aigObj.c:66
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition aigMan.c:47
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define Aig_ManForEachPiSeq(p, pObj, i)
SEQUENTIAL ITERATORS ///.
Definition aig.h:438
Aig_MmFixed_t * Aig_MmFixedStart(int nEntrySize, int nEntriesMax)
FUNCTION DEFINITIONS ///.
Definition aigMem.c:96
#define Aig_ManForEachPoSeq(p, pObj, i)
Definition aig.h:444
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigObj.c:45
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition aig.h:441
struct Aig_MmFixed_t_ Aig_MmFixed_t
Definition aig.h:52
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition aigMem.c:132
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition aig.h:450
unsigned Aig_ManRandom(int fReset)
Definition aigUtil.c:1170
void Aig_ObjPrint(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigObj.c:316
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
int Saig_TsiStateCount(Saig_Tsim_t *p, unsigned *pState)
Definition saigPhase.c:485
void Saig_TsiPrintTraces(Saig_Tsim_t *p, int nWords, int nPrefix, int nLoop)
Definition saigPhase.c:305
Abc_Cex_t * Saig_PhaseTranslateCex(Aig_Man_t *p, Abc_Cex_t *pCex)
Definition saigPhase.c:1045
Saig_Tsim_t * Saig_ManReachableTernary(Aig_Man_t *p, Vec_Int_t *vInits, int fVerbose)
Definition saigPhase.c:531
int Saig_TsiStateHash(unsigned *pState, int nWords, int nTableSize)
Definition saigPhase.c:189
int Saig_TsiStateLookup(Saig_Tsim_t *p, unsigned *pState, int nWords)
Definition saigPhase.c:395
void Saig_ManAnalizeControl(Aig_Man_t *p, int Reg)
Definition saigPhase.c:612
Saig_Tsim_t * Saig_TsiStart(Aig_Man_t *pAig)
DECLARATIONS ///.
Definition saigPhase.c:142
#define SAIG_XVS1
Definition saigPhase.c:37
#define TSIM_MAX_ROUNDS
Definition saigPhase.c:33
Aig_Man_t * Saig_ManPhaseAbstract(Aig_Man_t *p, Vec_Int_t *vInits, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose)
Definition saigPhase.c:911
struct Saig_Tsim_t_ Saig_Tsim_t
Definition saigPhase.c:103
unsigned * Saig_TsiStateNew(Saig_Tsim_t *p)
Definition saigPhase.c:436
#define SAIG_XVSX
Definition saigPhase.c:38
Aig_Man_t * Saig_ManPhaseAbstractAuto(Aig_Man_t *p, int fVerbose)
Definition saigPhase.c:965
void Saig_TsiStateOrAll(Saig_Tsim_t *pTsi, unsigned *pState)
Definition saigPhase.c:508
int Saig_ManFindRegisters(Saig_Tsim_t *pTsi, int nFrames, int fIgnore, int fVerbose)
Definition saigPhase.c:666
#define SAIG_XVS0
Definition saigPhase.c:36
Vec_Int_t * Saig_TsiComputeTransient(Saig_Tsim_t *p, int nPref)
Definition saigPhase.c:258
int Saig_ManPhasePrefixLength(Aig_Man_t *p, int fVerbose, int fVeryVerbose, Vec_Int_t **pvTrans)
Definition saigPhase.c:871
#define TSIM_ONE_SERIES
Definition saigPhase.c:34
Aig_Man_t * Saig_ManPerformAbstraction(Saig_Tsim_t *pTsi, int nFrames, int fVerbose)
Definition saigPhase.c:748
int Saig_TsiComputePrefix(Saig_Tsim_t *p, unsigned *pState, int nWords)
Definition saigPhase.c:365
int Saig_TsiCountNonXValuedRegisters(Saig_Tsim_t *p, int nPref)
Definition saigPhase.c:225
void Saig_TsiStateInsert(Saig_Tsim_t *p, unsigned *pState, int nWords)
Definition saigPhase.c:417
int Saig_ManPhaseFrameNum(Aig_Man_t *p, Vec_Int_t *vInits)
Definition saigPhase.c:841
void Saig_TsiStop(Saig_Tsim_t *p)
Definition saigPhase.c:168
void Saig_TsiStatePrint(Saig_Tsim_t *p, unsigned *pState)
Definition saigPhase.c:456
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition saig.h:101
#define Saig_ManForEachLi(p, pObj, i)
Definition saig.h:98
#define Saig_ManForEachLo(p, pObj, i)
Definition saig.h:96
#define Saig_ManForEachPi(p, pObj, i)
Definition saig.h:91
int Id
Definition aig.h:85
unsigned nCuts
Definition aig.h:83
Vec_Int_t * vNonXRegs
Definition saigPhase.c:114
unsigned ** pBins
Definition saigPhase.c:116
Aig_Man_t * pAig
Definition saigPhase.c:106
Aig_MmFixed_t * pMem
Definition saigPhase.c:110
Vec_Ptr_t * vStates
Definition saigPhase.c:109
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition utilCex.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition utilCex.h:39
#define assert(ex)
Definition util_old.h:213
char * memset()
int memcmp()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
Definition vecPtr.h:59
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