ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
amapUniq.c
Go to the documentation of this file.
1
20
21#include "amapInt.h"
22
24
25
29
33
45static inline int Vec_IntCheckWithMask( Vec_Int_t * p, int Entry )
46{
47 int i;
48 for ( i = 0; i < p->nSize; i++ )
49 if ( (0xffff & p->pArray[i]) == (0xffff & Entry) )
50 return p->pArray[i] >> 16;
51 return -1;
52}
53
65static inline void Vec_IntPushOrderWithMask( Vec_Int_t * p, int Entry )
66{
67 int i;
68 if ( p->nSize == p->nCap )
69 Vec_IntGrow( p, 2 * p->nCap );
70 p->nSize++;
71 for ( i = p->nSize-2; i >= 0; i-- )
72 if ( (0xffff & p->pArray[i]) > (0xffff & Entry) )
73 p->pArray[i+1] = p->pArray[i];
74 else
75 break;
76 p->pArray[i+1] = Entry;
77}
78
90int Amap_LibFindNode( Amap_Lib_t * pLib, int iFan0, int iFan1, int fXor )
91{
92 if ( fXor )
93 return Vec_IntCheckWithMask( (Vec_Int_t *)Vec_PtrEntry(pLib->vRulesX, iFan0), iFan1 );
94 else
95 return Vec_IntCheckWithMask( (Vec_Int_t *)Vec_PtrEntry(pLib->vRules, iFan0), iFan1 );
96}
97
109int Amap_LibFindMux( Amap_Lib_t * p, int iFan0, int iFan1, int iFan2 )
110{
111 int x;
112 for ( x = 0; x < Vec_IntSize(p->vRules3); x += 4 )
113 {
114 if ( Vec_IntEntry(p->vRules3, x) == iFan0 &&
115 Vec_IntEntry(p->vRules3, x+1) == iFan1 &&
116 Vec_IntEntry(p->vRules3, x+2) == iFan2 )
117 {
118 return Vec_IntEntry(p->vRules3, x+3);
119 }
120 }
121 return -1;
122}
123
136{
137 Amap_Nod_t * pNode;
138 if ( p->nNodes == p->nNodesAlloc )
139 {
140 p->pNodes = ABC_REALLOC( Amap_Nod_t, p->pNodes, 2*p->nNodesAlloc );
141 p->nNodesAlloc *= 2;
142 }
143 pNode = Amap_LibNod( p, p->nNodes );
144 memset( pNode, 0, sizeof(Amap_Nod_t) );
145 pNode->Id = p->nNodes++;
146 Vec_PtrPush( p->vRules, Vec_IntAlloc(8) );
147 Vec_PtrPush( p->vRules, Vec_IntAlloc(8) );
148 Vec_PtrPush( p->vRulesX, Vec_IntAlloc(8) );
149 Vec_PtrPush( p->vRulesX, Vec_IntAlloc(8) );
150 return pNode;
151}
152
165{
166 Amap_Nod_t * pNode;
167 // start the manager
168 assert( p->pNodes == NULL );
169 p->nNodesAlloc = 256;
170 p->pNodes = ABC_ALLOC( Amap_Nod_t, p->nNodesAlloc );
171 // create the first node
172 pNode = Amap_LibCreateObj( p );
173 p->pNodes->Type = AMAP_OBJ_PI;
174 p->pNodes->nSuppSize = 1;
175 return 0;
176}
177
189int Amap_LibCreateNode( Amap_Lib_t * p, int iFan0, int iFan1, int fXor )
190{
191 Amap_Nod_t * pNode;
192 int iFan;
193 if ( iFan0 < iFan1 )
194 {
195 iFan = iFan0;
196 iFan0 = iFan1;
197 iFan1 = iFan;
198 }
199 pNode = Amap_LibCreateObj( p );
200 pNode->Type = fXor? AMAP_OBJ_XOR : AMAP_OBJ_AND;
201 pNode->nSuppSize = p->pNodes[Abc_Lit2Var(iFan0)].nSuppSize + p->pNodes[Abc_Lit2Var(iFan1)].nSuppSize;
202 pNode->iFan0 = iFan0;
203 pNode->iFan1 = iFan1;
204if ( p->fVerbose )
205printf( "Creating node %5d %c : iFan0 = %5d%c iFan1 = %5d%c\n",
206pNode->Id, (fXor?'x':' '),
207Abc_Lit2Var(iFan0), (Abc_LitIsCompl(iFan0)?'-':'+'),
208Abc_Lit2Var(iFan1), (Abc_LitIsCompl(iFan1)?'-':'+') );
209
210 if ( fXor )
211 {
212 if ( iFan0 == iFan1 )
213 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRulesX, iFan0), (pNode->Id << 16) | iFan1 );
214 else
215 {
216 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRulesX, iFan0), (pNode->Id << 16) | iFan1 );
217 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRulesX, iFan1), (pNode->Id << 16) | iFan0 );
218 }
219 }
220 else
221 {
222 if ( iFan0 == iFan1 )
223 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRules, iFan0), (pNode->Id << 16) | iFan1 );
224 else
225 {
226 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRules, iFan0), (pNode->Id << 16) | iFan1 );
227 Vec_IntPushOrderWithMask( (Vec_Int_t *)Vec_PtrEntry(p->vRules, iFan1), (pNode->Id << 16) | iFan0 );
228 }
229 }
230 return pNode->Id;
231}
232
244int Amap_LibCreateMux( Amap_Lib_t * p, int iFan0, int iFan1, int iFan2 )
245{
246 Amap_Nod_t * pNode;
247 pNode = Amap_LibCreateObj( p );
248 pNode->Type = AMAP_OBJ_MUX;
249 pNode->nSuppSize = p->pNodes[Abc_Lit2Var(iFan0)].nSuppSize + p->pNodes[Abc_Lit2Var(iFan1)].nSuppSize + p->pNodes[Abc_Lit2Var(iFan2)].nSuppSize;
250 pNode->iFan0 = iFan0;
251 pNode->iFan1 = iFan1;
252 pNode->iFan2 = iFan2;
253if ( p->fVerbose )
254printf( "Creating node %5d %c : iFan0 = %5d%c iFan1 = %5d%c iFan2 = %5d%c\n",
255pNode->Id, 'm',
256Abc_Lit2Var(iFan0), (Abc_LitIsCompl(iFan0)?'-':'+'),
257Abc_Lit2Var(iFan1), (Abc_LitIsCompl(iFan1)?'-':'+'),
258Abc_Lit2Var(iFan2), (Abc_LitIsCompl(iFan2)?'-':'+') );
259
260 Vec_IntPush( p->vRules3, iFan0 );
261 Vec_IntPush( p->vRules3, iFan1 );
262 Vec_IntPush( p->vRules3, iFan2 );
263 Vec_IntPush( p->vRules3, pNode->Id );
264 return pNode->Id;
265}
266
278int ** Amap_LibLookupTableAlloc( Vec_Ptr_t * vVec, int fVerbose )
279{
280 Vec_Int_t * vOne;
281 int ** pRes;
282 int i, k, nTotal, nSize, nEntries, Value;
283 // count the total size
284 nEntries = nSize = Vec_PtrSize( vVec );
285 Vec_PtrForEachEntry( Vec_Int_t *, vVec, vOne, i )
286 nEntries += Vec_IntSize(vOne);
287 pRes = (int **)ABC_ALLOC( char, nSize * sizeof(void *) + nEntries * sizeof(int) );
288 pRes[0] = (int *)((char *)pRes + nSize * sizeof(void *));
289 nTotal = 0;
290 Vec_PtrForEachEntry( Vec_Int_t *, vVec, vOne, i )
291 {
292 pRes[i] = pRes[0] + nTotal;
293 nTotal += Vec_IntSize(vOne) + 1;
294 if ( fVerbose )
295 printf( "%d : ", i );
296 Vec_IntForEachEntry( vOne, Value, k )
297 {
298 pRes[i][k] = Value;
299 if ( fVerbose )
300 printf( "%d(%d) ", Value&0xffff, Value>>16 );
301 }
302 if ( fVerbose )
303 printf( "\n" );
304 pRes[i][k] = 0;
305 }
306 assert( nTotal == nEntries );
307 return pRes;
308}
309
313
314
316
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
@ AMAP_OBJ_XOR
Definition amapInt.h:56
@ AMAP_OBJ_AND
Definition amapInt.h:55
@ AMAP_OBJ_PI
Definition amapInt.h:53
@ AMAP_OBJ_MUX
Definition amapInt.h:57
struct Amap_Nod_t_ Amap_Nod_t
Definition amapInt.h:67
int Amap_LibCreateMux(Amap_Lib_t *p, int iFan0, int iFan1, int iFan2)
Definition amapUniq.c:244
int Amap_LibFindNode(Amap_Lib_t *pLib, int iFan0, int iFan1, int fXor)
Definition amapUniq.c:90
Amap_Nod_t * Amap_LibCreateObj(Amap_Lib_t *p)
Definition amapUniq.c:135
int Amap_LibCreateVar(Amap_Lib_t *p)
Definition amapUniq.c:164
int ** Amap_LibLookupTableAlloc(Vec_Ptr_t *vVec, int fVerbose)
Definition amapUniq.c:278
int Amap_LibCreateNode(Amap_Lib_t *p, int iFan0, int iFan1, int fXor)
Definition amapUniq.c:189
int Amap_LibFindMux(Amap_Lib_t *p, int iFan0, int iFan1, int iFan2)
Definition amapUniq.c:109
typedefABC_NAMESPACE_HEADER_START struct Amap_Lib_t_ Amap_Lib_t
INCLUDES ///.
Definition amap.h:42
int nTotal
DECLARATIONS ///.
Definition cutTruth.c:37
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
unsigned Type
Definition amapInt.h:177
short iFan0
Definition amapInt.h:178
unsigned nSuppSize
Definition amapInt.h:176
short iFan2
Definition amapInt.h:180
short iFan1
Definition amapInt.h:179
unsigned Id
Definition amapInt.h:175
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55