abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hopOper.c File Reference
#include "hop.h"

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Hop_ObjIsExorType (Hop_Obj_t *p0, Hop_Obj_t *p1, Hop_Obj_t **ppFan0, Hop_Obj_t **ppFan1)
 DECLARATIONS ///. More...
 
Hop_Obj_tHop_IthVar (Hop_Man_t *p, int i)
 FUNCTION DEFINITIONS ///. More...
 
Hop_Obj_tHop_Oper (Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1, Hop_Type_t Type)
 
Hop_Obj_tHop_And (Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
 
Hop_Obj_tHop_Exor (Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
 
Hop_Obj_tHop_Or (Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
 
Hop_Obj_tHop_Mux (Hop_Man_t *p, Hop_Obj_t *pC, Hop_Obj_t *p1, Hop_Obj_t *p0)
 
Hop_Obj_tHop_Maj (Hop_Man_t *p, Hop_Obj_t *pA, Hop_Obj_t *pB, Hop_Obj_t *pC)
 
Hop_Obj_tHop_Multi_rec (Hop_Man_t *p, Hop_Obj_t **ppObjs, int nObjs, Hop_Type_t Type)
 
Hop_Obj_tHop_Multi (Hop_Man_t *p, Hop_Obj_t **pArgs, int nArgs, Hop_Type_t Type)
 
Hop_Obj_tHop_Miter (Hop_Man_t *p, Vec_Ptr_t *vPairs)
 
Hop_Obj_tHop_CreateAnd (Hop_Man_t *p, int nVars)
 
Hop_Obj_tHop_CreateOr (Hop_Man_t *p, int nVars)
 
Hop_Obj_tHop_CreateExor (Hop_Man_t *p, int nVars)
 

Function Documentation

Hop_Obj_t* Hop_And ( Hop_Man_t p,
Hop_Obj_t p0,
Hop_Obj_t p1 
)

Function*************************************************************

Synopsis [Performs canonicization step.]

Description [The argument nodes can be complemented.]

SideEffects []

SeeAlso []

Definition at line 104 of file hopOper.c.

105 {
106  Hop_Obj_t * pGhost, * pResult;
107 // Hop_Obj_t * pFan0, * pFan1;
108  // check trivial cases
109  if ( p0 == p1 )
110  return p0;
111  if ( p0 == Hop_Not(p1) )
112  return Hop_Not(p->pConst1);
113  if ( Hop_Regular(p0) == p->pConst1 )
114  return p0 == p->pConst1 ? p1 : Hop_Not(p->pConst1);
115  if ( Hop_Regular(p1) == p->pConst1 )
116  return p1 == p->pConst1 ? p0 : Hop_Not(p->pConst1);
117  // check if it can be an EXOR gate
118 // if ( Hop_ObjIsExorType( p0, p1, &pFan0, &pFan1 ) )
119 // return Hop_Exor( p, pFan0, pFan1 );
120  // check the table
121  pGhost = Hop_ObjCreateGhost( p, p0, p1, AIG_AND );
122  if ( (pResult = Hop_TableLookup( p, pGhost )) )
123  return pResult;
124  return Hop_ObjCreate( p, pGhost );
125 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_ObjCreate(Hop_Man_t *p, Hop_Obj_t *pGhost)
Definition: hopObj.c:97
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Definition: hop.h:65
Definition: hop.h:59
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
static Hop_Obj_t * Hop_ObjCreateGhost(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1, Hop_Type_t Type)
Definition: hop.h:208
Hop_Obj_t * Hop_TableLookup(Hop_Man_t *p, Hop_Obj_t *pGhost)
FUNCTION DEFINITIONS ///.
Definition: hopTable.c:71
Hop_Obj_t* Hop_CreateAnd ( Hop_Man_t p,
int  nVars 
)

Function*************************************************************

Synopsis [Creates AND function with nVars inputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file hopOper.c.

321 {
322  Hop_Obj_t * pFunc;
323  int i;
324  pFunc = Hop_ManConst1( p );
325  for ( i = 0; i < nVars; i++ )
326  pFunc = Hop_And( p, pFunc, Hop_IthVar(p, i) );
327  return pFunc;
328 }
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: hop.h:65
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
Hop_Obj_t* Hop_CreateExor ( Hop_Man_t p,
int  nVars 
)

Function*************************************************************

Synopsis [Creates AND function with nVars inputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 362 of file hopOper.c.

363 {
364  Hop_Obj_t * pFunc;
365  int i;
366  pFunc = Hop_ManConst0( p );
367  for ( i = 0; i < nVars; i++ )
368  pFunc = Hop_Exor( p, pFunc, Hop_IthVar(p, i) );
369  return pFunc;
370 }
Hop_Obj_t * Hop_Exor(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:138
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: hop.h:65
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
static Hop_Obj_t * Hop_ManConst0(Hop_Man_t *p)
Definition: hop.h:131
Hop_Obj_t* Hop_CreateOr ( Hop_Man_t p,
int  nVars 
)

Function*************************************************************

Synopsis [Creates AND function with nVars inputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 341 of file hopOper.c.

342 {
343  Hop_Obj_t * pFunc;
344  int i;
345  pFunc = Hop_ManConst0( p );
346  for ( i = 0; i < nVars; i++ )
347  pFunc = Hop_Or( p, pFunc, Hop_IthVar(p, i) );
348  return pFunc;
349 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Or(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:171
Definition: hop.h:65
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
static Hop_Obj_t * Hop_ManConst0(Hop_Man_t *p)
Definition: hop.h:131
Hop_Obj_t* Hop_Exor ( Hop_Man_t p,
Hop_Obj_t p0,
Hop_Obj_t p1 
)

Function*************************************************************

Synopsis [Performs canonicization step.]

Description [The argument nodes can be complemented.]

SideEffects []

SeeAlso []

Definition at line 138 of file hopOper.c.

139 {
140 /*
141  Hop_Obj_t * pGhost, * pResult;
142  // check trivial cases
143  if ( p0 == p1 )
144  return Hop_Not(p->pConst1);
145  if ( p0 == Hop_Not(p1) )
146  return p->pConst1;
147  if ( Hop_Regular(p0) == p->pConst1 )
148  return Hop_NotCond( p1, p0 == p->pConst1 );
149  if ( Hop_Regular(p1) == p->pConst1 )
150  return Hop_NotCond( p0, p1 == p->pConst1 );
151  // check the table
152  pGhost = Hop_ObjCreateGhost( p, p0, p1, AIG_EXOR );
153  if ( pResult = Hop_TableLookup( p, pGhost ) )
154  return pResult;
155  return Hop_ObjCreate( p, pGhost );
156 */
157  return Hop_Or( p, Hop_And(p, p0, Hop_Not(p1)), Hop_And(p, Hop_Not(p0), p1) );
158 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Or(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:171
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
Hop_Obj_t* Hop_IthVar ( Hop_Man_t p,
int  i 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Returns i-th elementary variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 63 of file hopOper.c.

64 {
65  int v;
66  for ( v = Hop_ManPiNum(p); v <= i; v++ )
67  Hop_ObjCreatePi( p );
68  assert( i < Vec_PtrSize(p->vPis) );
69  return Hop_ManPi( p, i );
70 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Hop_Obj_t * Hop_ManPi(Hop_Man_t *p, int i)
Definition: hop.h:134
#define assert(ex)
Definition: util_old.h:213
Hop_Obj_t * Hop_ObjCreatePi(Hop_Man_t *p)
DECLARATIONS ///.
Definition: hopObj.c:45
static int Hop_ManPiNum(Hop_Man_t *p)
Definition: hop.h:145
Hop_Obj_t* Hop_Maj ( Hop_Man_t p,
Hop_Obj_t pA,
Hop_Obj_t pB,
Hop_Obj_t pC 
)

Function*************************************************************

Synopsis [Implements ITE operation.]

Description []

SideEffects []

SeeAlso []

Definition at line 242 of file hopOper.c.

243 {
244  return Hop_Or( p, Hop_Or(p, Hop_And(p, pA, pB), Hop_And(p, pA, pC)), Hop_And(p, pB, pC) );
245 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Or(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:171
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
Hop_Obj_t* Hop_Miter ( Hop_Man_t p,
Vec_Ptr_t vPairs 
)

Function*************************************************************

Synopsis [Implements the miter.]

Description []

SideEffects []

SeeAlso []

Definition at line 297 of file hopOper.c.

298 {
299  int i;
300  assert( vPairs->nSize > 0 );
301  assert( vPairs->nSize % 2 == 0 );
302  // go through the cubes of the node's SOP
303  for ( i = 0; i < vPairs->nSize; i += 2 )
304  vPairs->pArray[i/2] = Hop_Not( Hop_Exor( p, (Hop_Obj_t *)vPairs->pArray[i], (Hop_Obj_t *)vPairs->pArray[i+1] ) );
305  vPairs->nSize = vPairs->nSize/2;
306  return Hop_Not( Hop_Multi_rec( p, (Hop_Obj_t **)vPairs->pArray, vPairs->nSize, AIG_AND ) );
307 }
Hop_Obj_t * Hop_Exor(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:138
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Multi_rec(Hop_Man_t *p, Hop_Obj_t **ppObjs, int nObjs, Hop_Type_t Type)
Definition: hopOper.c:258
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Definition: hop.h:65
Definition: hop.h:59
#define assert(ex)
Definition: util_old.h:213
Hop_Obj_t* Hop_Multi ( Hop_Man_t p,
Hop_Obj_t **  pArgs,
int  nArgs,
Hop_Type_t  Type 
)

Function*************************************************************

Synopsis [Old code.]

Description []

SideEffects []

SeeAlso []

Definition at line 279 of file hopOper.c.

280 {
281  assert( Type == AIG_AND || Type == AIG_EXOR );
282  assert( nArgs > 0 );
283  return Hop_Multi_rec( p, pArgs, nArgs, Type );
284 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: hop.h:60
Hop_Obj_t * Hop_Multi_rec(Hop_Man_t *p, Hop_Obj_t **ppObjs, int nObjs, Hop_Type_t Type)
Definition: hopOper.c:258
Definition: hop.h:59
#define assert(ex)
Definition: util_old.h:213
Hop_Obj_t* Hop_Multi_rec ( Hop_Man_t p,
Hop_Obj_t **  ppObjs,
int  nObjs,
Hop_Type_t  Type 
)

Function*************************************************************

Synopsis [Constructs the well-balanced tree of gates.]

Description [Disregards levels and possible logic sharing.]

SideEffects []

SeeAlso []

Definition at line 258 of file hopOper.c.

259 {
260  Hop_Obj_t * pObj1, * pObj2;
261  if ( nObjs == 1 )
262  return ppObjs[0];
263  pObj1 = Hop_Multi_rec( p, ppObjs, nObjs/2, Type );
264  pObj2 = Hop_Multi_rec( p, ppObjs + nObjs/2, nObjs - nObjs/2, Type );
265  return Hop_Oper( p, pObj1, pObj2, Type );
266 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Multi_rec(Hop_Man_t *p, Hop_Obj_t **ppObjs, int nObjs, Hop_Type_t Type)
Definition: hopOper.c:258
Definition: hop.h:65
Hop_Obj_t * Hop_Oper(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1, Hop_Type_t Type)
Definition: hopOper.c:83
Hop_Obj_t* Hop_Mux ( Hop_Man_t p,
Hop_Obj_t pC,
Hop_Obj_t p1,
Hop_Obj_t p0 
)

Function*************************************************************

Synopsis [Implements ITE operation.]

Description []

SideEffects []

SeeAlso []

Definition at line 187 of file hopOper.c.

188 {
189 /*
190  Hop_Obj_t * pTempA1, * pTempA2, * pTempB1, * pTempB2, * pTemp;
191  int Count0, Count1;
192  // consider trivial cases
193  if ( p0 == Hop_Not(p1) )
194  return Hop_Exor( p, pC, p0 );
195  // other cases can be added
196  // implement the first MUX (F = C * x1 + C' * x0)
197 
198  // check for constants here!!!
199 
200  pTempA1 = Hop_TableLookup( p, Hop_ObjCreateGhost(p, pC, p1, AIG_AND) );
201  pTempA2 = Hop_TableLookup( p, Hop_ObjCreateGhost(p, Hop_Not(pC), p0, AIG_AND) );
202  if ( pTempA1 && pTempA2 )
203  {
204  pTemp = Hop_TableLookup( p, Hop_ObjCreateGhost(p, Hop_Not(pTempA1), Hop_Not(pTempA2), AIG_AND) );
205  if ( pTemp ) return Hop_Not(pTemp);
206  }
207  Count0 = (pTempA1 != NULL) + (pTempA2 != NULL);
208  // implement the second MUX (F' = C * x1' + C' * x0')
209  pTempB1 = Hop_TableLookup( p, Hop_ObjCreateGhost(p, pC, Hop_Not(p1), AIG_AND) );
210  pTempB2 = Hop_TableLookup( p, Hop_ObjCreateGhost(p, Hop_Not(pC), Hop_Not(p0), AIG_AND) );
211  if ( pTempB1 && pTempB2 )
212  {
213  pTemp = Hop_TableLookup( p, Hop_ObjCreateGhost(p, Hop_Not(pTempB1), Hop_Not(pTempB2), AIG_AND) );
214  if ( pTemp ) return pTemp;
215  }
216  Count1 = (pTempB1 != NULL) + (pTempB2 != NULL);
217  // compare and decide which one to implement
218  if ( Count0 >= Count1 )
219  {
220  pTempA1 = pTempA1? pTempA1 : Hop_And(p, pC, p1);
221  pTempA2 = pTempA2? pTempA2 : Hop_And(p, Hop_Not(pC), p0);
222  return Hop_Or( p, pTempA1, pTempA2 );
223  }
224  pTempB1 = pTempB1? pTempB1 : Hop_And(p, pC, Hop_Not(p1));
225  pTempB2 = pTempB2? pTempB2 : Hop_And(p, Hop_Not(pC), Hop_Not(p0));
226  return Hop_Not( Hop_Or( p, pTempB1, pTempB2 ) );
227 */
228  return Hop_Or( p, Hop_And(p, pC, p1), Hop_And(p, Hop_Not(pC), p0) );
229 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Hop_Obj_t * Hop_Or(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:171
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
static ABC_NAMESPACE_IMPL_START int Hop_ObjIsExorType ( Hop_Obj_t p0,
Hop_Obj_t p1,
Hop_Obj_t **  ppFan0,
Hop_Obj_t **  ppFan1 
)
inlinestatic

DECLARATIONS ///.

CFile****************************************************************

FileName [hopOper.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Minimalistic And-Inverter Graph package.]

Synopsis [AIG operations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006.]

Revision [

Id:
hopOper.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]

Definition at line 31 of file hopOper.c.

32 {
33  if ( !Hop_IsComplement(p0) || !Hop_IsComplement(p1) )
34  return 0;
35  p0 = Hop_Regular(p0);
36  p1 = Hop_Regular(p1);
37  if ( !Hop_ObjIsAnd(p0) || !Hop_ObjIsAnd(p1) )
38  return 0;
39  if ( Hop_ObjFanin0(p0) != Hop_ObjFanin0(p1) || Hop_ObjFanin1(p0) != Hop_ObjFanin1(p1) )
40  return 0;
41  if ( Hop_ObjFaninC0(p0) == Hop_ObjFaninC0(p1) || Hop_ObjFaninC1(p0) == Hop_ObjFaninC1(p1) )
42  return 0;
43  *ppFan0 = Hop_ObjChild0(p0);
44  *ppFan1 = Hop_ObjChild1(p0);
45  return 1;
46 }
static Hop_Obj_t * Hop_ObjChild0(Hop_Obj_t *pObj)
Definition: hop.h:184
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
static int Hop_ObjIsAnd(Hop_Obj_t *pObj)
Definition: hop.h:158
static Hop_Obj_t * Hop_ObjChild1(Hop_Obj_t *pObj)
Definition: hop.h:185
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
static int Hop_ObjFaninC0(Hop_Obj_t *pObj)
Definition: hop.h:180
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
Hop_Obj_t* Hop_Oper ( Hop_Man_t p,
Hop_Obj_t p0,
Hop_Obj_t p1,
Hop_Type_t  Type 
)

Function*************************************************************

Synopsis [Perform one operation.]

Description [The argument nodes can be complemented.]

SideEffects []

SeeAlso []

Definition at line 83 of file hopOper.c.

84 {
85  if ( Type == AIG_AND )
86  return Hop_And( p, p0, p1 );
87  if ( Type == AIG_EXOR )
88  return Hop_Exor( p, p0, p1 );
89  assert( 0 );
90  return NULL;
91 }
Hop_Obj_t * Hop_Exor(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:138
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: hop.h:60
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
Definition: hop.h:59
#define assert(ex)
Definition: util_old.h:213
Hop_Obj_t* Hop_Or ( Hop_Man_t p,
Hop_Obj_t p0,
Hop_Obj_t p1 
)

Function*************************************************************

Synopsis [Implements Boolean OR.]

Description []

SideEffects []

SeeAlso []

Definition at line 171 of file hopOper.c.

172 {
173  return Hop_Not( Hop_And( p, Hop_Not(p0), Hop_Not(p1) ) );
174 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104