00001
00021 #include "abc.h"
00022
00026
00027 #define XVS0 ABC_INIT_ZERO
00028 #define XVS1 ABC_INIT_ONE
00029 #define XVSX ABC_INIT_DC
00030
00031 static inline void Abc_ObjSetXsim( Abc_Obj_t * pObj, int Value ) { pObj->pCopy = (void *)Value; }
00032 static inline int Abc_ObjGetXsim( Abc_Obj_t * pObj ) { return (int)pObj->pCopy; }
00033 static inline int Abc_XsimInv( int Value )
00034 {
00035 if ( Value == XVS0 )
00036 return XVS1;
00037 if ( Value == XVS1 )
00038 return XVS0;
00039 assert( Value == XVSX );
00040 return XVSX;
00041 }
00042 static inline int Abc_XsimAnd( int Value0, int Value1 )
00043 {
00044 if ( Value0 == XVS0 || Value1 == XVS0 )
00045 return XVS0;
00046 if ( Value0 == XVSX || Value1 == XVSX )
00047 return XVSX;
00048 assert( Value0 == XVS1 && Value1 == XVS1 );
00049 return XVS1;
00050 }
00051 static inline int Abc_XsimRand2()
00052 {
00053 return (rand() & 1) ? XVS1 : XVS0;
00054 }
00055 static inline int Abc_XsimRand3()
00056 {
00057 int RetValue;
00058 do {
00059 RetValue = rand() & 3;
00060 } while ( RetValue == 0 );
00061 return RetValue;
00062 }
00063 static inline int Abc_ObjGetXsimFanin0( Abc_Obj_t * pObj )
00064 {
00065 int RetValue;
00066 RetValue = Abc_ObjGetXsim(Abc_ObjFanin0(pObj));
00067 return Abc_ObjFaninC0(pObj)? Abc_XsimInv(RetValue) : RetValue;
00068 }
00069 static inline int Abc_ObjGetXsimFanin1( Abc_Obj_t * pObj )
00070 {
00071 int RetValue;
00072 RetValue = Abc_ObjGetXsim(Abc_ObjFanin1(pObj));
00073 return Abc_ObjFaninC1(pObj)? Abc_XsimInv(RetValue) : RetValue;
00074 }
00075 static inline void Abc_XsimPrint( FILE * pFile, int Value )
00076 {
00077 if ( Value == XVS0 )
00078 {
00079 fprintf( pFile, "0" );
00080 return;
00081 }
00082 if ( Value == XVS1 )
00083 {
00084 fprintf( pFile, "1" );
00085 return;
00086 }
00087 assert( Value == XVSX );
00088 fprintf( pFile, "x" );
00089 }
00090
00094
00106 void Abc_NtkXValueSimulate( Abc_Ntk_t * pNtk, int nFrames, int fXInputs, int fXState, int fVerbose )
00107 {
00108 Abc_Obj_t * pObj;
00109 int i, f;
00110 assert( Abc_NtkIsStrash(pNtk) );
00111 srand( 0x12341234 );
00112
00113 Abc_ObjSetXsim( Abc_AigConst1(pNtk), XVS1 );
00114 if ( fXInputs )
00115 {
00116 Abc_NtkForEachPi( pNtk, pObj, i )
00117 Abc_ObjSetXsim( pObj, XVSX );
00118 }
00119 else
00120 {
00121 Abc_NtkForEachPi( pNtk, pObj, i )
00122 Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
00123 }
00124 if ( fXState )
00125 {
00126 Abc_NtkForEachLatch( pNtk, pObj, i )
00127 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), XVSX );
00128 }
00129 else
00130 {
00131 Abc_NtkForEachLatch( pNtk, pObj, i )
00132 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_LatchInit(pObj) );
00133 }
00134
00135 fprintf( stdout, "Frame : Inputs : Latches : Outputs\n" );
00136 for ( f = 0; f < nFrames; f++ )
00137 {
00138 Abc_AigForEachAnd( pNtk, pObj, i )
00139 Abc_ObjSetXsim( pObj, Abc_XsimAnd(Abc_ObjGetXsimFanin0(pObj), Abc_ObjGetXsimFanin1(pObj)) );
00140 Abc_NtkForEachCo( pNtk, pObj, i )
00141 Abc_ObjSetXsim( pObj, Abc_ObjGetXsimFanin0(pObj) );
00142
00143 fprintf( stdout, "%2d : ", f );
00144 Abc_NtkForEachPi( pNtk, pObj, i )
00145 Abc_XsimPrint( stdout, Abc_ObjGetXsim(pObj) );
00146 fprintf( stdout, " : " );
00147 Abc_NtkForEachLatch( pNtk, pObj, i )
00148 {
00149
00150
00151 Abc_XsimPrint( stdout, Abc_ObjGetXsim(Abc_ObjFanout0(pObj)) );
00152 }
00153 fprintf( stdout, " : " );
00154 Abc_NtkForEachPo( pNtk, pObj, i )
00155 Abc_XsimPrint( stdout, Abc_ObjGetXsim(pObj) );
00156 if ( Abc_NtkAssertNum(pNtk) )
00157 {
00158 fprintf( stdout, " : " );
00159 Abc_NtkForEachAssert( pNtk, pObj, i )
00160 Abc_XsimPrint( stdout, Abc_ObjGetXsim(pObj) );
00161 }
00162 fprintf( stdout, "\n" );
00163
00164 if ( fXInputs )
00165 {
00166 Abc_NtkForEachPi( pNtk, pObj, i )
00167 Abc_ObjSetXsim( pObj, XVSX );
00168 }
00169 else
00170 {
00171 Abc_NtkForEachPi( pNtk, pObj, i )
00172 Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
00173 }
00174
00175 Abc_NtkForEachLatch( pNtk, pObj, i )
00176 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_ObjGetXsim(Abc_ObjFanin0(pObj)) );
00177 }
00178 }
00179
00192 void Abc_NtkCycleInitState( Abc_Ntk_t * pNtk, int nFrames, int fVerbose )
00193 {
00194 Abc_Obj_t * pObj;
00195 int i, f;
00196 assert( Abc_NtkIsStrash(pNtk) );
00197 srand( 0x12341234 );
00198
00199 Abc_ObjSetXsim( Abc_AigConst1(pNtk), XVS1 );
00200 Abc_NtkForEachPi( pNtk, pObj, i )
00201 Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
00202 Abc_NtkForEachLatch( pNtk, pObj, i )
00203 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_LatchIsInit1(pObj)? XVS1 : XVS0 );
00204
00205 for ( f = 0; f < nFrames; f++ )
00206 {
00207 Abc_AigForEachAnd( pNtk, pObj, i )
00208 Abc_ObjSetXsim( pObj, Abc_XsimAnd(Abc_ObjGetXsimFanin0(pObj), Abc_ObjGetXsimFanin1(pObj)) );
00209 Abc_NtkForEachCo( pNtk, pObj, i )
00210 Abc_ObjSetXsim( pObj, Abc_ObjGetXsimFanin0(pObj) );
00211
00212 Abc_NtkForEachPi( pNtk, pObj, i )
00213 Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
00214
00215 Abc_NtkForEachLatch( pNtk, pObj, i )
00216 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_ObjGetXsim(Abc_ObjFanin0(pObj)) );
00217 }
00218
00219 Abc_NtkForEachLatch( pNtk, pObj, i )
00220 pObj->pData = (void *)Abc_ObjGetXsim(Abc_ObjFanout0(pObj));
00221 }
00222
00226
00227