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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Hop_ManIncrementTravId (Hop_Man_t *p)
 DECLARATIONS ///. More...
 
void Hop_ManCleanData (Hop_Man_t *p)
 
void Hop_ObjCleanData_rec (Hop_Obj_t *pObj)
 
void Hop_ObjCollectMulti_rec (Hop_Obj_t *pRoot, Hop_Obj_t *pObj, Vec_Ptr_t *vSuper)
 
void Hop_ObjCollectMulti (Hop_Obj_t *pRoot, Vec_Ptr_t *vSuper)
 
int Hop_ObjIsMuxType (Hop_Obj_t *pNode)
 
int Hop_ObjRecognizeExor (Hop_Obj_t *pObj, Hop_Obj_t **ppFan0, Hop_Obj_t **ppFan1)
 
Hop_Obj_tHop_ObjRecognizeMux (Hop_Obj_t *pNode, Hop_Obj_t **ppNodeT, Hop_Obj_t **ppNodeE)
 
void Hop_ObjPrintEqn (FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
 
void Hop_ObjPrintVerilog (FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
 
void Hop_ObjPrintVerbose (Hop_Obj_t *pObj, int fHaig)
 
void Hop_ManPrintVerbose (Hop_Man_t *p, int fHaig)
 
void Hop_ManDumpBlif (Hop_Man_t *p, char *pFileName)
 

Function Documentation

void Hop_ManCleanData ( Hop_Man_t p)

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

Synopsis [Cleans the data pointers for the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 63 of file hopUtil.c.

64 {
65  Hop_Obj_t * pObj;
66  int i;
67  p->nTravIds = 1;
68  Hop_ManConst1(p)->pData = NULL;
69  Hop_ManForEachPi( p, pObj, i )
70  pObj->pData = NULL;
71  Hop_ManForEachPo( p, pObj, i )
72  pObj->pData = NULL;
73  Hop_ManForEachNode( p, pObj, i )
74  pObj->pData = NULL;
75 }
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Hop_ManForEachNode(p, pObj, i)
Definition: hop.h:265
#define Hop_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: hop.h:259
#define Hop_ManForEachPo(p, pObj, i)
Definition: hop.h:262
Definition: hop.h:65
void * pData
Definition: hop.h:68
void Hop_ManDumpBlif ( Hop_Man_t p,
char *  pFileName 
)

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

Synopsis [Writes the AIG into the BLIF file.]

Description []

SideEffects []

SeeAlso []

Definition at line 509 of file hopUtil.c.

510 {
511  FILE * pFile;
512  Vec_Ptr_t * vNodes;
513  Hop_Obj_t * pObj, * pConst1 = NULL;
514  int i, nDigits, Counter = 0;
515  if ( Hop_ManPoNum(p) == 0 )
516  {
517  printf( "Hop_ManDumpBlif(): AIG manager does not have POs.\n" );
518  return;
519  }
520  // collect nodes in the DFS order
521  vNodes = Hop_ManDfs( p );
522  // assign IDs to objects
523  Hop_ManConst1(p)->pData = (void *)(ABC_PTRUINT_T)Counter++;
524  Hop_ManForEachPi( p, pObj, i )
525  pObj->pData = (void *)(ABC_PTRUINT_T)Counter++;
526  Hop_ManForEachPo( p, pObj, i )
527  pObj->pData = (void *)(ABC_PTRUINT_T)Counter++;
528  Vec_PtrForEachEntry( Hop_Obj_t *, vNodes, pObj, i )
529  pObj->pData = (void *)(ABC_PTRUINT_T)Counter++;
530  nDigits = Hop_Base10Log( Counter );
531  // write the file
532  pFile = fopen( pFileName, "w" );
533  fprintf( pFile, "# BLIF file written by procedure Hop_ManDumpBlif() in ABC\n" );
534  fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" );
535  fprintf( pFile, ".model test\n" );
536  // write PIs
537  fprintf( pFile, ".inputs" );
538  Hop_ManForEachPi( p, pObj, i )
539  fprintf( pFile, " n%0*d", nDigits, (int)(ABC_PTRUINT_T)pObj->pData );
540  fprintf( pFile, "\n" );
541  // write POs
542  fprintf( pFile, ".outputs" );
543  Hop_ManForEachPo( p, pObj, i )
544  fprintf( pFile, " n%0*d", nDigits, (int)(ABC_PTRUINT_T)pObj->pData );
545  fprintf( pFile, "\n" );
546  // write nodes
547  Vec_PtrForEachEntry( Hop_Obj_t *, vNodes, pObj, i )
548  {
549  fprintf( pFile, ".names n%0*d n%0*d n%0*d\n",
550  nDigits, (int)(ABC_PTRUINT_T)Hop_ObjFanin0(pObj)->pData,
551  nDigits, (int)(ABC_PTRUINT_T)Hop_ObjFanin1(pObj)->pData,
552  nDigits, (int)(ABC_PTRUINT_T)pObj->pData );
553  fprintf( pFile, "%d%d 1\n", !Hop_ObjFaninC0(pObj), !Hop_ObjFaninC1(pObj) );
554  }
555  // write POs
556  Hop_ManForEachPo( p, pObj, i )
557  {
558  fprintf( pFile, ".names n%0*d n%0*d\n",
559  nDigits, (int)(ABC_PTRUINT_T)Hop_ObjFanin0(pObj)->pData,
560  nDigits, (int)(ABC_PTRUINT_T)pObj->pData );
561  fprintf( pFile, "%d 1\n", !Hop_ObjFaninC0(pObj) );
562  if ( Hop_ObjIsConst1(Hop_ObjFanin0(pObj)) )
563  pConst1 = Hop_ManConst1(p);
564  }
565  if ( pConst1 )
566  fprintf( pFile, ".names n%0*d\n 1\n", nDigits, (int)(ABC_PTRUINT_T)pConst1->pData );
567  fprintf( pFile, ".end\n\n" );
568  fclose( pFile );
569  Vec_PtrFree( vNodes );
570 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Ptr_t * Hop_ManDfs(Hop_Man_t *p)
Definition: hopDfs.c:68
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Hop_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: hop.h:259
#define Hop_ManForEachPo(p, pObj, i)
Definition: hop.h:262
static int Hop_ManPoNum(Hop_Man_t *p)
Definition: hop.h:146
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
Definition: hop.h:65
static int Hop_Base10Log(unsigned n)
Definition: hop.h:124
static int Counter
void * pData
Definition: hop.h:68
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
static int Hop_ObjFaninC0(Hop_Obj_t *pObj)
Definition: hop.h:180
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
ABC_NAMESPACE_IMPL_START void Hop_ManIncrementTravId ( Hop_Man_t p)

DECLARATIONS ///.

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

FileName [hopUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [Various procedures.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Increments the current traversal ID of the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file hopUtil.c.

46 {
47  if ( p->nTravIds >= (1<<30)-1 )
49  p->nTravIds++;
50 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Hop_ManCleanData(Hop_Man_t *p)
Definition: hopUtil.c:63
void Hop_ManPrintVerbose ( Hop_Man_t p,
int  fHaig 
)

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

Synopsis [Prints node in HAIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 482 of file hopUtil.c.

483 {
484  Vec_Ptr_t * vNodes;
485  Hop_Obj_t * pObj;
486  int i;
487  printf( "PIs: " );
488  Hop_ManForEachPi( p, pObj, i )
489  printf( " %p", pObj );
490  printf( "\n" );
491  vNodes = Hop_ManDfs( p );
492  Vec_PtrForEachEntry( Hop_Obj_t *, vNodes, pObj, i )
493  Hop_ObjPrintVerbose( pObj, fHaig ), printf( "\n" );
494  printf( "\n" );
495  Vec_PtrFree( vNodes );
496 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Ptr_t * Hop_ManDfs(Hop_Man_t *p)
Definition: hopDfs.c:68
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Hop_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: hop.h:259
void Hop_ObjPrintVerbose(Hop_Obj_t *pObj, int fHaig)
Definition: hopUtil.c:456
Definition: hop.h:65
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Hop_ObjCleanData_rec ( Hop_Obj_t pObj)

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

Synopsis [Recursively cleans the data pointers in the cone of the node.]

Description [Applicable to small AIGs only because no caching is performed.]

SideEffects []

SeeAlso []

Definition at line 88 of file hopUtil.c.

89 {
90  assert( !Hop_IsComplement(pObj) );
91  assert( !Hop_ObjIsPo(pObj) );
92  if ( Hop_ObjIsAnd(pObj) )
93  {
96  }
97  pObj->pData = NULL;
98 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjIsAnd(Hop_Obj_t *pObj)
Definition: hop.h:158
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static int Hop_ObjIsPo(Hop_Obj_t *pObj)
Definition: hop.h:157
void * pData
Definition: hop.h:68
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
#define assert(ex)
Definition: util_old.h:213
void Hop_ObjCleanData_rec(Hop_Obj_t *pObj)
Definition: hopUtil.c:88
void Hop_ObjCollectMulti ( Hop_Obj_t pRoot,
Vec_Ptr_t vSuper 
)

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

Synopsis [Detects multi-input gate rooted at this node.]

Description []

SideEffects []

SeeAlso []

Definition at line 133 of file hopUtil.c.

134 {
135  assert( !Hop_IsComplement(pRoot) );
136  Vec_PtrClear( vSuper );
137  Hop_ObjCollectMulti_rec( pRoot, pRoot, vSuper );
138 }
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Hop_ObjCollectMulti_rec(Hop_Obj_t *pRoot, Hop_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: hopUtil.c:111
void Hop_ObjCollectMulti_rec ( Hop_Obj_t pRoot,
Hop_Obj_t pObj,
Vec_Ptr_t vSuper 
)

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

Synopsis [Detects multi-input gate rooted at this node.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file hopUtil.c.

112 {
113  if ( pRoot != pObj && (Hop_IsComplement(pObj) || Hop_ObjIsPi(pObj) || Hop_ObjType(pRoot) != Hop_ObjType(pObj)) )
114  {
115  Vec_PtrPushUnique(vSuper, pObj);
116  return;
117  }
118  Hop_ObjCollectMulti_rec( pRoot, Hop_ObjChild0(pObj), vSuper );
119  Hop_ObjCollectMulti_rec( pRoot, Hop_ObjChild1(pObj), vSuper );
120 }
static Hop_Obj_t * Hop_ObjChild0(Hop_Obj_t *pObj)
Definition: hop.h:184
static int Vec_PtrPushUnique(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:656
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static Hop_Type_t Hop_ObjType(Hop_Obj_t *pObj)
Definition: hop.h:153
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
void Hop_ObjCollectMulti_rec(Hop_Obj_t *pRoot, Hop_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: hopUtil.c:111
int Hop_ObjIsMuxType ( Hop_Obj_t pNode)

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

Synopsis [Returns 1 if the node is the root of MUX or EXOR/NEXOR.]

Description []

SideEffects []

SeeAlso []

Definition at line 151 of file hopUtil.c.

152 {
153  Hop_Obj_t * pNode0, * pNode1;
154  // check that the node is regular
155  assert( !Hop_IsComplement(pNode) );
156  // if the node is not AND, this is not MUX
157  if ( !Hop_ObjIsAnd(pNode) )
158  return 0;
159  // if the children are not complemented, this is not MUX
160  if ( !Hop_ObjFaninC0(pNode) || !Hop_ObjFaninC1(pNode) )
161  return 0;
162  // get children
163  pNode0 = Hop_ObjFanin0(pNode);
164  pNode1 = Hop_ObjFanin1(pNode);
165  // if the children are not ANDs, this is not MUX
166  if ( !Hop_ObjIsAnd(pNode0) || !Hop_ObjIsAnd(pNode1) )
167  return 0;
168  // otherwise the node is MUX iff it has a pair of equal grandchildren
169  return (Hop_ObjFanin0(pNode0) == Hop_ObjFanin0(pNode1) && (Hop_ObjFaninC0(pNode0) ^ Hop_ObjFaninC0(pNode1))) ||
170  (Hop_ObjFanin0(pNode0) == Hop_ObjFanin1(pNode1) && (Hop_ObjFaninC0(pNode0) ^ Hop_ObjFaninC1(pNode1))) ||
171  (Hop_ObjFanin1(pNode0) == Hop_ObjFanin0(pNode1) && (Hop_ObjFaninC1(pNode0) ^ Hop_ObjFaninC0(pNode1))) ||
172  (Hop_ObjFanin1(pNode0) == Hop_ObjFanin1(pNode1) && (Hop_ObjFaninC1(pNode0) ^ Hop_ObjFaninC1(pNode1)));
173 }
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
Definition: hop.h:65
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
#define assert(ex)
Definition: util_old.h:213
void Hop_ObjPrintEqn ( FILE *  pFile,
Hop_Obj_t pObj,
Vec_Vec_t vLevels,
int  Level 
)

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

Synopsis [Prints Eqn formula for the AIG rooted at this node.]

Description [The formula is in terms of PIs, which should have their names assigned in pObj->pData fields.]

SideEffects []

SeeAlso []

Definition at line 322 of file hopUtil.c.

323 {
324  Vec_Ptr_t * vSuper;
325  Hop_Obj_t * pFanin;
326  int fCompl, i;
327  // store the complemented attribute
328  fCompl = Hop_IsComplement(pObj);
329  pObj = Hop_Regular(pObj);
330  // constant case
331  if ( Hop_ObjIsConst1(pObj) )
332  {
333  fprintf( pFile, "%d", !fCompl );
334  return;
335  }
336  // PI case
337  if ( Hop_ObjIsPi(pObj) )
338  {
339  fprintf( pFile, "%s%s", fCompl? "!" : "", (char*)pObj->pData );
340  return;
341  }
342  // AND case
343  Vec_VecExpand( vLevels, Level );
344  vSuper = Vec_VecEntry(vLevels, Level);
345  Hop_ObjCollectMulti( pObj, vSuper );
346  fprintf( pFile, "%s", (Level==0? "" : "(") );
347  Vec_PtrForEachEntry( Hop_Obj_t *, vSuper, pFanin, i )
348  {
349  Hop_ObjPrintEqn( pFile, Hop_NotCond(pFanin, fCompl), vLevels, Level+1 );
350  if ( i < Vec_PtrSize(vSuper) - 1 )
351  fprintf( pFile, " %s ", fCompl? "+" : "*" );
352  }
353  fprintf( pFile, "%s", (Level==0? "" : ")") );
354  return;
355 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: hop.h:65
void Hop_ObjPrintEqn(FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
Definition: hopUtil.c:322
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
void * pData
Definition: hop.h:68
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
static void Vec_VecExpand(Vec_Vec_t *p, int Level)
Definition: vecVec.h:190
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
void Hop_ObjCollectMulti(Hop_Obj_t *pRoot, Vec_Ptr_t *vSuper)
Definition: hopUtil.c:133
void Hop_ObjPrintVerbose ( Hop_Obj_t pObj,
int  fHaig 
)

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

Synopsis [Prints node in HAIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 456 of file hopUtil.c.

457 {
458  assert( !Hop_IsComplement(pObj) );
459  printf( "Node %p : ", pObj );
460  if ( Hop_ObjIsConst1(pObj) )
461  printf( "constant 1" );
462  else if ( Hop_ObjIsPi(pObj) )
463  printf( "PI" );
464  else
465  printf( "AND( %p%s, %p%s )",
466  Hop_ObjFanin0(pObj), (Hop_ObjFaninC0(pObj)? "\'" : " "),
467  Hop_ObjFanin1(pObj), (Hop_ObjFaninC1(pObj)? "\'" : " ") );
468  printf( " (refs = %3d)", Hop_ObjRefs(pObj) );
469 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjRefs(Hop_Obj_t *pObj)
Definition: hop.h:176
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
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_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
static int Hop_ObjFaninC0(Hop_Obj_t *pObj)
Definition: hop.h:180
#define assert(ex)
Definition: util_old.h:213
void Hop_ObjPrintVerilog ( FILE *  pFile,
Hop_Obj_t pObj,
Vec_Vec_t vLevels,
int  Level 
)

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

Synopsis [Prints Verilog formula for the AIG rooted at this node.]

Description [The formula is in terms of PIs, which should have their names assigned in pObj->pData fields.]

SideEffects []

SeeAlso []

Definition at line 369 of file hopUtil.c.

370 {
371  Vec_Ptr_t * vSuper;
372  Hop_Obj_t * pFanin, * pFanin0, * pFanin1, * pFaninC;
373  int fCompl, i;
374  // store the complemented attribute
375  fCompl = Hop_IsComplement(pObj);
376  pObj = Hop_Regular(pObj);
377  // constant case
378  if ( Hop_ObjIsConst1(pObj) )
379  {
380  fprintf( pFile, "1\'b%d", !fCompl );
381  return;
382  }
383  // PI case
384  if ( Hop_ObjIsPi(pObj) )
385  {
386  fprintf( pFile, "%s%s", fCompl? "~" : "", (char*)pObj->pData );
387  return;
388  }
389  // EXOR case
390  if ( Hop_ObjIsExor(pObj) )
391  {
392  Vec_VecExpand( vLevels, Level );
393  vSuper = Vec_VecEntry( vLevels, Level );
394  Hop_ObjCollectMulti( pObj, vSuper );
395  fprintf( pFile, "%s", (Level==0? "" : "(") );
396  Vec_PtrForEachEntry( Hop_Obj_t *, vSuper, pFanin, i )
397  {
398  Hop_ObjPrintVerilog( pFile, Hop_NotCond(pFanin, (fCompl && i==0)), vLevels, Level+1 );
399  if ( i < Vec_PtrSize(vSuper) - 1 )
400  fprintf( pFile, " ^ " );
401  }
402  fprintf( pFile, "%s", (Level==0? "" : ")") );
403  return;
404  }
405  // MUX case
406  if ( Hop_ObjIsMuxType(pObj) )
407  {
408  if ( Hop_ObjRecognizeExor( pObj, &pFanin0, &pFanin1 ) )
409  {
410  fprintf( pFile, "%s", (Level==0? "" : "(") );
411  Hop_ObjPrintVerilog( pFile, Hop_NotCond(pFanin0, fCompl), vLevels, Level+1 );
412  fprintf( pFile, " ^ " );
413  Hop_ObjPrintVerilog( pFile, pFanin1, vLevels, Level+1 );
414  fprintf( pFile, "%s", (Level==0? "" : ")") );
415  }
416  else
417  {
418  pFaninC = Hop_ObjRecognizeMux( pObj, &pFanin1, &pFanin0 );
419  fprintf( pFile, "%s", (Level==0? "" : "(") );
420  Hop_ObjPrintVerilog( pFile, pFaninC, vLevels, Level+1 );
421  fprintf( pFile, " ? " );
422  Hop_ObjPrintVerilog( pFile, Hop_NotCond(pFanin1, fCompl), vLevels, Level+1 );
423  fprintf( pFile, " : " );
424  Hop_ObjPrintVerilog( pFile, Hop_NotCond(pFanin0, fCompl), vLevels, Level+1 );
425  fprintf( pFile, "%s", (Level==0? "" : ")") );
426  }
427  return;
428  }
429  // AND case
430  Vec_VecExpand( vLevels, Level );
431  vSuper = Vec_VecEntry(vLevels, Level);
432  Hop_ObjCollectMulti( pObj, vSuper );
433  fprintf( pFile, "%s", (Level==0? "" : "(") );
434  Vec_PtrForEachEntry( Hop_Obj_t *, vSuper, pFanin, i )
435  {
436  Hop_ObjPrintVerilog( pFile, Hop_NotCond(pFanin, fCompl), vLevels, Level+1 );
437  if ( i < Vec_PtrSize(vSuper) - 1 )
438  fprintf( pFile, " %s ", fCompl? "|" : "&" );
439  }
440  fprintf( pFile, "%s", (Level==0? "" : ")") );
441  return;
442 }
int Hop_ObjRecognizeExor(Hop_Obj_t *pObj, Hop_Obj_t **ppFan0, Hop_Obj_t **ppFan1)
Definition: hopUtil.c:187
int Hop_ObjIsMuxType(Hop_Obj_t *pNode)
Definition: hopUtil.c:151
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: hop.h:65
void Hop_ObjPrintVerilog(FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
Definition: hopUtil.c:369
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
void * pData
Definition: hop.h:68
static int Hop_ObjIsExor(Hop_Obj_t *pObj)
Definition: hop.h:159
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
Hop_Obj_t * Hop_ObjRecognizeMux(Hop_Obj_t *pNode, Hop_Obj_t **ppNodeT, Hop_Obj_t **ppNodeE)
Definition: hopUtil.c:231
static void Vec_VecExpand(Vec_Vec_t *p, int Level)
Definition: vecVec.h:190
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
void Hop_ObjCollectMulti(Hop_Obj_t *pRoot, Vec_Ptr_t *vSuper)
Definition: hopUtil.c:133
int Hop_ObjRecognizeExor ( Hop_Obj_t pObj,
Hop_Obj_t **  ppFan0,
Hop_Obj_t **  ppFan1 
)

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

Synopsis [Recognizes what nodes are inputs of the EXOR.]

Description []

SideEffects []

SeeAlso []

Definition at line 187 of file hopUtil.c.

188 {
189  Hop_Obj_t * p0, * p1;
190  assert( !Hop_IsComplement(pObj) );
191  if ( !Hop_ObjIsNode(pObj) )
192  return 0;
193  if ( Hop_ObjIsExor(pObj) )
194  {
195  *ppFan0 = Hop_ObjChild0(pObj);
196  *ppFan1 = Hop_ObjChild1(pObj);
197  return 1;
198  }
199  assert( Hop_ObjIsAnd(pObj) );
200  p0 = Hop_ObjChild0(pObj);
201  p1 = Hop_ObjChild1(pObj);
202  if ( !Hop_IsComplement(p0) || !Hop_IsComplement(p1) )
203  return 0;
204  p0 = Hop_Regular(p0);
205  p1 = Hop_Regular(p1);
206  if ( !Hop_ObjIsAnd(p0) || !Hop_ObjIsAnd(p1) )
207  return 0;
208  if ( Hop_ObjFanin0(p0) != Hop_ObjFanin0(p1) || Hop_ObjFanin1(p0) != Hop_ObjFanin1(p1) )
209  return 0;
210  if ( Hop_ObjFaninC0(p0) == Hop_ObjFaninC0(p1) || Hop_ObjFaninC1(p0) == Hop_ObjFaninC1(p1) )
211  return 0;
212  *ppFan0 = Hop_ObjChild0(p0);
213  *ppFan1 = Hop_ObjChild1(p0);
214  return 1;
215 }
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_ObjIsNode(Hop_Obj_t *pObj)
Definition: hop.h:160
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
static int Hop_ObjIsAnd(Hop_Obj_t *pObj)
Definition: hop.h:158
Definition: hop.h:65
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 int Hop_ObjIsExor(Hop_Obj_t *pObj)
Definition: hop.h:159
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
#define assert(ex)
Definition: util_old.h:213
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
Hop_Obj_t* Hop_ObjRecognizeMux ( Hop_Obj_t pNode,
Hop_Obj_t **  ppNodeT,
Hop_Obj_t **  ppNodeE 
)

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

Synopsis [Recognizes what nodes are control and data inputs of a MUX.]

Description [If the node is a MUX, returns the control variable C. Assigns nodes T and E to be the then and else variables of the MUX. Node C is never complemented. Nodes T and E can be complemented. This function also recognizes EXOR/NEXOR gates as MUXes.]

SideEffects []

SeeAlso []

Definition at line 231 of file hopUtil.c.

232 {
233  Hop_Obj_t * pNode0, * pNode1;
234  assert( !Hop_IsComplement(pNode) );
235  assert( Hop_ObjIsMuxType(pNode) );
236  // get children
237  pNode0 = Hop_ObjFanin0(pNode);
238  pNode1 = Hop_ObjFanin1(pNode);
239 
240  // find the control variable
241  if ( Hop_ObjFanin1(pNode0) == Hop_ObjFanin1(pNode1) && (Hop_ObjFaninC1(pNode0) ^ Hop_ObjFaninC1(pNode1)) )
242  {
243 // if ( Fraig_IsComplement(pNode1->p2) )
244  if ( Hop_ObjFaninC1(pNode0) )
245  { // pNode2->p2 is positive phase of C
246  *ppNodeT = Hop_Not(Hop_ObjChild0(pNode1));//pNode2->p1);
247  *ppNodeE = Hop_Not(Hop_ObjChild0(pNode0));//pNode1->p1);
248  return Hop_ObjChild1(pNode1);//pNode2->p2;
249  }
250  else
251  { // pNode1->p2 is positive phase of C
252  *ppNodeT = Hop_Not(Hop_ObjChild0(pNode0));//pNode1->p1);
253  *ppNodeE = Hop_Not(Hop_ObjChild0(pNode1));//pNode2->p1);
254  return Hop_ObjChild1(pNode0);//pNode1->p2;
255  }
256  }
257  else if ( Hop_ObjFanin0(pNode0) == Hop_ObjFanin0(pNode1) && (Hop_ObjFaninC0(pNode0) ^ Hop_ObjFaninC0(pNode1)) )
258  {
259 // if ( Fraig_IsComplement(pNode1->p1) )
260  if ( Hop_ObjFaninC0(pNode0) )
261  { // pNode2->p1 is positive phase of C
262  *ppNodeT = Hop_Not(Hop_ObjChild1(pNode1));//pNode2->p2);
263  *ppNodeE = Hop_Not(Hop_ObjChild1(pNode0));//pNode1->p2);
264  return Hop_ObjChild0(pNode1);//pNode2->p1;
265  }
266  else
267  { // pNode1->p1 is positive phase of C
268  *ppNodeT = Hop_Not(Hop_ObjChild1(pNode0));//pNode1->p2);
269  *ppNodeE = Hop_Not(Hop_ObjChild1(pNode1));//pNode2->p2);
270  return Hop_ObjChild0(pNode0);//pNode1->p1;
271  }
272  }
273  else if ( Hop_ObjFanin0(pNode0) == Hop_ObjFanin1(pNode1) && (Hop_ObjFaninC0(pNode0) ^ Hop_ObjFaninC1(pNode1)) )
274  {
275 // if ( Fraig_IsComplement(pNode1->p1) )
276  if ( Hop_ObjFaninC0(pNode0) )
277  { // pNode2->p2 is positive phase of C
278  *ppNodeT = Hop_Not(Hop_ObjChild0(pNode1));//pNode2->p1);
279  *ppNodeE = Hop_Not(Hop_ObjChild1(pNode0));//pNode1->p2);
280  return Hop_ObjChild1(pNode1);//pNode2->p2;
281  }
282  else
283  { // pNode1->p1 is positive phase of C
284  *ppNodeT = Hop_Not(Hop_ObjChild1(pNode0));//pNode1->p2);
285  *ppNodeE = Hop_Not(Hop_ObjChild0(pNode1));//pNode2->p1);
286  return Hop_ObjChild0(pNode0);//pNode1->p1;
287  }
288  }
289  else if ( Hop_ObjFanin1(pNode0) == Hop_ObjFanin0(pNode1) && (Hop_ObjFaninC1(pNode0) ^ Hop_ObjFaninC0(pNode1)) )
290  {
291 // if ( Fraig_IsComplement(pNode1->p2) )
292  if ( Hop_ObjFaninC1(pNode0) )
293  { // pNode2->p1 is positive phase of C
294  *ppNodeT = Hop_Not(Hop_ObjChild1(pNode1));//pNode2->p2);
295  *ppNodeE = Hop_Not(Hop_ObjChild0(pNode0));//pNode1->p1);
296  return Hop_ObjChild0(pNode1);//pNode2->p1;
297  }
298  else
299  { // pNode1->p2 is positive phase of C
300  *ppNodeT = Hop_Not(Hop_ObjChild0(pNode0));//pNode1->p1);
301  *ppNodeE = Hop_Not(Hop_ObjChild1(pNode1));//pNode2->p2);
302  return Hop_ObjChild1(pNode0);//pNode1->p2;
303  }
304  }
305  assert( 0 ); // this is not MUX
306  return NULL;
307 }
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
int Hop_ObjIsMuxType(Hop_Obj_t *pNode)
Definition: hopUtil.c:151
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Definition: hop.h:65
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
#define assert(ex)
Definition: util_old.h:213