abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wlcAbs.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [wlcAbs.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Verilog parser.]
8 
9  Synopsis [Abstraction for word-level networks.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - August 22, 2014.]
16 
17  Revision [$Id: wlcAbs.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "wlc.h"
22 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// FUNCTION DEFINITIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 /**Function*************************************************************
34 
35  Synopsis [Check if two objects have the same input/output signatures.]
36 
37  Description []
38 
39  SideEffects []
40 
41  SeeAlso []
42 
43 ***********************************************************************/
45 {
46  Wlc_Obj_t * pFanin, * pFanin2; int k;
47  if ( Wlc_ObjRange(pObj) != Wlc_ObjRange(pObj2) )
48  return 0;
49  if ( Wlc_ObjIsSigned(pObj) != Wlc_ObjIsSigned(pObj2) )
50  return 0;
51  if ( Wlc_ObjFaninNum(pObj) != Wlc_ObjFaninNum(pObj2) )
52  return 0;
53  for ( k = 0; k < Wlc_ObjFaninNum(pObj); k++ )
54  {
55  pFanin = Wlc_ObjFanin(p, pObj, k);
56  pFanin2 = Wlc_ObjFanin(p, pObj2, k);
57  if ( Wlc_ObjRange(pFanin) != Wlc_ObjRange(pFanin2) )
58  return 0;
59  if ( Wlc_ObjIsSigned(pFanin) != Wlc_ObjIsSigned(pFanin2) )
60  return 0;
61  }
62  return 1;
63 }
64 
65 /**Function*************************************************************
66 
67  Synopsis [Collect IDs of the multipliers.]
68 
69  Description []
70 
71  SideEffects []
72 
73  SeeAlso []
74 
75 ***********************************************************************/
77 {
78  Wlc_Obj_t * pObj; int i;
79  Vec_Int_t * vBoxIds = Vec_IntAlloc( 100 );
80  Wlc_NtkForEachObj( p, pObj, i )
81  if ( pObj->Type == WLC_OBJ_ARI_MULTI )
82  Vec_IntPush( vBoxIds, i );
83  if ( Vec_IntSize( vBoxIds ) > 0 )
84  return vBoxIds;
85  Vec_IntFree( vBoxIds );
86  return NULL;
87 }
88 
89 /**Function*************************************************************
90 
91  Synopsis [Returns all pairs of uifable multipliers.]
92 
93  Description []
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
101 {
102  Vec_Int_t * vMultis = Wlc_NtkCollectMultipliers( p );
103  Vec_Int_t * vPairs = Vec_IntAlloc( 2 );
104  Wlc_Obj_t * pObj, * pObj2; int i, k;
105  // iterate through unique pairs
106  Wlc_NtkForEachObjVec( vMultis, p, pObj, i )
107  Wlc_NtkForEachObjVec( vMultis, p, pObj2, k )
108  {
109  if ( k == i )
110  break;
111  if ( Wlc_NtkPairIsUifable( p, pObj, pObj2 ) )
112  {
113  Vec_IntPush( vPairs, Wlc_ObjId(p, pObj) );
114  Vec_IntPush( vPairs, Wlc_ObjId(p, pObj2) );
115  }
116  }
117  Vec_IntFree( vMultis );
118  if ( Vec_IntSize( vPairs ) > 0 )
119  return vPairs;
120  Vec_IntFree( vPairs );
121  return NULL;
122 }
123 
124 
125 
126 /**Function*************************************************************
127 
128  Synopsis [Abstracts nodes by replacing their outputs with new PIs.]
129 
130  Description [If array is NULL, abstract all multipliers.]
131 
132  SideEffects []
133 
134  SeeAlso []
135 
136 ***********************************************************************/
138 {
139  Vec_Int_t * vNodes = vNodesInit;
140  Wlc_Ntk_t * pNew;
141  Wlc_Obj_t * pObj;
142  int i, k, iObj, iFanin;
143  // get multipliers if not given
144  if ( vNodes == NULL )
145  vNodes = Wlc_NtkCollectMultipliers( p );
146  if ( vNodes == NULL )
147  return NULL;
148  // mark nodes
149  Wlc_NtkForEachObjVec( vNodes, p, pObj, i )
150  pObj->Mark = 1;
151  // iterate through the nodes in the DFS order
152  Wlc_NtkCleanCopy( p );
153  Wlc_NtkForEachObj( p, pObj, i )
154  {
155  if ( i == Vec_IntSize(&p->vCopies) )
156  break;
157  if ( pObj->Mark ) {
158  // clean
159  pObj->Mark = 0;
160  // add fresh PI with the same number of bits
161  iObj = Wlc_ObjAlloc( p, WLC_OBJ_PI, Wlc_ObjIsSigned(pObj), Wlc_ObjRange(pObj) - 1, 0 );
162  }
163  else {
164  // update fanins
165  Wlc_ObjForEachFanin( pObj, iFanin, k )
166  Wlc_ObjFanins(pObj)[k] = Wlc_ObjCopy(p, iFanin);
167  // node to remain
168  iObj = i;
169  }
170  Wlc_ObjSetCopy( p, i, iObj );
171  }
172  // POs do not change in this procedure
173  if ( vNodes != vNodesInit )
174  Vec_IntFree( vNodes );
175  // reconstruct topological order
176  pNew = Wlc_NtkDupDfs( p );
177  Wlc_NtkTransferNames( pNew, p );
178  return pNew;
179 }
180 
181 /**Function*************************************************************
182 
183  Synopsis [Adds UIF constraints to node pairs and updates POs.]
184 
185  Description []
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
193 {
194  Vec_Int_t * vPairs = vPairsInit;
195  Wlc_Ntk_t * pNew;
196  Wlc_Obj_t * pObj, * pObj2;
197  Vec_Int_t * vUifConstrs, * vCompares, * vFanins;
198  int i, k, iObj, iObj2, iObjNew, iObjNew2;
199  int iFanin, iFanin2, iFaninNew;
200  // get multiplier pairs if not given
201  if ( vPairs == NULL )
202  vPairs = Wlc_NtkFindUifableMultiplierPairs( p );
203  if ( vPairs == NULL )
204  return NULL;
205  // sanity checks
206  assert( Vec_IntSize(vPairs) > 0 && Vec_IntSize(vPairs) % 2 == 0 );
207  // iterate through node pairs
208  vFanins = Vec_IntAlloc( 100 );
209  vCompares = Vec_IntAlloc( 100 );
210  vUifConstrs = Vec_IntAlloc( 100 );
211  Vec_IntForEachEntryDouble( vPairs, iObj, iObj2, i )
212  {
213  // get two nodes
214  pObj = Wlc_NtkObj( p, iObj );
215  pObj2 = Wlc_NtkObj( p, iObj2 );
216  assert( Wlc_NtkPairIsUifable(p, pObj, pObj2) );
217  // create fanin comparator nodes
218  Vec_IntClear( vCompares );
219  Wlc_ObjForEachFanin( pObj, iFanin, k )
220  {
221  iFanin2 = Wlc_ObjFaninId( pObj2, k );
222  Vec_IntFillTwo( vFanins, 2, iFanin, iFanin2 );
223  iFaninNew = Wlc_ObjCreate( p, WLC_OBJ_COMP_NOTEQU, 0, 0, 0, vFanins );
224  Vec_IntPush( vCompares, iFaninNew );
225  // note that a pointer to Wlc_Obj_t (for example, pObj) can be invalidated after a call to
226  // Wlc_ObjCreate() due to a possible realloc of the internal array of objects...
227  pObj = Wlc_NtkObj( p, iObj );
228  }
229  // concatenate fanin comparators
230  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vCompares) - 1, 0, vCompares );
231  // create reduction-OR node
232  Vec_IntFill( vFanins, 1, iObjNew );
233  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_REDUCT_OR, 0, 0, 0, vFanins );
234  // craete output comparator node
235  Vec_IntFillTwo( vFanins, 2, iObj, iObj2 );
236  iObjNew2 = Wlc_ObjCreate( p, WLC_OBJ_COMP_EQU, 0, 0, 0, vFanins );
237  // create implication node (iObjNew is already complemented above)
238  Vec_IntFillTwo( vFanins, 2, iObjNew, iObjNew2 );
239  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_LOGIC_OR, 0, 0, 0, vFanins );
240  // save the constraint
241  Vec_IntPush( vUifConstrs, iObjNew );
242  }
243  // derive the AND of the UIF contraints
244  assert( Vec_IntSize(vUifConstrs) > 0 );
245  if ( Vec_IntSize(vUifConstrs) == 1 )
246  iObjNew = Vec_IntEntry( vUifConstrs, 0 );
247  else
248  {
249  // concatenate
250  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vUifConstrs) - 1, 0, vUifConstrs );
251  // create reduction-AND node
252  Vec_IntFill( vFanins, 1, iObjNew );
253  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_REDUCT_AND, 0, 0, 0, vFanins );
254  }
255  // update each PO to point to the new node
256  Wlc_NtkForEachPo( p, pObj, i )
257  {
258  iObj = Wlc_ObjId(p, pObj);
259  Vec_IntFillTwo( vFanins, 2, iObj, iObjNew );
260  iObjNew = Wlc_ObjCreate( p, WLC_OBJ_LOGIC_AND, 0, 0, 0, vFanins );
261  // note that a pointer to Wlc_Obj_t (for example, pObj) can be invalidated after a call to
262  // Wlc_ObjCreate() due to a possible realloc of the internal array of objects...
263  pObj = Wlc_NtkObj( p, iObj );
264  // update PO/CO arrays
265  assert( Vec_IntEntry(&p->vPos, i) == iObj );
266  assert( Vec_IntEntry(&p->vCos, i) == iObj );
267  Vec_IntWriteEntry( &p->vPos, i, iObjNew );
268  Vec_IntWriteEntry( &p->vCos, i, iObjNew );
269  // transfer the PO attribute
270  Wlc_NtkObj(p, iObjNew)->fIsPo = 1;
271  assert( pObj->fIsPo );
272  pObj->fIsPo = 0;
273  }
274  // cleanup
275  Vec_IntFree( vUifConstrs );
276  Vec_IntFree( vCompares );
277  Vec_IntFree( vFanins );
278  if ( vPairs != vPairsInit )
279  Vec_IntFree( vPairs );
280  // reconstruct topological order
281  pNew = Wlc_NtkDupDfs( p );
282  Wlc_NtkTransferNames( pNew, p );
283  return pNew;
284 }
285 
286 ////////////////////////////////////////////////////////////////////////
287 /// END OF FILE ///
288 ////////////////////////////////////////////////////////////////////////
289 
290 
292 
static int Wlc_ObjId(Wlc_Ntk_t *p, Wlc_Obj_t *pObj)
Definition: wlc.h:161
static int Wlc_ObjIsSigned(Wlc_Obj_t *p)
Definition: wlc.h:178
#define Wlc_ObjForEachFanin(pObj, iFanin, i)
Definition: wlc.h:221
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 Wlc_Obj_t * Wlc_NtkObj(Wlc_Ntk_t *p, int Id)
Definition: wlc.h:149
#define Wlc_NtkForEachObjVec(vVec, p, pObj, i)
Definition: wlc.h:208
void Wlc_NtkTransferNames(Wlc_Ntk_t *pNew, Wlc_Ntk_t *p)
Definition: wlcNtk.c:475
Vec_Int_t * Wlc_NtkCollectMultipliers(Wlc_Ntk_t *p)
Definition: wlcAbs.c:76
static Wlc_Obj_t * Wlc_ObjFanin(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int i)
Definition: wlc.h:170
#define Wlc_NtkForEachPo(p, pPo, i)
Definition: wlc.h:212
static int Wlc_ObjRange(Wlc_Obj_t *p)
Definition: wlc.h:175
static void Wlc_NtkCleanCopy(Wlc_Ntk_t *p)
Definition: wlc.h:185
int Wlc_ObjAlloc(Wlc_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition: wlcNtk.c:141
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static void Wlc_ObjSetCopy(Wlc_Ntk_t *p, int iObj, int i)
Definition: wlc.h:187
int Wlc_ObjCreate(Wlc_Ntk_t *p, int Type, int Signed, int End, int Beg, Vec_Int_t *vFanins)
Definition: wlcNtk.c:161
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Wlc_ObjFaninNum(Wlc_Obj_t *p)
Definition: wlc.h:163
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
unsigned Type
Definition: wlc.h:102
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
ABC_NAMESPACE_IMPL_START int Wlc_NtkPairIsUifable(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Wlc_Obj_t *pObj2)
DECLARATIONS ///.
Definition: wlcAbs.c:44
unsigned fIsPo
Definition: wlc.h:105
#define Wlc_NtkForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: wlc.h:206
Wlc_Ntk_t * Wlc_NtkUifNodePairs(Wlc_Ntk_t *p, Vec_Int_t *vPairsInit)
Definition: wlcAbs.c:192
Wlc_Ntk_t * Wlc_NtkAbstractNodes(Wlc_Ntk_t *p, Vec_Int_t *vNodesInit)
Definition: wlcAbs.c:137
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
Vec_Int_t vCopies
Definition: wlc.h:138
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Definition: wlc.h:45
Wlc_Ntk_t * Wlc_NtkDupDfs(Wlc_Ntk_t *p)
Definition: wlcNtk.c:457
static int Wlc_ObjCopy(Wlc_Ntk_t *p, int iObj)
Definition: wlc.h:188
static int Wlc_ObjFaninId(Wlc_Obj_t *p, int i)
Definition: wlc.h:166
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Vec_Int_t vPos
Definition: wlc.h:119
static int * Wlc_ObjFanins(Wlc_Obj_t *p)
Definition: wlc.h:165
unsigned Mark
Definition: wlc.h:104
Vec_Int_t vCos
Definition: wlc.h:121
#define assert(ex)
Definition: util_old.h:213
Vec_Int_t * Wlc_NtkFindUifableMultiplierPairs(Wlc_Ntk_t *p)
Definition: wlcAbs.c:100
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 void Vec_IntFillTwo(Vec_Int_t *p, int nSize, int FillEven, int FillOdd)
Definition: vecInt.h:556