abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaTis.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaTis.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Technology independent synthesis.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaTis.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Derives GIA with MUXes.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Gia_Man_t * pNew, * pTemp;
48  Gia_Obj_t * pObj, * pFan0, * pFan1, * pFanC;
49  int i;
50  assert( p->pMuxes == NULL );
51  ABC_FREE( p->pRefs );
52  Gia_ManCreateRefs( p );
53  // start the new manager
54  pNew = Gia_ManStart( 5000 );
55  pNew->pName = Abc_UtilStrsav( p->pName );
56  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
57  pNew->pMuxes = ABC_CALLOC( unsigned, pNew->nObjsAlloc );
58  // create constant
59  Gia_ManConst0(p)->Value = 0;
60  // create PIs
61  Gia_ManForEachCi( p, pObj, i )
62  pObj->Value = Gia_ManAppendCi( pNew );
63  // create internal nodes
64  Gia_ManHashStart( pNew );
65  Gia_ManForEachAnd( p, pObj, i )
66  {
67  if ( !Gia_ObjIsMuxType(pObj) || (Gia_ObjRefNum(p, Gia_ObjFanin0(pObj)) > 1 && Gia_ObjRefNum(p, Gia_ObjFanin1(pObj)) > 1) )
68  pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
69  else if ( Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1) )
70  pObj->Value = Gia_ManHashXorReal( pNew, Gia_ObjLitCopy(p, Gia_ObjToLit(p, pFan0)), Gia_ObjLitCopy(p, Gia_ObjToLit(p, pFan1)) );
71  else
72  {
73  pFanC = Gia_ObjRecognizeMux( pObj, &pFan1, &pFan0 );
74  pObj->Value = Gia_ManHashMuxReal( pNew, Gia_ObjLitCopy(p, Gia_ObjToLit(p, pFanC)), Gia_ObjLitCopy(p, Gia_ObjToLit(p, pFan1)), Gia_ObjLitCopy(p, Gia_ObjToLit(p, pFan0)) );
75  }
76  }
77  Gia_ManHashStop( pNew );
78  // create ROs
79  Gia_ManForEachCo( p, pObj, i )
80  pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
81  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
82  // perform cleanup
83  pNew = Gia_ManCleanup( pTemp = pNew );
84  Gia_ManStop( pTemp );
85  return pNew;
86 }
87 
88 /**Function*************************************************************
89 
90  Synopsis []
91 
92  Description []
93 
94  SideEffects []
95 
96  SeeAlso []
97 
98 ***********************************************************************/
99 void Gia_ManTisCollectMffc_rec( Gia_Man_t * p, int Id, Vec_Int_t * vMffc, Vec_Int_t * vLeaves )
100 {
101  Gia_Obj_t * pObj;
102  if ( Gia_ObjIsTravIdCurrentId(p, Id) )
103  return;
105  if ( Gia_ObjRefNumId(p, Id) > 1 )
106  {
107  Vec_IntPush( vLeaves, Id );
108  return;
109  }
110  pObj = Gia_ManObj( p, Id );
111  if ( Gia_ObjIsCi(pObj) )
112  {
113  Vec_IntPush( vLeaves, Id );
114  return;
115  }
116  assert( Gia_ObjIsAnd(pObj) );
117  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId0(pObj, Id), vMffc, vLeaves );
118  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId1(pObj, Id), vMffc, vLeaves );
119  if ( Gia_ObjIsMuxId(p, Id) )
120  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId2(p, Id), vMffc, vLeaves );
121  Vec_IntPush( vMffc, Id );
122 }
123 void Gia_ManTisCollectMffc( Gia_Man_t * p, int Id, Vec_Int_t * vMffc, Vec_Int_t * vLeaves )
124 {
125  Gia_Obj_t * pObj = Gia_ManObj( p, Id );
126  assert( Gia_ObjIsAnd(pObj) );
127  Vec_IntClear( vMffc );
128  Vec_IntClear( vLeaves );
130  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId0(pObj, Id), vMffc, vLeaves );
131  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId1(pObj, Id), vMffc, vLeaves );
132  if ( Gia_ObjIsMuxId(p, Id) )
133  Gia_ManTisCollectMffc_rec( p, Gia_ObjFaninId2(p, Id), vMffc, vLeaves );
134  Vec_IntPush( vMffc, Id );
135 }
136 
137 /**Function*************************************************************
138 
139  Synopsis []
140 
141  Description []
142 
143  SideEffects []
144 
145  SeeAlso []
146 
147 ***********************************************************************/
148 void Gia_ManTisPrintMffc( Gia_Man_t * p, int Id, Vec_Int_t * vMffc, Vec_Int_t * vLeaves )
149 {
150  Gia_Obj_t * pObj;
151  int i;
152  printf( "MFFC %d has %d nodes and %d leaves:\n", Id, Vec_IntSize(vMffc), Vec_IntSize(vLeaves) );
153  Gia_ManForEachObjVecReverse( vMffc, p, pObj, i )
154  {
155  printf( "Node %2d : ", Vec_IntSize(vMffc) - 1 - i );
156  Gia_ObjPrint( p, pObj );
157  }
158  Gia_ManForEachObjVec( vLeaves, p, pObj, i )
159  {
160  printf( "Leaf %2d : ", i );
161  Gia_ObjPrint( p, pObj );
162  }
163  printf( "\n" );
164 }
165 
166 /**Function*************************************************************
167 
168  Synopsis []
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176 ***********************************************************************/
177 void Gia_ManTisTest( Gia_Man_t * pInit )
178 {
179  Gia_Man_t * p;
180  Gia_Obj_t * pObj;
181  Vec_Int_t * vMffc, * vLeaves;
182  int i;
183  vMffc = Vec_IntAlloc( 10 );
184  vLeaves = Vec_IntAlloc( 10 );
185  p = Gia_ManTisDupMuxes( pInit );
186  Gia_ManCreateRefs( p );
187  Gia_ManForEachAnd( p, pObj, i )
188  {
189  if ( Gia_ObjRefNumId(p, i) == 1 )
190  continue;
191  Gia_ManTisCollectMffc( p, i, vMffc, vLeaves );
192  Gia_ManTisPrintMffc( p, i, vMffc, vLeaves );
193  }
194  Gia_ManForEachCo( p, pObj, i )
195  {
196  if ( Gia_ObjRefNumId(p, Gia_ObjFaninId0p(p, pObj)) > 1 )
197  continue;
198  Gia_ManTisCollectMffc( p, Gia_ObjFaninId0p(p, pObj), vMffc, vLeaves );
199  Gia_ManTisPrintMffc( p, Gia_ObjFaninId0p(p, pObj), vMffc, vLeaves );
200  }
201  Gia_ManStop( p );
202  Vec_IntFree( vMffc );
203  Vec_IntFree( vLeaves );
204 }
205 
206 
207 ////////////////////////////////////////////////////////////////////////
208 /// END OF FILE ///
209 ////////////////////////////////////////////////////////////////////////
210 
211 
213 
int nObjsAlloc
Definition: gia.h:102
static int Gia_ObjToLit(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:497
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
void Gia_ManTisPrintMffc(Gia_Man_t *p, int Id, Vec_Int_t *vMffc, Vec_Int_t *vLeaves)
Definition: giaTis.c:148
int Gia_ObjRecognizeExor(Gia_Obj_t *pObj, Gia_Obj_t **ppFan0, Gia_Obj_t **ppFan1)
Definition: giaUtil.c:921
void Gia_ManTisTest(Gia_Man_t *pInit)
Definition: giaTis.c:177
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
static int Gia_ObjRefNumId(Gia_Man_t *p, int Id)
Definition: gia.h:518
unsigned * pMuxes
Definition: gia.h:104
static int Gia_ObjRefNum(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:521
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
int * pRefs
Definition: gia.h:114
Definition: gia.h:75
void Gia_ManTisCollectMffc(Gia_Man_t *p, int Id, Vec_Int_t *vMffc, Vec_Int_t *vLeaves)
Definition: giaTis.c:123
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
static int Gia_ObjIsMuxId(Gia_Man_t *p, int iObj)
Definition: gia.h:424
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Gia_ManHashStart(Gia_Man_t *p)
Definition: giaHash.c:117
#define Gia_ManForEachObjVecReverse(vVec, p, pObj, i)
Definition: gia.h:990
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
int Gia_ManHashXorReal(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:465
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaUtil.c:1258
void Gia_ManTisCollectMffc_rec(Gia_Man_t *p, int Id, Vec_Int_t *vMffc, Vec_Int_t *vLeaves)
Definition: giaTis.c:99
static int Gia_ObjLitCopy(Gia_Man_t *p, int iLit)
Definition: gia.h:479
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
static int Gia_ObjIsTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:536
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition: gia.h:988
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
Definition: giaUtil.c:885
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition: giaUtil.c:959
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
ABC_NAMESPACE_IMPL_START Gia_Man_t * Gia_ManTisDupMuxes(Gia_Man_t *p)
DECLARATIONS ///.
Definition: giaTis.c:45
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjFaninId2(Gia_Man_t *p, int ObjId)
Definition: gia.h:462
unsigned Value
Definition: gia.h:87
int Gia_ManHashMuxReal(Gia_Man_t *p, int iLitC, int iLit1, int iLit0)
Definition: giaHash.c:517
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
static void Gia_ObjSetTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:535
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387