ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sswAig.c
Go to the documentation of this file.
1
20
21#include "sswInt.h"
22
24
25
29
33
46{
47 Ssw_Frm_t * p;
48 p = ABC_ALLOC( Ssw_Frm_t, 1 );
49 memset( p, 0, sizeof(Ssw_Frm_t) );
50 p->pAig = pAig;
51 p->nObjs = Aig_ManObjNumMax( pAig );
52 p->nFrames = 0;
53 p->pFrames = NULL;
54 p->vAig2Frm = Vec_PtrAlloc( 0 );
55 Vec_PtrFill( p->vAig2Frm, 2 * p->nObjs, NULL );
56 return p;
57}
58
71{
72 if ( p->pFrames )
73 Aig_ManStop( p->pFrames );
74 Vec_PtrFree( p->vAig2Frm );
75 ABC_FREE( p );
76}
77
90{
91 int Counter = 1;
92 assert( pNode->nRefs > 0 );
93 if ( --pNode->nRefs > 0 )
94 return 0;
95 assert( pNode->nRefs == 0 );
96 if ( Aig_ObjIsCi(pNode) || Aig_ObjIsConst1(pNode) )
97 return 0;
98 Counter += Aig_ObjDeref_rec( Aig_ObjFanin0(pNode) );
99 Counter += Aig_ObjDeref_rec( Aig_ObjFanin1(pNode) );
100 return Counter;
101}
103{
104 int Counter = 1;
105 assert( pNode->nRefs >= 0 );
106 if ( pNode->nRefs++ > 0 )
107 return 0;
108 assert( pNode->nRefs == 1 );
109 if ( Aig_ObjIsCi(pNode) || Aig_ObjIsConst1(pNode) )
110 return 0;
111 Counter += Aig_ObjRef_rec( Aig_ObjFanin0(pNode) );
112 Counter += Aig_ObjRef_rec( Aig_ObjFanin1(pNode) );
113 return Counter;
114}
115int Aig_ManConeSize( Aig_Obj_t * pNode0, Aig_Obj_t * pNode1 )
116{
117 pNode0 = Aig_Regular(pNode0);
118 pNode1 = Aig_Regular(pNode1);
119 Aig_ObjRef( pNode0 );
120 Aig_ObjRef( pNode1 );
121 int Count0 = Aig_ObjDeref_rec(pNode0) + Aig_ObjDeref_rec(pNode1);
122 int Count1 = Aig_ObjRef_rec(pNode0) + Aig_ObjRef_rec(pNode1);
123 Aig_ObjDeref( pNode0 );
124 Aig_ObjDeref( pNode1 );
125 assert( Count0 == Count1 );
126 return Count0;
127}
128
140static inline void Ssw_FramesConstrainNode( Ssw_Man_t * p, Aig_Man_t * pFrames, Aig_Man_t * pAig, Aig_Obj_t * pObj, int iFrame, int fTwoPos )
141{
142 Aig_Obj_t * pObjNew, * pObjNew2, * pObjRepr, * pObjReprNew, * pMiter;
143 // skip nodes without representative
144 pObjRepr = Aig_ObjRepr(pAig, pObj);
145 if ( pObjRepr == NULL )
146 return;
147 p->nConstrTotal++;
148 assert( pObjRepr->Id < pObj->Id );
149 // get the new node
150 pObjNew = Ssw_ObjFrame( p, pObj, iFrame );
151 // get the new node of the representative
152 pObjReprNew = Ssw_ObjFrame( p, pObjRepr, iFrame );
153 // if this is the same node, no need to add constraints
154 if ( pObj->fPhase == pObjRepr->fPhase )
155 {
156 assert( pObjNew != Aig_Not(pObjReprNew) );
157 if ( pObjNew == pObjReprNew )
158 return;
159 }
160 else
161 {
162 assert( pObjNew != pObjReprNew );
163 if ( pObjNew == Aig_Not(pObjReprNew) )
164 return;
165 }
166 p->nConstrReduced++;
167 // these are different nodes - perform speculative reduction
168 pObjNew2 = Aig_NotCond( pObjReprNew, pObj->fPhase ^ pObjRepr->fPhase );
169 // set the new node
170 Ssw_ObjSetFrame( p, pObj, iFrame, pObjNew2 );
171 // add the constraint
172 if ( fTwoPos )
173 {
174 if ( p->pPars->nSkipLimit ) {
175 if ( Aig_ManConeSize(pObjNew, pObjNew2) < p->pPars->nSkipLimit ) {
176 Aig_ObjCreateCo( pFrames, pObjNew2 );
177 Aig_ObjCreateCo( pFrames, pObjNew );
178 }
179 }
180 else if ( p->pPars->nSkip == 0 || rand() % p->pPars->nSkip == 0 ) {
181 Aig_ObjCreateCo( pFrames, pObjNew2 );
182 Aig_ObjCreateCo( pFrames, pObjNew );
183 }
184 }
185 else
186 {
187 pMiter = Aig_Exor( pFrames, pObjNew, pObjNew2 );
188 Aig_ObjCreateCo( pFrames, Aig_NotCond(pMiter, Aig_ObjPhaseReal(pMiter)) );
189 }
190}
191
204{
205 Aig_Man_t * pFrames;
206 Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew;
207 int i, f, iLits;
208 assert( p->pFrames == NULL );
209 assert( Aig_ManRegNum(p->pAig) > 0 );
210 assert( Aig_ManRegNum(p->pAig) < Aig_ManCiNum(p->pAig) );
211 p->nConstrTotal = p->nConstrReduced = 0;
212
213 // start the fraig package
214 pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->nFrames );
215 // create latches for the first frame
216 Saig_ManForEachLo( p->pAig, pObj, i )
217 Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
218 // add timeframes
219 iLits = 0;
220 if ( p->pPars->nSkip )
221 srand(1);
222 for ( f = 0; f < p->pPars->nFramesK; f++ )
223 {
224 // map constants and PIs
225 Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(pFrames) );
226 Saig_ManForEachPi( p->pAig, pObj, i )
227 {
228 pObjNew = Aig_ObjCreateCi(pFrames);
229 pObjNew->fPhase = (p->vInits != NULL) && Vec_IntEntry(p->vInits, iLits++);
230 Ssw_ObjSetFrame( p, pObj, f, pObjNew );
231 }
232 // set the constraints on the latch outputs
233 Saig_ManForEachLo( p->pAig, pObj, i )
234 Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, f, 1 );
235 // add internal nodes of this frame
236 Aig_ManForEachNode( p->pAig, pObj, i )
237 {
238 pObjNew = Aig_And( pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
239 Ssw_ObjSetFrame( p, pObj, f, pObjNew );
240 Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, f, 1 );
241 }
242 // transfer to the primary outputs
243 Aig_ManForEachCo( p->pAig, pObj, i )
244 Ssw_ObjSetFrame( p, pObj, f, Ssw_ObjChild0Fra(p, pObj,f) );
245 // transfer latch input to the latch outputs
246 Saig_ManForEachLiLo( p->pAig, pObjLi, pObjLo, i )
247 Ssw_ObjSetFrame( p, pObjLo, f+1, Ssw_ObjFrame(p, pObjLi,f) );
248 }
249 assert( p->vInits == NULL || Vec_IntSize(p->vInits) == iLits + Saig_ManPiNum(p->pAig) );
250 // add the POs for the latch outputs of the last frame
251 Saig_ManForEachLo( p->pAig, pObj, i )
252 Aig_ObjCreateCo( pFrames, Ssw_ObjFrame( p, pObj, p->pPars->nFramesK ) );
253 // remove dangling nodes
254 Aig_ManCleanup( pFrames );
255 // make sure the satisfying assignment is node assigned
256 assert( pFrames->pData == NULL );
257//Aig_ManShow( pFrames, 0, NULL );
258 return pFrames;
259}
260
273{
274 Aig_Man_t * pFrames;
275 Aig_Obj_t * pObj, * pObjNew;
276 int i;
277 assert( p->pFrames == NULL );
278 assert( Aig_ManRegNum(p->pAig) > 0 );
279 assert( Aig_ManRegNum(p->pAig) < Aig_ManCiNum(p->pAig) );
280 p->nConstrTotal = p->nConstrReduced = 0;
281
282 // start the fraig package
283 pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->nFrames );
284 pFrames->pName = Abc_UtilStrsav( p->pAig->pName );
285 // map constants and PIs
286 Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), 0, Aig_ManConst1(pFrames) );
287 Saig_ManForEachPi( p->pAig, pObj, i )
288 Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
289 // create latches for the first frame
290 Saig_ManForEachLo( p->pAig, pObj, i )
291 Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
292 // set the constraints on the latch outputs
293 Saig_ManForEachLo( p->pAig, pObj, i )
294 Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, 0, 0 );
295 // add internal nodes of this frame
296 Aig_ManForEachNode( p->pAig, pObj, i )
297 {
298 pObjNew = Aig_And( pFrames, Ssw_ObjChild0Fra(p, pObj, 0), Ssw_ObjChild1Fra(p, pObj, 0) );
299 Ssw_ObjSetFrame( p, pObj, 0, pObjNew );
300 Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, 0, 0 );
301 }
302 // add the POs for the latch outputs of the last frame
303 Saig_ManForEachLi( p->pAig, pObj, i )
304 Aig_ObjCreateCo( pFrames, Ssw_ObjChild0Fra(p, pObj,0) );
305 // remove dangling nodes
306 Aig_ManCleanup( pFrames );
307 Aig_ManSetRegNum( pFrames, Aig_ManRegNum(p->pAig) );
308// Abc_Print( 1, "SpecRed: Total constraints = %d. Reduced constraints = %d.\n",
309// p->nConstrTotal, p->nConstrReduced );
310 return pFrames;
311}
312
316
317
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
Definition aigMan.c:438
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition aigObj.c:66
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Aig_Obj_t * Aig_Exor(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:220
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition aigMan.c:47
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
int Aig_ManCleanup(Aig_Man_t *p)
Definition aigMan.c:265
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigObj.c:45
Cube * p
Definition exorList.c:222
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition saig.h:101
#define Saig_ManForEachLi(p, pObj, i)
Definition saig.h:98
#define Saig_ManForEachLo(p, pObj, i)
Definition saig.h:96
#define Saig_ManForEachPi(p, pObj, i)
Definition saig.h:91
ABC_NAMESPACE_IMPL_START Ssw_Frm_t * Ssw_FrmStart(Aig_Man_t *pAig)
DECLARATIONS ///.
Definition sswAig.c:45
int Aig_ManConeSize(Aig_Obj_t *pNode0, Aig_Obj_t *pNode1)
Definition sswAig.c:115
int Aig_ObjRef_rec(Aig_Obj_t *pNode)
Definition sswAig.c:102
Aig_Man_t * Ssw_FramesWithClasses(Ssw_Man_t *p)
Definition sswAig.c:203
void Ssw_FrmStop(Ssw_Frm_t *p)
Definition sswAig.c:70
Aig_Man_t * Ssw_SpeculativeReduction(Ssw_Man_t *p)
Definition sswAig.c:272
int Aig_ObjDeref_rec(Aig_Obj_t *pNode)
Definition sswAig.c:89
typedefABC_NAMESPACE_HEADER_START struct Ssw_Man_t_ Ssw_Man_t
INCLUDES ///.
Definition sswInt.h:47
struct Ssw_Frm_t_ Ssw_Frm_t
Definition sswInt.h:48
int Id
Definition aig.h:85
unsigned int nRefs
Definition aig.h:81
unsigned int fPhase
Definition aig.h:78
#define assert(ex)
Definition util_old.h:213
char * memset()