abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaAgi.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaAig.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis []
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaAig.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 #define AGI_PI ABC_CONST(0xFFFFFFFF00000000)
31 #define AGI_RO ABC_CONST(0xFFFFFFFE00000000)
32 #define AGI_PO ABC_CONST(0xFFFFFFFD00000000)
33 #define AGI_RI ABC_CONST(0xFFFFFFFC00000000)
34 #define AGI_C0 ABC_CONST(0xFFFFFFFBFFFFFFFA)
35 #define AGI_M0 ABC_CONST(0x00000000FFFFFFFF)
36 #define AGI_M1 ABC_CONST(0xFFFFFFFF00000000)
37 
38 typedef struct Agi_Man_t_ Agi_Man_t;
39 struct Agi_Man_t_
40 {
41  char * pName; // name of the AIG
42  char * pSpec; // name of the input file
43  int nCap; // number of objects
44  int nObjs; // number of objects
45  int nNodes; // number of objects
46  int nRegs; // number of registers
47  unsigned nTravIds; // number of objects
48  Vec_Int_t vCis; // comb inputs
49  Vec_Int_t vCos; // comb outputs
50  word * pObjs; // objects
51  unsigned * pThird; // third input
52  unsigned * pTravIds; // traversal IDs
53  unsigned * pNext; // next values
54  unsigned * pTable; // hash table
55  unsigned * pCopy; // hash table
56 };
57 
58 static inline int Agi_ManObjNum( Agi_Man_t * p ) { return p->nObjs; }
59 static inline int Agi_ManCiNum( Agi_Man_t * p ) { return Vec_IntSize( &p->vCis ); }
60 static inline int Agi_ManCoNum( Agi_Man_t * p ) { return Vec_IntSize( &p->vCos ); }
61 static inline int Agi_ManNodeNum( Agi_Man_t * p ) { return p->nNodes; }
62 
63 static inline unsigned Agi_ObjLit0( Agi_Man_t * p, int i ) { return (unsigned)(p->pObjs[i]); }
64 static inline unsigned Agi_ObjLit1( Agi_Man_t * p, int i ) { return (unsigned)(p->pObjs[i] >> 32); }
65 static inline unsigned Agi_ObjLit2( Agi_Man_t * p, int i ) { return p->pThird[i]; }
66 static inline int Agi_ObjVar0( Agi_Man_t * p, int i ) { return Agi_ObjLit0(p, i) >> 1; }
67 static inline int Agi_ObjVar1( Agi_Man_t * p, int i ) { return Agi_ObjLit1(p, i) >> 1; }
68 static inline int Agi_ObjVar2( Agi_Man_t * p, int i ) { return Agi_ObjLit2(p, i) >> 1; }
69 static inline void Agi_ObjSetLit0( Agi_Man_t * p, int i, unsigned l ) { p->pObjs[i] = (p->pObjs[i] & AGI_M1) | (word)l; }
70 static inline void Agi_ObjSetLit1( Agi_Man_t * p, int i, unsigned l ) { p->pObjs[i] = (p->pObjs[i] & AGI_M0) | ((word)l << 32); }
71 static inline void Agi_ObjSetLit2( Agi_Man_t * p, int i, unsigned l ) { p->pThird[i] = l; }
72 
73 static inline int Agi_ObjIsC0( Agi_Man_t * p, int i ) { return (i == 0); }
74 static inline int Agi_ObjIsPi( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_PI) == AGI_PI; }
75 static inline int Agi_ObjIsRo( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_PI) == AGI_RO; }
76 static inline int Agi_ObjIsPo( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_PI) == AGI_PO; }
77 static inline int Agi_ObjIsRi( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_PI) == AGI_RI; }
78 static inline int Agi_ObjIsCi( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_RO) == AGI_RO; }
79 static inline int Agi_ObjIsCo( Agi_Man_t * p, int i ) { return (p->pObjs[i] & AGI_RO) == AGI_PO; }
80 static inline int Agi_ObjIsNode( Agi_Man_t * p, int i ) { return p->pObjs[i] < AGI_C0; }
81 static inline int Agi_ObjIsBuf( Agi_Man_t * p, int i ) { return Agi_ObjLit0(p, i) == Agi_ObjLit1(p, i); }
82 static inline int Agi_ObjIsAnd( Agi_Man_t * p, int i ) { return Agi_ObjIsNode(p, i) && Agi_ObjLit0(p, i) < Agi_ObjLit1(p, i); }
83 static inline int Agi_ObjIsXor( Agi_Man_t * p, int i ) { return Agi_ObjIsNode(p, i) && Agi_ObjLit0(p, i) > Agi_ObjLit1(p, i); }
84 static inline int Agi_ObjIsMux( Agi_Man_t * p, int i ) { return Agi_ObjIsAnd(p, i) && ~Agi_ObjLit2(p, i); }
85 static inline int Agi_ObjIsMaj( Agi_Man_t * p, int i ) { return Agi_ObjIsXor(p, i) && ~Agi_ObjLit2(p, i); }
86 
87 static inline int Agi_ManAppendObj( Agi_Man_t * p )
88 {
89  assert( p->nObjs < p->nCap );
90  return p->nObjs++; // return var
91 }
92 static inline int Agi_ManAppendCi( Agi_Man_t * p )
93 {
94  int iObj = Agi_ManAppendObj( p );
95  p->pObjs[iObj] = AGI_PI | (word)Vec_IntSize(&p->vCis);
96  Vec_IntPush( &p->vCis, iObj );
97  return Abc_Var2Lit( iObj, 0 ); // return lit
98 }
99 static inline int Agi_ManAppendCo( Agi_Man_t * p, int iLit0 )
100 {
101  int iObj = Agi_ManAppendObj( p );
102  p->pObjs[iObj] = AGI_PO | (word)iLit0;
103  Vec_IntPush( &p->vCos, iObj );
104  return Abc_Var2Lit( iObj, 0 ); // return lit
105 }
106 static inline int Agi_ManAppendAnd( Agi_Man_t * p, int iLit0, int iLit1 )
107 {
108  int iObj = Agi_ManAppendObj( p );
109  assert( iLit0 < iLit1 );
110  p->pObjs[iObj] = ((word)iLit1 << 32) | (word)iLit0;
111  p->nNodes++;
112  return Abc_Var2Lit( iObj, 0 ); // return lit
113 }
114 
115 #define Agi_ManForEachCi( p, iCi, i ) Vec_IntForEachEntry( &p->vCis, iCi, i )
116 #define Agi_ManForEachCo( p, iCo, i ) Vec_IntForEachEntry( &p->vCos, iCo, i )
117 #define Agi_ManForEachObj( p, i ) for ( i = 0; i < Agi_ManObjNum(p); i++ )
118 #define Agi_ManForEachObj1( p, i ) for ( i = 1; i < Agi_ManObjNum(p); i++ )
119 #define Agi_ManForEachNode( p, i ) for ( i = 1; i < Agi_ManObjNum(p); i++ ) if ( !Agi_ObjIsNode(p, i) ) {} else
120 
121 ////////////////////////////////////////////////////////////////////////
122 /// FUNCTION DEFINITIONS ///
123 ////////////////////////////////////////////////////////////////////////
124 
125 /**Function*************************************************************
126 
127  Synopsis []
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
136 Agi_Man_t * Agi_ManAlloc( int nCap )
137 {
138  Agi_Man_t * p;
139  nCap = Abc_MaxInt( nCap, 16 );
140  p = ABC_CALLOC( Agi_Man_t, 1 );
141  p->nCap = nCap;
142  p->pObjs = ABC_CALLOC( word, nCap );
143  p->pTravIds = ABC_CALLOC( unsigned, nCap );
144  p->pObjs[0] = AGI_C0;
145  p->nObjs = 1;
146  return p;
147 }
149 {
150  ABC_FREE( p->pObjs );
151  ABC_FREE( p->pTravIds );
152  ABC_FREE( p->vCis.pArray );
153  ABC_FREE( p->vCos.pArray );
154  ABC_FREE( p );
155 }
156 
157 /**Function*************************************************************
158 
159  Synopsis []
160 
161  Description []
162 
163  SideEffects []
164 
165  SeeAlso []
166 
167 ***********************************************************************/
169 {
170  Agi_Man_t * pNew;
171  Gia_Obj_t * pObj;
172  int i;
173  pNew = Agi_ManAlloc( Gia_ManObjNum(p) );
174  Gia_ManForEachObj1( p, pObj, i )
175  if ( Gia_ObjIsAnd(pObj) )
176  pObj->Value = Agi_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
177  else if ( Gia_ObjIsCo(pObj) )
178  pObj->Value = Agi_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
179  else if ( Gia_ObjIsCi(pObj) )
180  pObj->Value = Agi_ManAppendCi( pNew );
181  else assert( 0 );
182  return pNew;
183 }
184 
185 /**Function*************************************************************
186 
187  Synopsis []
188 
189  Description []
190 
191  SideEffects []
192 
193  SeeAlso []
194 
195 ***********************************************************************/
197 {
198  if ( p->pTravIds[i] == p->nTravIds )
199  return 0;
200  p->pTravIds[i] = p->nTravIds;
201  if ( Agi_ObjIsCi(p, i) )
202  return 1;
203  assert( Agi_ObjIsAnd(p, i) );
204  return Agi_ManSuppSize_rec( p, Agi_ObjVar0(p, i) ) + Agi_ManSuppSize_rec( p, Agi_ObjVar1(p, i) );
205 }
207 {
208  p->nTravIds++;
209  return Agi_ManSuppSize_rec( p, i );
210 }
212 {
213  abctime clk = Abc_Clock();
214  int i, Counter = 0;
215  Agi_ManForEachNode( p, i )
216  Counter += (Agi_ManSuppSizeOne(p, i) <= 16);
217  printf( "Nodes with small support %d (out of %d)\n", Counter, Agi_ManNodeNum(p) );
218  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
219  return Counter;
220 
221 }
222 void Agi_ManTest( Gia_Man_t * pGia )
223 {
224  extern int Gia_ManSuppSizeTest( Gia_Man_t * p );
225  Agi_Man_t * p;
226  Gia_ManSuppSizeTest( pGia );
227  p = Agi_ManFromGia( pGia );
228  Agi_ManSuppSizeTest( p );
229  Agi_ManFree( p );
230 }
231 
232 ////////////////////////////////////////////////////////////////////////
233 /// END OF FILE ///
234 ////////////////////////////////////////////////////////////////////////
235 
236 
238 
static int Agi_ManObjNum(Agi_Man_t *p)
Definition: giaAgi.c:58
void Agi_ManFree(Agi_Man_t *p)
Definition: giaAgi.c:148
static int Agi_ObjIsMaj(Agi_Man_t *p, int i)
Definition: giaAgi.c:85
unsigned * pCopy
Definition: giaAgi.c:55
void Agi_ManTest(Gia_Man_t *pGia)
Definition: giaAgi.c:222
#define AGI_M0
Definition: giaAgi.c:35
word * pObjs
Definition: giaAgi.c:50
#define AGI_RI
Definition: giaAgi.c:33
unsigned * pTravIds
Definition: giaAgi.c:52
static int Agi_ObjVar0(Agi_Man_t *p, int i)
Definition: giaAgi.c:66
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static unsigned Agi_ObjLit0(Agi_Man_t *p, int i)
Definition: giaAgi.c:63
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static unsigned Agi_ObjLit1(Agi_Man_t *p, int i)
Definition: giaAgi.c:64
unsigned * pNext
Definition: giaAgi.c:53
#define AGI_M1
Definition: giaAgi.c:36
static int Agi_ManAppendObj(Agi_Man_t *p)
Definition: giaAgi.c:87
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Agi_ObjVar2(Agi_Man_t *p, int i)
Definition: giaAgi.c:68
static void Agi_ObjSetLit0(Agi_Man_t *p, int i, unsigned l)
Definition: giaAgi.c:69
Vec_Int_t vCis
Definition: giaAgi.c:48
Agi_Man_t * Agi_ManFromGia(Gia_Man_t *p)
Definition: giaAgi.c:168
char * pSpec
Definition: giaAgi.c:42
#define AGI_C0
Definition: giaAgi.c:34
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define Agi_ManForEachNode(p, i)
Definition: giaAgi.c:119
static int Agi_ManAppendCi(Agi_Man_t *p)
Definition: giaAgi.c:92
static int Agi_ManAppendCo(Agi_Man_t *p, int iLit0)
Definition: giaAgi.c:99
Definition: gia.h:75
static int Agi_ObjIsRo(Agi_Man_t *p, int i)
Definition: giaAgi.c:75
static int Agi_ManAppendAnd(Agi_Man_t *p, int iLit0, int iLit1)
Definition: giaAgi.c:106
int nCap
Definition: giaAgi.c:43
static int Agi_ObjIsPo(Agi_Man_t *p, int i)
Definition: giaAgi.c:76
static void Agi_ObjSetLit1(Agi_Man_t *p, int i, unsigned l)
Definition: giaAgi.c:70
static int Agi_ObjIsNode(Agi_Man_t *p, int i)
Definition: giaAgi.c:80
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static int Agi_ObjIsPi(Agi_Man_t *p, int i)
Definition: giaAgi.c:74
static int Agi_ObjVar1(Agi_Man_t *p, int i)
Definition: giaAgi.c:67
static int Agi_ObjIsRi(Agi_Man_t *p, int i)
Definition: giaAgi.c:77
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
unsigned * pThird
Definition: giaAgi.c:51
Agi_Man_t * Agi_ManAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: giaAgi.c:136
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Agi_ObjIsMux(Agi_Man_t *p, int i)
Definition: giaAgi.c:84
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static unsigned Agi_ObjLit2(Agi_Man_t *p, int i)
Definition: giaAgi.c:65
static int Counter
#define AGI_PO
Definition: giaAgi.c:32
Vec_Int_t vCos
Definition: giaAgi.c:49
static void Agi_ObjSetLit2(Agi_Man_t *p, int i, unsigned l)
Definition: giaAgi.c:71
int nObjs
Definition: giaAgi.c:44
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
#define AGI_RO
Definition: giaAgi.c:31
int Agi_ManSuppSizeOne(Agi_Man_t *p, int i)
Definition: giaAgi.c:206
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int nRegs
Definition: giaAgi.c:46
unsigned nTravIds
Definition: giaAgi.c:47
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static int Agi_ObjIsCo(Agi_Man_t *p, int i)
Definition: giaAgi.c:79
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
char * pName
Definition: giaAgi.c:41
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Agi_ObjIsC0(Agi_Man_t *p, int i)
Definition: giaAgi.c:73
int nNodes
Definition: giaAgi.c:45
int Agi_ManSuppSize_rec(Agi_Man_t *p, int i)
Definition: giaAgi.c:196
static int Agi_ObjIsXor(Agi_Man_t *p, int i)
Definition: giaAgi.c:83
#define assert(ex)
Definition: util_old.h:213
static int Agi_ObjIsBuf(Agi_Man_t *p, int i)
Definition: giaAgi.c:81
unsigned * pTable
Definition: giaAgi.c:54
unsigned Value
Definition: gia.h:87
static int Agi_ManCoNum(Agi_Man_t *p)
Definition: giaAgi.c:60
static int Agi_ManNodeNum(Agi_Man_t *p)
Definition: giaAgi.c:61
static int Agi_ManCiNum(Agi_Man_t *p)
Definition: giaAgi.c:59
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
int Agi_ManSuppSizeTest(Agi_Man_t *p)
Definition: giaAgi.c:211
static int Agi_ObjIsCi(Agi_Man_t *p, int i)
Definition: giaAgi.c:78
#define AGI_PI
DECLARATIONS ///.
Definition: giaAgi.c:30
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
int Gia_ManSuppSizeTest(Gia_Man_t *p)
Definition: giaDfs.c:276
static int Agi_ObjIsAnd(Agi_Man_t *p, int i)
Definition: giaAgi.c:82