abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ivyOper.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ivyOper.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [And-Inverter Graph package.]
8 
9  Synopsis [AIG operations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: ivyOper.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ivy.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // procedure to detect an EXOR gate
31 static inline int Ivy_ObjIsExorType( Ivy_Obj_t * p0, Ivy_Obj_t * p1, Ivy_Obj_t ** ppFan0, Ivy_Obj_t ** ppFan1 )
32 {
33  if ( !Ivy_IsComplement(p0) || !Ivy_IsComplement(p1) )
34  return 0;
35  p0 = Ivy_Regular(p0);
36  p1 = Ivy_Regular(p1);
37  if ( !Ivy_ObjIsAnd(p0) || !Ivy_ObjIsAnd(p1) )
38  return 0;
39  if ( Ivy_ObjFanin0(p0) != Ivy_ObjFanin0(p1) || Ivy_ObjFanin1(p0) != Ivy_ObjFanin1(p1) )
40  return 0;
41  if ( Ivy_ObjFaninC0(p0) == Ivy_ObjFaninC0(p1) || Ivy_ObjFaninC1(p0) == Ivy_ObjFaninC1(p1) )
42  return 0;
43  *ppFan0 = Ivy_ObjChild0(p0);
44  *ppFan1 = Ivy_ObjChild1(p0);
45  return 1;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////
49 /// FUNCTION DEFINITIONS ///
50 ////////////////////////////////////////////////////////////////////////
51 
52 /**Function*************************************************************
53 
54  Synopsis [Perform one operation.]
55 
56  Description [The argument nodes can be complemented.]
57 
58  SideEffects []
59 
60  SeeAlso []
61 
62 ***********************************************************************/
64 {
65  if ( Type == IVY_AND )
66  return Ivy_And( p, p0, p1 );
67  if ( Type == IVY_EXOR )
68  return Ivy_Exor( p, p0, p1 );
69  assert( 0 );
70  return NULL;
71 }
72 
73 /**Function*************************************************************
74 
75  Synopsis [Performs canonicization step.]
76 
77  Description [The argument nodes can be complemented.]
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
85 {
86 // Ivy_Obj_t * pFan0, * pFan1;
87  // check trivial cases
88  if ( p0 == p1 )
89  return p0;
90  if ( p0 == Ivy_Not(p1) )
91  return Ivy_Not(p->pConst1);
92  if ( Ivy_Regular(p0) == p->pConst1 )
93  return p0 == p->pConst1 ? p1 : Ivy_Not(p->pConst1);
94  if ( Ivy_Regular(p1) == p->pConst1 )
95  return p1 == p->pConst1 ? p0 : Ivy_Not(p->pConst1);
96  // check if it can be an EXOR gate
97 // if ( Ivy_ObjIsExorType( p0, p1, &pFan0, &pFan1 ) )
98 // return Ivy_CanonExor( pFan0, pFan1 );
99  return Ivy_CanonAnd( p, p0, p1 );
100 }
101 
102 /**Function*************************************************************
103 
104  Synopsis [Performs canonicization step.]
105 
106  Description [The argument nodes can be complemented.]
107 
108  SideEffects []
109 
110  SeeAlso []
111 
112 ***********************************************************************/
114 {
115 /*
116  // check trivial cases
117  if ( p0 == p1 )
118  return Ivy_Not(p->pConst1);
119  if ( p0 == Ivy_Not(p1) )
120  return p->pConst1;
121  if ( Ivy_Regular(p0) == p->pConst1 )
122  return Ivy_NotCond( p1, p0 == p->pConst1 );
123  if ( Ivy_Regular(p1) == p->pConst1 )
124  return Ivy_NotCond( p0, p1 == p->pConst1 );
125  // check the table
126  return Ivy_CanonExor( p, p0, p1 );
127 */
128  return Ivy_Or( p, Ivy_And(p, p0, Ivy_Not(p1)), Ivy_And(p, Ivy_Not(p0), p1) );
129 }
130 
131 /**Function*************************************************************
132 
133  Synopsis [Implements Boolean OR.]
134 
135  Description []
136 
137  SideEffects []
138 
139  SeeAlso []
140 
141 ***********************************************************************/
143 {
144  return Ivy_Not( Ivy_And( p, Ivy_Not(p0), Ivy_Not(p1) ) );
145 }
146 
147 /**Function*************************************************************
148 
149  Synopsis [Implements ITE operation.]
150 
151  Description []
152 
153  SideEffects []
154 
155  SeeAlso []
156 
157 ***********************************************************************/
159 {
160  Ivy_Obj_t * pTempA1, * pTempA2, * pTempB1, * pTempB2, * pTemp;
161  int Count0, Count1;
162  // consider trivial cases
163  if ( p0 == Ivy_Not(p1) )
164  return Ivy_Exor( p, pC, p0 );
165  // other cases can be added
166  // implement the first MUX (F = C * x1 + C' * x0)
167  pTempA1 = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, pC, p1, IVY_AND, IVY_INIT_NONE) );
168  pTempA2 = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, Ivy_Not(pC), p0, IVY_AND, IVY_INIT_NONE) );
169  if ( pTempA1 && pTempA2 )
170  {
171  pTemp = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, Ivy_Not(pTempA1), Ivy_Not(pTempA2), IVY_AND, IVY_INIT_NONE) );
172  if ( pTemp ) return Ivy_Not(pTemp);
173  }
174  Count0 = (pTempA1 != NULL) + (pTempA2 != NULL);
175  // implement the second MUX (F' = C * x1' + C' * x0')
176  pTempB1 = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, pC, Ivy_Not(p1), IVY_AND, IVY_INIT_NONE) );
178  if ( pTempB1 && pTempB2 )
179  {
180  pTemp = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, Ivy_Not(pTempB1), Ivy_Not(pTempB2), IVY_AND, IVY_INIT_NONE) );
181  if ( pTemp ) return pTemp;
182  }
183  Count1 = (pTempB1 != NULL) + (pTempB2 != NULL);
184  // compare and decide which one to implement
185  if ( Count0 >= Count1 )
186  {
187  pTempA1 = pTempA1? pTempA1 : Ivy_And(p, pC, p1);
188  pTempA2 = pTempA2? pTempA2 : Ivy_And(p, Ivy_Not(pC), p0);
189  return Ivy_Or( p, pTempA1, pTempA2 );
190  }
191  pTempB1 = pTempB1? pTempB1 : Ivy_And(p, pC, Ivy_Not(p1));
192  pTempB2 = pTempB2? pTempB2 : Ivy_And(p, Ivy_Not(pC), Ivy_Not(p0));
193  return Ivy_Not( Ivy_Or( p, pTempB1, pTempB2 ) );
194 
195 // return Ivy_Or( Ivy_And(pC, p1), Ivy_And(Ivy_Not(pC), p0) );
196 }
197 
198 /**Function*************************************************************
199 
200  Synopsis [Implements ITE operation.]
201 
202  Description []
203 
204  SideEffects []
205 
206  SeeAlso []
207 
208 ***********************************************************************/
210 {
211  return Ivy_Or( p, Ivy_Or(p, Ivy_And(p, pA, pB), Ivy_And(p, pA, pC)), Ivy_And(p, pB, pC) );
212 }
213 
214 /**Function*************************************************************
215 
216  Synopsis [Constructs the well-balanced tree of gates.]
217 
218  Description [Disregards levels and possible logic sharing.]
219 
220  SideEffects []
221 
222  SeeAlso []
223 
224 ***********************************************************************/
225 Ivy_Obj_t * Ivy_Multi_rec( Ivy_Man_t * p, Ivy_Obj_t ** ppObjs, int nObjs, Ivy_Type_t Type )
226 {
227  Ivy_Obj_t * pObj1, * pObj2;
228  if ( nObjs == 1 )
229  return ppObjs[0];
230  pObj1 = Ivy_Multi_rec( p, ppObjs, nObjs/2, Type );
231  pObj2 = Ivy_Multi_rec( p, ppObjs + nObjs/2, nObjs - nObjs/2, Type );
232  return Ivy_Oper( p, pObj1, pObj2, Type );
233 }
234 
235 /**Function*************************************************************
236 
237  Synopsis [Old code.]
238 
239  Description []
240 
241  SideEffects []
242 
243  SeeAlso []
244 
245 ***********************************************************************/
246 Ivy_Obj_t * Ivy_Multi( Ivy_Man_t * p, Ivy_Obj_t ** pArgs, int nArgs, Ivy_Type_t Type )
247 {
248  assert( Type == IVY_AND || Type == IVY_EXOR );
249  assert( nArgs > 0 );
250  return Ivy_Multi_rec( p, pArgs, nArgs, Type );
251 }
252 
253 /**Function*************************************************************
254 
255  Synopsis [Implements the miter.]
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
265 {
266  int i;
267  assert( vPairs->nSize > 0 );
268  assert( vPairs->nSize % 2 == 0 );
269  // go through the cubes of the node's SOP
270  for ( i = 0; i < vPairs->nSize; i += 2 )
271  vPairs->pArray[i/2] = Ivy_Not( Ivy_Exor( p, (Ivy_Obj_t *)vPairs->pArray[i], (Ivy_Obj_t *)vPairs->pArray[i+1] ) );
272  vPairs->nSize = vPairs->nSize/2;
273  return Ivy_Not( Ivy_Multi_rec( p, (Ivy_Obj_t **)vPairs->pArray, vPairs->nSize, IVY_AND ) );
274 }
275 
276 /**Function*************************************************************
277 
278  Synopsis [Performs canonicization step.]
279 
280  Description []
281 
282  SideEffects []
283 
284  SeeAlso []
285 
286 ***********************************************************************/
288 {
289  return Ivy_CanonLatch( p, pObj, Init );
290 }
291 
292 ////////////////////////////////////////////////////////////////////////
293 /// END OF FILE ///
294 ////////////////////////////////////////////////////////////////////////
295 
296 
298 
static ABC_NAMESPACE_IMPL_START int Ivy_ObjIsExorType(Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Obj_t **ppFan0, Ivy_Obj_t **ppFan1)
DECLARATIONS ///.
Definition: ivyOper.c:31
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Definition: ivy.h:58
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Ivy_Obj_t * Ivy_Maj(Ivy_Man_t *p, Ivy_Obj_t *pA, Ivy_Obj_t *pB, Ivy_Obj_t *pC)
Definition: ivyOper.c:209
Ivy_Obj_t * Ivy_Miter(Ivy_Man_t *p, Vec_Ptr_t *vPairs)
Definition: ivyOper.c:264
Ivy_Obj_t * Ivy_Mux(Ivy_Man_t *p, Ivy_Obj_t *pC, Ivy_Obj_t *p1, Ivy_Obj_t *p0)
Definition: ivyOper.c:158
static Ivy_Obj_t * Ivy_ObjFanin1(Ivy_Obj_t *pObj)
Definition: ivy.h:272
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
Ivy_Obj_t * Ivy_TableLookup(Ivy_Man_t *p, Ivy_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: ivyTable.c:71
static int Ivy_ObjFaninC1(Ivy_Obj_t *pObj)
Definition: ivy.h:270
Ivy_Obj_t * Ivy_Or(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:142
Ivy_Init_t
Definition: ivy.h:65
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
Ivy_Obj_t * Ivy_CanonAnd(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyCanon.c:90
static Ivy_Obj_t * Ivy_ObjChild0(Ivy_Obj_t *pObj)
Definition: ivy.h:273
Ivy_Obj_t * Ivy_CanonLatch(Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Init_t Init)
Definition: ivyCanon.c:131
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
Ivy_Obj_t * Ivy_Exor(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:113
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Ivy_Obj_t * Ivy_ObjCreateGhost(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type, Ivy_Init_t Init)
Definition: ivy.h:308
Definition: ivy.h:59
static int Ivy_ObjIsAnd(Ivy_Obj_t *pObj)
Definition: ivy.h:242
static Ivy_Obj_t * Ivy_Not(Ivy_Obj_t *p)
Definition: ivy.h:194
Ivy_Obj_t * Ivy_Multi(Ivy_Man_t *p, Ivy_Obj_t **pArgs, int nArgs, Ivy_Type_t Type)
Definition: ivyOper.c:246
static Ivy_Obj_t * Ivy_ObjChild1(Ivy_Obj_t *pObj)
Definition: ivy.h:274
#define assert(ex)
Definition: util_old.h:213
Ivy_Obj_t * Ivy_Multi_rec(Ivy_Man_t *p, Ivy_Obj_t **ppObjs, int nObjs, Ivy_Type_t Type)
Definition: ivyOper.c:225
Ivy_Obj_t * Ivy_Latch(Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Init_t Init)
Definition: ivyOper.c:287
Ivy_Obj_t * Ivy_And(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:84
Ivy_Type_t
Definition: ivy.h:52
Ivy_Obj_t * Ivy_Oper(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type)
FUNCTION DEFINITIONS ///.
Definition: ivyOper.c:63
static int Ivy_ObjFaninC0(Ivy_Obj_t *pObj)
Definition: ivy.h:269