00001
00021 #include "hop.h"
00022
00026
00027
00028 static inline int Hop_ObjIsExorType( Hop_Obj_t * p0, Hop_Obj_t * p1, Hop_Obj_t ** ppFan0, Hop_Obj_t ** ppFan1 )
00029 {
00030 if ( !Hop_IsComplement(p0) || !Hop_IsComplement(p1) )
00031 return 0;
00032 p0 = Hop_Regular(p0);
00033 p1 = Hop_Regular(p1);
00034 if ( !Hop_ObjIsAnd(p0) || !Hop_ObjIsAnd(p1) )
00035 return 0;
00036 if ( Hop_ObjFanin0(p0) != Hop_ObjFanin0(p1) || Hop_ObjFanin1(p0) != Hop_ObjFanin1(p1) )
00037 return 0;
00038 if ( Hop_ObjFaninC0(p0) == Hop_ObjFaninC0(p1) || Hop_ObjFaninC1(p0) == Hop_ObjFaninC1(p1) )
00039 return 0;
00040 *ppFan0 = Hop_ObjChild0(p0);
00041 *ppFan1 = Hop_ObjChild1(p0);
00042 return 1;
00043 }
00044
00048
00060 Hop_Obj_t * Hop_IthVar( Hop_Man_t * p, int i )
00061 {
00062 int v;
00063 for ( v = Hop_ManPiNum(p); v <= i; v++ )
00064 Hop_ObjCreatePi( p );
00065 assert( i < Vec_PtrSize(p->vPis) );
00066 return Hop_ManPi( p, i );
00067 }
00068
00080 Hop_Obj_t * Hop_Oper( Hop_Man_t * p, Hop_Obj_t * p0, Hop_Obj_t * p1, Hop_Type_t Type )
00081 {
00082 if ( Type == AIG_AND )
00083 return Hop_And( p, p0, p1 );
00084 if ( Type == AIG_EXOR )
00085 return Hop_Exor( p, p0, p1 );
00086 assert( 0 );
00087 return NULL;
00088 }
00089
00101 Hop_Obj_t * Hop_And( Hop_Man_t * p, Hop_Obj_t * p0, Hop_Obj_t * p1 )
00102 {
00103 Hop_Obj_t * pGhost, * pResult;
00104
00105
00106 if ( p0 == p1 )
00107 return p0;
00108 if ( p0 == Hop_Not(p1) )
00109 return Hop_Not(p->pConst1);
00110 if ( Hop_Regular(p0) == p->pConst1 )
00111 return p0 == p->pConst1 ? p1 : Hop_Not(p->pConst1);
00112 if ( Hop_Regular(p1) == p->pConst1 )
00113 return p1 == p->pConst1 ? p0 : Hop_Not(p->pConst1);
00114
00115
00116
00117
00118 pGhost = Hop_ObjCreateGhost( p, p0, p1, AIG_AND );
00119 if ( pResult = Hop_TableLookup( p, pGhost ) )
00120 return pResult;
00121 return Hop_ObjCreate( p, pGhost );
00122 }
00123
00135 Hop_Obj_t * Hop_Exor( Hop_Man_t * p, Hop_Obj_t * p0, Hop_Obj_t * p1 )
00136 {
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 return Hop_Or( p, Hop_And(p, p0, Hop_Not(p1)), Hop_And(p, Hop_Not(p0), p1) );
00155 }
00156
00168 Hop_Obj_t * Hop_Or( Hop_Man_t * p, Hop_Obj_t * p0, Hop_Obj_t * p1 )
00169 {
00170 return Hop_Not( Hop_And( p, Hop_Not(p0), Hop_Not(p1) ) );
00171 }
00172
00184 Hop_Obj_t * Hop_Mux( Hop_Man_t * p, Hop_Obj_t * pC, Hop_Obj_t * p1, Hop_Obj_t * p0 )
00185 {
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 return Hop_Or( p, Hop_And(p, pC, p1), Hop_And(p, Hop_Not(pC), p0) );
00226 }
00227
00239 Hop_Obj_t * Hop_Maj( Hop_Man_t * p, Hop_Obj_t * pA, Hop_Obj_t * pB, Hop_Obj_t * pC )
00240 {
00241 return Hop_Or( p, Hop_Or(p, Hop_And(p, pA, pB), Hop_And(p, pA, pC)), Hop_And(p, pB, pC) );
00242 }
00243
00255 Hop_Obj_t * Hop_Multi_rec( Hop_Man_t * p, Hop_Obj_t ** ppObjs, int nObjs, Hop_Type_t Type )
00256 {
00257 Hop_Obj_t * pObj1, * pObj2;
00258 if ( nObjs == 1 )
00259 return ppObjs[0];
00260 pObj1 = Hop_Multi_rec( p, ppObjs, nObjs/2, Type );
00261 pObj2 = Hop_Multi_rec( p, ppObjs + nObjs/2, nObjs - nObjs/2, Type );
00262 return Hop_Oper( p, pObj1, pObj2, Type );
00263 }
00264
00276 Hop_Obj_t * Hop_Multi( Hop_Man_t * p, Hop_Obj_t ** pArgs, int nArgs, Hop_Type_t Type )
00277 {
00278 assert( Type == AIG_AND || Type == AIG_EXOR );
00279 assert( nArgs > 0 );
00280 return Hop_Multi_rec( p, pArgs, nArgs, Type );
00281 }
00282
00294 Hop_Obj_t * Hop_Miter( Hop_Man_t * p, Vec_Ptr_t * vPairs )
00295 {
00296 int i;
00297 assert( vPairs->nSize > 0 );
00298 assert( vPairs->nSize % 2 == 0 );
00299
00300 for ( i = 0; i < vPairs->nSize; i += 2 )
00301 vPairs->pArray[i/2] = Hop_Not( Hop_Exor( p, vPairs->pArray[i], vPairs->pArray[i+1] ) );
00302 vPairs->nSize = vPairs->nSize/2;
00303 return Hop_Not( Hop_Multi_rec( p, (Hop_Obj_t **)vPairs->pArray, vPairs->nSize, AIG_AND ) );
00304 }
00305
00317 Hop_Obj_t * Hop_CreateAnd( Hop_Man_t * p, int nVars )
00318 {
00319 Hop_Obj_t * pFunc;
00320 int i;
00321 pFunc = Hop_ManConst1( p );
00322 for ( i = 0; i < nVars; i++ )
00323 pFunc = Hop_And( p, pFunc, Hop_IthVar(p, i) );
00324 return pFunc;
00325 }
00326
00338 Hop_Obj_t * Hop_CreateOr( Hop_Man_t * p, int nVars )
00339 {
00340 Hop_Obj_t * pFunc;
00341 int i;
00342 pFunc = Hop_ManConst0( p );
00343 for ( i = 0; i < nVars; i++ )
00344 pFunc = Hop_Or( p, pFunc, Hop_IthVar(p, i) );
00345 return pFunc;
00346 }
00347
00359 Hop_Obj_t * Hop_CreateExor( Hop_Man_t * p, int nVars )
00360 {
00361 Hop_Obj_t * pFunc;
00362 int i;
00363 pFunc = Hop_ManConst0( p );
00364 for ( i = 0; i < nVars; i++ )
00365 pFunc = Hop_Exor( p, pFunc, Hop_IthVar(p, i) );
00366 return pFunc;
00367 }
00368
00372
00373