abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sswAig.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sswAig.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Inductive prover with constraints.]
8 
9  Synopsis [AIG manipulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - September 1, 2008.]
16 
17  Revision [$Id: sswAig.c,v 1.00 2008/09/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sswInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Starts the SAT manager.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
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 
59 /**Function*************************************************************
60 
61  Synopsis [Starts the SAT manager.]
62 
63  Description []
64 
65  SideEffects []
66 
67  SeeAlso []
68 
69 ***********************************************************************/
71 {
72  if ( p->pFrames )
73  Aig_ManStop( p->pFrames );
74  Vec_PtrFree( p->vAig2Frm );
75  ABC_FREE( p );
76 }
77 
78 /**Function*************************************************************
79 
80  Synopsis [Performs speculative reduction for one node.]
81 
82  Description []
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
89 static inline void Ssw_FramesConstrainNode( Ssw_Man_t * p, Aig_Man_t * pFrames, Aig_Man_t * pAig, Aig_Obj_t * pObj, int iFrame, int fTwoPos )
90 {
91  Aig_Obj_t * pObjNew, * pObjNew2, * pObjRepr, * pObjReprNew, * pMiter;
92  // skip nodes without representative
93  pObjRepr = Aig_ObjRepr(pAig, pObj);
94  if ( pObjRepr == NULL )
95  return;
96  p->nConstrTotal++;
97  assert( pObjRepr->Id < pObj->Id );
98  // get the new node
99  pObjNew = Ssw_ObjFrame( p, pObj, iFrame );
100  // get the new node of the representative
101  pObjReprNew = Ssw_ObjFrame( p, pObjRepr, iFrame );
102  // if this is the same node, no need to add constraints
103  if ( pObj->fPhase == pObjRepr->fPhase )
104  {
105  assert( pObjNew != Aig_Not(pObjReprNew) );
106  if ( pObjNew == pObjReprNew )
107  return;
108  }
109  else
110  {
111  assert( pObjNew != pObjReprNew );
112  if ( pObjNew == Aig_Not(pObjReprNew) )
113  return;
114  }
115  p->nConstrReduced++;
116  // these are different nodes - perform speculative reduction
117  pObjNew2 = Aig_NotCond( pObjReprNew, pObj->fPhase ^ pObjRepr->fPhase );
118  // set the new node
119  Ssw_ObjSetFrame( p, pObj, iFrame, pObjNew2 );
120  // add the constraint
121  if ( fTwoPos )
122  {
123  Aig_ObjCreateCo( pFrames, pObjNew2 );
124  Aig_ObjCreateCo( pFrames, pObjNew );
125  }
126  else
127  {
128  pMiter = Aig_Exor( pFrames, pObjNew, pObjNew2 );
129  Aig_ObjCreateCo( pFrames, Aig_NotCond(pMiter, Aig_ObjPhaseReal(pMiter)) );
130  }
131 }
132 
133 /**Function*************************************************************
134 
135  Synopsis [Prepares the inductive case with speculative reduction.]
136 
137  Description []
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
145 {
146  Aig_Man_t * pFrames;
147  Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew;
148  int i, f, iLits;
149  assert( p->pFrames == NULL );
150  assert( Aig_ManRegNum(p->pAig) > 0 );
151  assert( Aig_ManRegNum(p->pAig) < Aig_ManCiNum(p->pAig) );
152  p->nConstrTotal = p->nConstrReduced = 0;
153 
154  // start the fraig package
155  pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->nFrames );
156  // create latches for the first frame
157  Saig_ManForEachLo( p->pAig, pObj, i )
158  Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
159  // add timeframes
160  iLits = 0;
161  for ( f = 0; f < p->pPars->nFramesK; f++ )
162  {
163  // map constants and PIs
164  Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(pFrames) );
165  Saig_ManForEachPi( p->pAig, pObj, i )
166  {
167  pObjNew = Aig_ObjCreateCi(pFrames);
168  pObjNew->fPhase = (p->vInits != NULL) && Vec_IntEntry(p->vInits, iLits++);
169  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
170  }
171  // set the constraints on the latch outputs
172  Saig_ManForEachLo( p->pAig, pObj, i )
173  Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, f, 1 );
174  // add internal nodes of this frame
175  Aig_ManForEachNode( p->pAig, pObj, i )
176  {
177  pObjNew = Aig_And( pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
178  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
179  Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, f, 1 );
180  }
181  // transfer to the primary outputs
182  Aig_ManForEachCo( p->pAig, pObj, i )
183  Ssw_ObjSetFrame( p, pObj, f, Ssw_ObjChild0Fra(p, pObj,f) );
184  // transfer latch input to the latch outputs
185  Saig_ManForEachLiLo( p->pAig, pObjLi, pObjLo, i )
186  Ssw_ObjSetFrame( p, pObjLo, f+1, Ssw_ObjFrame(p, pObjLi,f) );
187  }
188  assert( p->vInits == NULL || Vec_IntSize(p->vInits) == iLits + Saig_ManPiNum(p->pAig) );
189  // add the POs for the latch outputs of the last frame
190  Saig_ManForEachLo( p->pAig, pObj, i )
191  Aig_ObjCreateCo( pFrames, Ssw_ObjFrame( p, pObj, p->pPars->nFramesK ) );
192 
193  // remove dangling nodes
194  Aig_ManCleanup( pFrames );
195  // make sure the satisfying assignment is node assigned
196  assert( pFrames->pData == NULL );
197 //Aig_ManShow( pFrames, 0, NULL );
198  return pFrames;
199 }
200 
201 /**Function*************************************************************
202 
203  Synopsis [Prepares the inductive case with speculative reduction.]
204 
205  Description []
206 
207  SideEffects []
208 
209  SeeAlso []
210 
211 ***********************************************************************/
213 {
214  Aig_Man_t * pFrames;
215  Aig_Obj_t * pObj, * pObjNew;
216  int i;
217  assert( p->pFrames == NULL );
218  assert( Aig_ManRegNum(p->pAig) > 0 );
219  assert( Aig_ManRegNum(p->pAig) < Aig_ManCiNum(p->pAig) );
220  p->nConstrTotal = p->nConstrReduced = 0;
221 
222  // start the fraig package
223  pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->nFrames );
224  pFrames->pName = Abc_UtilStrsav( p->pAig->pName );
225  // map constants and PIs
226  Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), 0, Aig_ManConst1(pFrames) );
227  Saig_ManForEachPi( p->pAig, pObj, i )
228  Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
229  // create latches for the first frame
230  Saig_ManForEachLo( p->pAig, pObj, i )
231  Ssw_ObjSetFrame( p, pObj, 0, Aig_ObjCreateCi(pFrames) );
232  // set the constraints on the latch outputs
233  Saig_ManForEachLo( p->pAig, pObj, i )
234  Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, 0, 0 );
235  // add internal nodes of this frame
236  Aig_ManForEachNode( p->pAig, pObj, i )
237  {
238  pObjNew = Aig_And( pFrames, Ssw_ObjChild0Fra(p, pObj, 0), Ssw_ObjChild1Fra(p, pObj, 0) );
239  Ssw_ObjSetFrame( p, pObj, 0, pObjNew );
240  Ssw_FramesConstrainNode( p, pFrames, p->pAig, pObj, 0, 0 );
241  }
242  // add the POs for the latch outputs of the last frame
243  Saig_ManForEachLi( p->pAig, pObj, i )
244  Aig_ObjCreateCo( pFrames, Ssw_ObjChild0Fra(p, pObj,0) );
245  // remove dangling nodes
246  Aig_ManCleanup( pFrames );
247  Aig_ManSetRegNum( pFrames, Aig_ManRegNum(p->pAig) );
248 // Abc_Print( 1, "SpecRed: Total constraints = %d. Reduced constraints = %d.\n",
249 // p->nConstrTotal, p->nConstrReduced );
250  return pFrames;
251 }
252 
253 ////////////////////////////////////////////////////////////////////////
254 /// END OF FILE ///
255 ////////////////////////////////////////////////////////////////////////
256 
257 
char * memset()
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition: aigObj.c:66
static Aig_Obj_t * Aig_ObjRepr(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:330
int nFrames
Definition: sswInt.h:160
static Aig_Obj_t * Ssw_ObjChild0Fra(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:185
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition: saig.h:101
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
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigObj.c:45
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
typedefABC_NAMESPACE_HEADER_START struct Ssw_Man_t_ Ssw_Man_t
INCLUDES ///.
Definition: sswInt.h:47
static Aig_Obj_t * Aig_Not(Aig_Obj_t *p)
Definition: aig.h:247
static Aig_Obj_t * Ssw_ObjChild1Fra(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:186
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Aig_Man_t * pAig
Definition: sswInt.h:158
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
Definition: aigMan.c:438
#define Saig_ManForEachLi(p, pObj, i)
Definition: saig.h:98
static void Ssw_FramesConstrainNode(Ssw_Man_t *p, Aig_Man_t *pFrames, Aig_Man_t *pAig, Aig_Obj_t *pObj, int iFrame, int fTwoPos)
Definition: sswAig.c:89
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Aig_Man_t * pFrames
Definition: sswInt.h:161
static int Aig_ObjPhaseReal(Aig_Obj_t *pObj)
Definition: aig.h:299
Definition: aig.h:69
#define Saig_ManForEachLo(p, pObj, i)
Definition: saig.h:96
Vec_Ptr_t * vAig2Frm
Definition: sswInt.h:162
Aig_Man_t * pAig
Definition: sswSim.c:33
ABC_NAMESPACE_IMPL_START Ssw_Frm_t * Ssw_FrmStart(Aig_Man_t *pAig)
DECLARATIONS ///.
Definition: sswAig.c:45
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
unsigned int fPhase
Definition: aig.h:78
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static void Ssw_ObjSetFrame(Ssw_Man_t *p, Aig_Obj_t *pObj, int i, Aig_Obj_t *pNode)
Definition: sswInt.h:183
static int Saig_ManPiNum(Aig_Man_t *p)
MACRO DEFINITIONS ///.
Definition: saig.h:73
#define ABC_FREE(obj)
Definition: abc_global.h:232
int nObjs
Definition: sswInt.h:159
Aig_Man_t * Ssw_FramesWithClasses(Ssw_Man_t *p)
Definition: sswAig.c:144
#define assert(ex)
Definition: util_old.h:213
void Ssw_FrmStop(Ssw_Frm_t *p)
Definition: sswAig.c:70
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
Aig_Man_t * Ssw_SpeculativeReduction(Ssw_Man_t *p)
Definition: sswAig.c:212
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int Id
Definition: aig.h:85
int Aig_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
#define Saig_ManForEachPi(p, pObj, i)
Definition: saig.h:91
static Aig_Obj_t * Ssw_ObjFrame(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:182