00001
00019 #include "fraigInt.h"
00020
00024
00025
00026 #define Fraig_NodeIsSimComplement(p) (Fraig_IsComplement(p)? !(Fraig_Regular(p)->fInv) : (p)->fInv)
00027
00031
00043 Fraig_Node_t * Fraig_NodeCreateConst( Fraig_Man_t * p )
00044 {
00045 Fraig_Node_t * pNode;
00046
00047
00048 pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
00049 memset( pNode, 0, sizeof(Fraig_Node_t) );
00050
00051
00052 pNode->Num = p->vNodes->nSize;
00053 Fraig_NodeVecPush( p->vNodes, pNode );
00054 pNode->NumPi = -1;
00055 pNode->Level = 0;
00056 pNode->nRefs = 1;
00057 pNode->fInv = 1;
00058
00059
00060 pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00061 pNode->puSimD = pNode->puSimR + p->nWordsRand;
00062 memset( pNode->puSimR, 0, sizeof(unsigned) * p->nWordsRand );
00063 memset( pNode->puSimD, 0, sizeof(unsigned) * p->nWordsDyna );
00064
00065
00066 pNode->nOnes = p->nWordsRand * sizeof(unsigned) * 8;
00067
00068
00069 Fraig_HashTableLookupF0( p, pNode );
00070 return pNode;
00071 }
00072
00084 Fraig_Node_t * Fraig_NodeCreatePi( Fraig_Man_t * p )
00085 {
00086 Fraig_Node_t * pNode, * pNodeRes;
00087 int i, clk;
00088
00089
00090 pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
00091 memset( pNode, 0, sizeof(Fraig_Node_t) );
00092 pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00093 pNode->puSimD = pNode->puSimR + p->nWordsRand;
00094 memset( pNode->puSimD, 0, sizeof(unsigned) * p->nWordsDyna );
00095
00096
00097 pNode->Num = p->vNodes->nSize;
00098 Fraig_NodeVecPush( p->vNodes, pNode );
00099
00100
00101 pNode->NumPi = p->vInputs->nSize;
00102 Fraig_NodeVecPush( p->vInputs, pNode );
00103
00104 pNode->Level = 0;
00105 pNode->nRefs = 1;
00106 pNode->fInv = 0;
00107
00108
00109 clk = clock();
00110
00111 pNode->uHashR = 0;
00112 for ( i = 0; i < p->nWordsRand; i++ )
00113 {
00114
00115 pNode->puSimR[i] = FRAIG_RANDOM_UNSIGNED;
00116
00117
00118 if ( i == 0 )
00119 pNode->puSimR[i] <<= 1;
00120
00121 pNode->uHashR ^= pNode->puSimR[i] * s_FraigPrimes[i];
00122 }
00123
00124 pNode->nOnes = Fraig_BitStringCountOnes( pNode->puSimR, p->nWordsRand );
00125
00126
00127 pNode->uHashD = 0;
00128 for ( i = 0; i < p->iWordStart; i++ )
00129 {
00130
00131 pNode->puSimD[i] = FRAIG_RANDOM_UNSIGNED;
00132
00133 pNode->uHashD ^= pNode->puSimD[i] * s_FraigPrimes[i];
00134 }
00135 p->timeSims += clock() - clk;
00136
00137
00138 pNodeRes = Fraig_HashTableLookupF( p, pNode );
00139 assert( pNodeRes == NULL );
00140
00141 return pNode;
00142 }
00143
00156 Fraig_Node_t * Fraig_NodeCreate( Fraig_Man_t * p, Fraig_Node_t * p1, Fraig_Node_t * p2 )
00157 {
00158 Fraig_Node_t * pNode;
00159 int clk;
00160
00161
00162 pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
00163 memset( pNode, 0, sizeof(Fraig_Node_t) );
00164
00165
00166 pNode->p1 = p1; Fraig_Ref(p1); Fraig_Regular(p1)->nRefs++;
00167 pNode->p2 = p2; Fraig_Ref(p2); Fraig_Regular(p2)->nRefs++;
00168
00169
00170 pNode->Num = p->vNodes->nSize;
00171 Fraig_NodeVecPush( p->vNodes, pNode );
00172
00173
00174 pNode->NumPi = -1;
00175
00176
00177 pNode->Level = 1 + FRAIG_MAX(Fraig_Regular(p1)->Level, Fraig_Regular(p2)->Level);
00178 pNode->fInv = Fraig_NodeIsSimComplement(p1) & Fraig_NodeIsSimComplement(p2);
00179 pNode->fFailTfo = Fraig_Regular(p1)->fFailTfo | Fraig_Regular(p2)->fFailTfo;
00180
00181
00182 clk = clock();
00183
00184 pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00185 pNode->puSimD = pNode->puSimR + p->nWordsRand;
00186
00187 pNode->uHashR = 0;
00188 Fraig_NodeSimulate( pNode, 0, p->nWordsRand, 1 );
00189
00190 pNode->uHashD = 0;
00191 Fraig_NodeSimulate( pNode, 0, p->iWordStart, 0 );
00192
00193 pNode->nOnes = Fraig_BitStringCountOnes( pNode->puSimR, p->nWordsRand );
00194 if ( pNode->fInv )
00195 pNode->nOnes = p->nWordsRand * 32 - pNode->nOnes;
00196
00197 p->timeSims += clock() - clk;
00198
00199 #ifdef FRAIG_ENABLE_FANOUTS
00200
00201 Fraig_NodeAddFaninFanout( Fraig_Regular(p1), pNode );
00202 Fraig_NodeAddFaninFanout( Fraig_Regular(p2), pNode );
00203 #endif
00204 return pNode;
00205 }
00206
00207
00222 void Fraig_NodeSimulate( Fraig_Node_t * pNode, int iWordStart, int iWordStop, int fUseRand )
00223 {
00224 unsigned * pSims, * pSims1, * pSims2;
00225 unsigned uHash;
00226 int fCompl, fCompl1, fCompl2, i;
00227
00228 assert( !Fraig_IsComplement(pNode) );
00229
00230
00231 pSims = fUseRand? pNode->puSimR : pNode->puSimD;
00232 pSims1 = fUseRand? Fraig_Regular(pNode->p1)->puSimR : Fraig_Regular(pNode->p1)->puSimD;
00233 pSims2 = fUseRand? Fraig_Regular(pNode->p2)->puSimR : Fraig_Regular(pNode->p2)->puSimD;
00234
00235
00236 fCompl = pNode->fInv;
00237 fCompl1 = Fraig_NodeIsSimComplement(pNode->p1);
00238 fCompl2 = Fraig_NodeIsSimComplement(pNode->p2);
00239
00240
00241 uHash = 0;
00242 if ( fCompl1 && fCompl2 )
00243 {
00244 if ( fCompl )
00245 for ( i = iWordStart; i < iWordStop; i++ )
00246 {
00247 pSims[i] = (pSims1[i] | pSims2[i]);
00248 uHash ^= pSims[i] * s_FraigPrimes[i];
00249 }
00250 else
00251 for ( i = iWordStart; i < iWordStop; i++ )
00252 {
00253 pSims[i] = ~(pSims1[i] | pSims2[i]);
00254 uHash ^= pSims[i] * s_FraigPrimes[i];
00255 }
00256 }
00257 else if ( fCompl1 && !fCompl2 )
00258 {
00259 if ( fCompl )
00260 for ( i = iWordStart; i < iWordStop; i++ )
00261 {
00262 pSims[i] = (pSims1[i] | ~pSims2[i]);
00263 uHash ^= pSims[i] * s_FraigPrimes[i];
00264 }
00265 else
00266 for ( i = iWordStart; i < iWordStop; i++ )
00267 {
00268 pSims[i] = (~pSims1[i] & pSims2[i]);
00269 uHash ^= pSims[i] * s_FraigPrimes[i];
00270 }
00271 }
00272 else if ( !fCompl1 && fCompl2 )
00273 {
00274 if ( fCompl )
00275 for ( i = iWordStart; i < iWordStop; i++ )
00276 {
00277 pSims[i] = (~pSims1[i] | pSims2[i]);
00278 uHash ^= pSims[i] * s_FraigPrimes[i];
00279 }
00280 else
00281 for ( i = iWordStart; i < iWordStop; i++ )
00282 {
00283 pSims[i] = (pSims1[i] & ~pSims2[i]);
00284 uHash ^= pSims[i] * s_FraigPrimes[i];
00285 }
00286 }
00287 else
00288 {
00289 if ( fCompl )
00290 for ( i = iWordStart; i < iWordStop; i++ )
00291 {
00292 pSims[i] = ~(pSims1[i] & pSims2[i]);
00293 uHash ^= pSims[i] * s_FraigPrimes[i];
00294 }
00295 else
00296 for ( i = iWordStart; i < iWordStop; i++ )
00297 {
00298 pSims[i] = (pSims1[i] & pSims2[i]);
00299 uHash ^= pSims[i] * s_FraigPrimes[i];
00300 }
00301 }
00302
00303 if ( fUseRand )
00304 pNode->uHashR ^= uHash;
00305 else
00306 pNode->uHashD ^= uHash;
00307 }
00308
00309
00313