33#define TSIM_MAX_ROUNDS 10000
34#define TSIM_ONE_SERIES 3000
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 )
53static inline int Saig_XsimAnd(
int Value0,
int Value1 )
62static inline int Saig_XsimRand2()
66static inline int Saig_XsimRand3()
71 }
while ( RetValue == 0 );
74static inline int Saig_ObjGetXsimFanin0(
Aig_Obj_t * pObj )
77 RetValue = Saig_ObjGetXsim(Aig_ObjFanin0(pObj));
78 return Aig_ObjFaninC0(pObj)? Saig_XsimInv(RetValue) : RetValue;
80static inline int Saig_ObjGetXsimFanin1(
Aig_Obj_t * pObj )
83 RetValue = Saig_ObjGetXsim(Aig_ObjFanin1(pObj));
84 return Aig_ObjFaninC1(pObj)? Saig_XsimInv(RetValue) : RetValue;
86static inline void Saig_XsimPrint( FILE * pFile,
int Value )
90 fprintf( pFile,
"0" );
95 fprintf( pFile,
"1" );
99 fprintf( pFile,
"x" );
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; }
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 );
153 memset(
p->pBins, 0,
sizeof(
unsigned *) *
p->nBins );
171 Vec_IntFree(
p->vNonXRegs );
173 Vec_PtrFree(
p->vStates );
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
209 for ( i = 0; i <
nWords; i++ )
210 uHash ^= pState[i] * s_FPrimes[i & 0x7F];
211 return uHash % nTableSize;
228 int nRegs =
p->pAig->nRegs;
230 assert(
p->vNonXRegs == NULL );
231 p->vNonXRegs = Vec_IntAlloc( 10 );
232 for ( i = 0; i < nRegs; i++ )
236 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
241 if ( k == Vec_PtrSize(
p->vStates) )
242 Vec_IntPush(
p->vNonXRegs, i );
244 return Vec_IntSize(
p->vNonXRegs);
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++ )
269 ValueThis = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
272 if ( ValuePrev != ValueThis )
274 ValuePrev = ValueThis;
281 if ( StepPrev >= nPref )
283 Vec_IntAddToEntry( vCounters, StepPrev, 1 );
287 if ( ValueThis == 0 )
308 int nRegs =
p->pAig->nRegs;
309 int Value, i, k, Counter = 0;
310 printf(
"Ternary traces for each flop:\n" );
312 for ( i = 0; i < Vec_PtrSize(
p->vStates) - nLoop - 1; i++ )
313 printf(
"%d", i%10 );
315 for ( i = 0; i < nLoop; i++ )
316 printf(
"%d", i%10 );
318 for ( i = 0; i < nRegs; i++ )
335 printf(
"%5d : ", Counter++ );
338 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
347 if ( k == nPrefix - 1 )
367 unsigned * pEntry, * pPrev;
370 for ( pEntry =
p->pBins[Hash]; pEntry; pEntry = Saig_TsiNext(pEntry,
nWords) )
371 if ( !
memcmp( pEntry, pState,
sizeof(
unsigned) *
nWords ) )
375 if ( pPrev == pEntry )
400 for ( pEntry =
p->pBins[Hash]; pEntry; pEntry = Saig_TsiNext(pEntry,
nWords) )
401 if ( !
memcmp( pEntry, pState,
sizeof(
unsigned) *
nWords ) )
421 Saig_TsiSetNext( pState,
nWords,
p->pBins[Hash] );
422 p->pBins[Hash] = pState;
440 memset( pState, 0,
sizeof(
unsigned) *
p->nWords );
441 Vec_PtrPush(
p->vStates, pState );
458 int i, Value, nZeros = 0, nOnes = 0, nDcs = 0;
459 for ( i = 0; i < Aig_ManRegNum(
p->pAig); i++ )
461 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
463 printf(
"0" ), nZeros++;
465 printf(
"1" ), nOnes++;
467 printf(
"x" ), nDcs++;
471 printf(
" (0=%5d, 1=%5d, x=%5d)\n", nZeros, nOnes, nDcs );
488 int i, Value, nCounter = 0;
491 Value = (Abc_InfoHasBit( pState, 2 * i + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * i );
514 for ( k = 0; k < pTsi->
nWords; k++ )
515 pState[k] |= pPrev[k];
536 int i, f, Value, nCounter;
540 Saig_ObjSetXsim( Aig_ManConst1(
p),
SAIG_XVS1 );
546 Saig_ObjSetXsim( pObj, Saig_XsimConvertValue(Vec_IntEntry(vInits, i)) );
560 Value = Saig_ObjGetXsim(pObjLo);
562 Abc_InfoSetBit( pState, 2 * i );
564 Abc_InfoSetBit( pState, 2 * i + 1 );
572 printf(
"Ternary simulation converged after %d iterations.\n", f );
579 Saig_ObjSetXsim( pObj, Saig_XsimAnd(Saig_ObjGetXsimFanin0(pObj), Saig_ObjGetXsimFanin1(pObj)) );
582 Saig_ObjSetXsim( pObj, Saig_ObjGetXsimFanin0(pObj) );
587 Saig_ObjSetXsim( pObjLo, Saig_ObjGetXsim(pObjLi) );
590 if ( Saig_ObjGetXsim(pObjLi) != Saig_ObjGetXsim(pObjLo) )
593 nCounter += (Saig_ObjGetXsim(pObjLo) ==
SAIG_XVS0);
596 printf(
"Saig_ManReachableTernary(): Did not reach a fixed point after %d iterations (not a bug).\n",
TSIM_MAX_ROUNDS );
614 Aig_Obj_t * pObj, * pReg, * pCtrl, * pAnd;
616 pReg = Saig_ManLo(
p, Reg );
617 pCtrl = Saig_ManLo(
p, Saig_ManRegNum(
p)-1 );
623 if ( Aig_ObjFanin0(pObj) == pReg && Aig_ObjFanin1(pObj) == pCtrl )
631 printf(
"Register is not found.\n" );
634 printf(
"Clock-like register: \n" );
637 printf(
"Control register: \n" );
640 printf(
"Their fanout: \n" );
645 printf(
"Fanouts of the fanout: \n" );
647 if ( Aig_ObjFanin0(pObj) == pAnd || Aig_ObjFanin1(pObj) == pAnd )
668 int Values[257] = {0};
670 int r, i, k, Reg, Value;
676 for ( k = 0; k < nTests; k++ )
678 if ( k < pTsi->nPrefix + pTsi->
nCycle )
679 pState = (
unsigned *)Vec_PtrEntry( pTsi->
vStates, k );
681 pState = (
unsigned *)Vec_PtrEntry( pTsi->
vStates, k - pTsi->
nCycle );
682 Value = (Abc_InfoHasBit( pState, 2 * Reg + 1 ) << 1) | Abc_InfoHasBit( pState, 2 * Reg );
684 if ( k < nFrames || (fIgnore && k == nFrames) )
685 Values[k % nFrames] = Value;
686 else if ( Values[k % nFrames] != Value )
694 for ( k = 1; k < nFrames; k++ )
695 if ( Values[k] != Values[0] )
701 Vec_IntWriteEntry( pTsi->
vNonXRegs, r++, Reg );
704 printf(
"Register %5d has generator: [", Reg );
705 for ( k = 0; k < nFrames; k++ )
706 Saig_XsimPrint( stdout, Values[k] );
715 printf(
"Found %3d useful registers.\n", Vec_IntSize(pTsi->
vNonXRegs) );
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; }
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; }
751 Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew;
754 int i, f, Reg, Value;
760 memset( pObjMap, 0,
sizeof(
Aig_Obj_t *) * nFrames * Aig_ManObjNumMax(pAig) );
763 pFrames =
Aig_ManStart( Aig_ManObjNumMax(pAig) * nFrames );
764 pFrames->pName = Abc_UtilStrsav( pAig->pName );
765 pFrames->pSpec = Abc_UtilStrsav( pAig->pSpec );
767 for ( f = 0; f < nFrames; f++ )
768 Saig_ObjSetFrames( pObjMap, nFrames, Aig_ManConst1(pAig), f, Aig_ManConst1(pFrames) );
770 for ( f = 0; f < nFrames; f++ )
772 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f,
Aig_ObjCreateCi(pFrames) );
775 Saig_ObjSetFrames( pObjMap, nFrames, pObj, 0,
Aig_ObjCreateCi(pFrames) );
778 for ( f = 0; f < nFrames; f++ )
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 );
787 pObjNew = (Value ==
SAIG_XVS1)? Aig_ManConst1(pFrames) : Aig_ManConst0(pFrames);
788 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, pObjNew );
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 );
799 pObjNew = Saig_ObjChild0Frames(pObjMap,nFrames,pObjLi,f);
800 if ( f < nFrames - 1 )
801 Saig_ObjSetFrames( pObjMap, nFrames, pObjLo, f+1, pObjNew );
804 for ( f = 0; f < nFrames; f++ )
808 pObjNew =
Aig_ObjCreateCo( pFrames, Saig_ObjChild0Frames(pObjMap,nFrames,pObj,f) );
809 Saig_ObjSetFrames( pObjMap, nFrames, pObj, f, pObjNew );
812 pFrames->nRegs = pAig->nRegs;
813 pFrames->nTruePis = Aig_ManCiNum(pFrames) - Aig_ManRegNum(pFrames);
814 pFrames->nTruePos = Aig_ManCoNum(pFrames) - Aig_ManRegNum(pFrames);
817 pObjNew =
Aig_ObjCreateCo( pFrames, Saig_ObjChild0Frames(pObjMap,nFrames,pObj,nFrames-1) );
818 Saig_ObjSetFrames( pObjMap, nFrames, pObj, nFrames-1, pObjNew );
844 int nFrames, nPrefix;
854 nFrames = Vec_PtrSize(pTsi->
vStates) - 1 - nPrefix;
874 int nFrames, nPrefix, nNonXRegs;
884 nFrames = Vec_PtrSize(pTsi->
vStates) - 1 - nPrefix;
892 printf(
"Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n", nPrefix, nFrames,
p->nRegs, nNonXRegs );
929 printf(
"Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n",
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 );
945 printf(
"All registers have X-valued states. Phase abstraction cannot be done.\n" );
947 printf(
"There is no registers to abstract with %d frames.\n", nFrames );
985 printf(
"Lead = %5d. Loop = %5d. Total flops = %5d. Binary flops = %5d.\n",
993 printf(
"Print-out finished. Phase assignment is not performed.\n" );
995 else if ( nFrames < 2 )
999 else if ( nFrames > 256 )
1003 else if ( pTsi->
nCycle == 1 )
1007 else if ( pTsi->
nCycle % nFrames != 0 )
1024 if ( Aig_ManCiNum(pNew) == Aig_ManRegNum(pNew) )
1048 int i, k, iFrame, nFrames;
1052 if ( pCex->nPis % Saig_ManPiNum(
p) != 0 )
1054 printf(
"The PI count in the AIG and in the CEX do not match.\n" );
1058 nFrames = pCex->nPis / Saig_ManPiNum(
p);
1060 iFrame = pCex->iFrame * nFrames + pCex->iPo / Saig_ManPoNum(
p);
1062 pNew =
Abc_CexAlloc( Saig_ManRegNum(
p), Saig_ManPiNum(
p), iFrame+1 );
1063 assert( pNew->nBits == pNew->nPis * (iFrame + 1) + pNew->nRegs );
1065 pNew->iFrame = iFrame;
1066 pNew->iPo = pCex->iPo % Saig_ManPoNum(
p);
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 );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int Aig_ManSeqCleanup(Aig_Man_t *p)
Aig_Man_t * Aig_ManDupSimple(Aig_Man_t *p)
DECLARATIONS ///.
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
#define Aig_ManForEachObj(p, pObj, i)
void Aig_ManStop(Aig_Man_t *p)
#define Aig_ManForEachLiSeq(p, pObj, i)
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
struct Aig_Obj_t_ Aig_Obj_t
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
#define Aig_ManForEachNode(p, pObj, i)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
#define Aig_ManForEachPiSeq(p, pObj, i)
SEQUENTIAL ITERATORS ///.
Aig_MmFixed_t * Aig_MmFixedStart(int nEntrySize, int nEntriesMax)
FUNCTION DEFINITIONS ///.
#define Aig_ManForEachPoSeq(p, pObj, i)
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
#define Aig_ManForEachLoSeq(p, pObj, i)
struct Aig_MmFixed_t_ Aig_MmFixed_t
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
unsigned Aig_ManRandom(int fReset)
void Aig_ObjPrint(Aig_Man_t *p, Aig_Obj_t *pObj)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
int Saig_TsiStateCount(Saig_Tsim_t *p, unsigned *pState)
void Saig_TsiPrintTraces(Saig_Tsim_t *p, int nWords, int nPrefix, int nLoop)
Abc_Cex_t * Saig_PhaseTranslateCex(Aig_Man_t *p, Abc_Cex_t *pCex)
Saig_Tsim_t * Saig_ManReachableTernary(Aig_Man_t *p, Vec_Int_t *vInits, int fVerbose)
int Saig_TsiStateHash(unsigned *pState, int nWords, int nTableSize)
int Saig_TsiStateLookup(Saig_Tsim_t *p, unsigned *pState, int nWords)
void Saig_ManAnalizeControl(Aig_Man_t *p, int Reg)
Saig_Tsim_t * Saig_TsiStart(Aig_Man_t *pAig)
DECLARATIONS ///.
Aig_Man_t * Saig_ManPhaseAbstract(Aig_Man_t *p, Vec_Int_t *vInits, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose)
struct Saig_Tsim_t_ Saig_Tsim_t
unsigned * Saig_TsiStateNew(Saig_Tsim_t *p)
Aig_Man_t * Saig_ManPhaseAbstractAuto(Aig_Man_t *p, int fVerbose)
void Saig_TsiStateOrAll(Saig_Tsim_t *pTsi, unsigned *pState)
int Saig_ManFindRegisters(Saig_Tsim_t *pTsi, int nFrames, int fIgnore, int fVerbose)
Vec_Int_t * Saig_TsiComputeTransient(Saig_Tsim_t *p, int nPref)
int Saig_ManPhasePrefixLength(Aig_Man_t *p, int fVerbose, int fVeryVerbose, Vec_Int_t **pvTrans)
Aig_Man_t * Saig_ManPerformAbstraction(Saig_Tsim_t *pTsi, int nFrames, int fVerbose)
int Saig_TsiComputePrefix(Saig_Tsim_t *p, unsigned *pState, int nWords)
int Saig_TsiCountNonXValuedRegisters(Saig_Tsim_t *p, int nPref)
void Saig_TsiStateInsert(Saig_Tsim_t *p, unsigned *pState, int nWords)
int Saig_ManPhaseFrameNum(Aig_Man_t *p, Vec_Int_t *vInits)
void Saig_TsiStop(Saig_Tsim_t *p)
void Saig_TsiStatePrint(Saig_Tsim_t *p, unsigned *pState)
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
#define Saig_ManForEachLi(p, pObj, i)
#define Saig_ManForEachLo(p, pObj, i)
#define Saig_ManForEachPi(p, pObj, i)
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.