ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
simUtils.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "sim.h"
23
25
26
30
31static int bit_count[256] = {
32 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
33 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
34 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
35 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
36 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
37 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
38 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
39 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
40};
41
45
57Vec_Ptr_t * Sim_UtilInfoAlloc( int nSize, int nWords, int fClean )
58{
59 Vec_Ptr_t * vInfo;
60 int i;
61 assert( nSize > 0 && nWords > 0 );
62 vInfo = Vec_PtrAlloc( nSize );
63 vInfo->pArray[0] = ABC_ALLOC( unsigned, (long)nSize * (long)nWords );
64 assert( vInfo->pArray[0]);
65 if ( fClean )
66 memset( vInfo->pArray[0], 0, sizeof(unsigned) * nSize * nWords );
67 for ( i = 1; i < nSize; i++ )
68 vInfo->pArray[i] = ((unsigned *)vInfo->pArray[i-1]) + nWords;
69 vInfo->nSize = nSize;
70 return vInfo;
71}
72
85{
86 ABC_FREE( p->pArray[0] );
87 Vec_PtrFree( p );
88}
89
101void Sim_UtilInfoAdd( unsigned * pInfo1, unsigned * pInfo2, int nWords )
102{
103 int w;
104 for ( w = 0; w < nWords; w++ )
105 pInfo1[w] |= pInfo2[w];
106}
107
119void Sim_UtilInfoDetectDiffs( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
120{
121 int w, b;
122 unsigned uMask;
123 vDiffs->nSize = 0;
124 for ( w = 0; w < nWords; w++ )
125 if ( (uMask = (pInfo2[w] ^ pInfo1[w])) )
126 for ( b = 0; b < 32; b++ )
127 if ( uMask & (1 << b) )
128 Vec_IntPush( vDiffs, 32*w + b );
129}
130
142void Sim_UtilInfoDetectNews( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
143{
144 int w, b;
145 unsigned uMask;
146 vDiffs->nSize = 0;
147 for ( w = 0; w < nWords; w++ )
148 if ( (uMask = (pInfo2[w] & ~pInfo1[w])) )
149 for ( b = 0; b < 32; b++ )
150 if ( uMask & (1 << b) )
151 Vec_IntPush( vDiffs, 32*w + b );
152}
153
166{
167 unsigned * pSimInfo1, * pSimInfo2;
168 int k;
169 pSimInfo1 = (unsigned *)p->vSim0->pArray[pNode->Id];
170 pSimInfo2 = (unsigned *)p->vSim1->pArray[pNode->Id];
171 for ( k = 0; k < p->nSimWords; k++ )
172 pSimInfo2[k] = ~pSimInfo1[k];
173}
174
187{
188 unsigned * pSimInfo1, * pSimInfo2;
189 int k;
190 pSimInfo1 = (unsigned *)p->vSim0->pArray[pNode->Id];
191 pSimInfo2 = (unsigned *)p->vSim1->pArray[pNode->Id];
192 for ( k = 0; k < p->nSimWords; k++ )
193 if ( pSimInfo2[k] != pSimInfo1[k] )
194 return 0;
195 return 1;
196}
197
209void Sim_UtilSimulate( Sim_Man_t * p, int fType )
210{
211 Abc_Obj_t * pNode;
212 int i;
213 // simulate the internal nodes
214 Abc_NtkForEachNode( p->pNtk, pNode, i )
215 Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
216 // assign simulation info of the CO nodes
217 Abc_NtkForEachCo( p->pNtk, pNode, i )
218 Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
219}
220
232void Sim_UtilSimulateNode( Sim_Man_t * p, Abc_Obj_t * pNode, int fType, int fType1, int fType2 )
233{
234 unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
235 int k, fComp1, fComp2;
236 // simulate the internal nodes
237 if ( Abc_ObjIsNode(pNode) )
238 {
239 if ( fType )
240 pSimmNode = (unsigned *)p->vSim1->pArray[ pNode->Id ];
241 else
242 pSimmNode = (unsigned *)p->vSim0->pArray[ pNode->Id ];
243
244 if ( fType1 )
245 pSimmNode1 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
246 else
247 pSimmNode1 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
248
249 if ( fType2 )
250 pSimmNode2 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId1(pNode) ];
251 else
252 pSimmNode2 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId1(pNode) ];
253
254 fComp1 = Abc_ObjFaninC0(pNode);
255 fComp2 = Abc_ObjFaninC1(pNode);
256 if ( fComp1 && fComp2 )
257 for ( k = 0; k < p->nSimWords; k++ )
258 pSimmNode[k] = ~pSimmNode1[k] & ~pSimmNode2[k];
259 else if ( fComp1 && !fComp2 )
260 for ( k = 0; k < p->nSimWords; k++ )
261 pSimmNode[k] = ~pSimmNode1[k] & pSimmNode2[k];
262 else if ( !fComp1 && fComp2 )
263 for ( k = 0; k < p->nSimWords; k++ )
264 pSimmNode[k] = pSimmNode1[k] & ~pSimmNode2[k];
265 else // if ( fComp1 && fComp2 )
266 for ( k = 0; k < p->nSimWords; k++ )
267 pSimmNode[k] = pSimmNode1[k] & pSimmNode2[k];
268 }
269 else
270 {
271 assert( Abc_ObjFaninNum(pNode) == 1 );
272 if ( fType )
273 pSimmNode = (unsigned *)p->vSim1->pArray[ pNode->Id ];
274 else
275 pSimmNode = (unsigned *)p->vSim0->pArray[ pNode->Id ];
276
277 if ( fType1 )
278 pSimmNode1 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
279 else
280 pSimmNode1 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
281
282 fComp1 = Abc_ObjFaninC0(pNode);
283 if ( fComp1 )
284 for ( k = 0; k < p->nSimWords; k++ )
285 pSimmNode[k] = ~pSimmNode1[k];
286 else
287 for ( k = 0; k < p->nSimWords; k++ )
288 pSimmNode[k] = pSimmNode1[k];
289 }
290}
291
303void Sim_UtilSimulateNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset )
304{
305 unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
306 int k, fComp1, fComp2;
307 // simulate the internal nodes
308 assert( Abc_ObjIsNode(pNode) );
309 pSimmNode = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
310 pSimmNode1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
311 pSimmNode2 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId1(pNode));
312 pSimmNode += nOffset;
313 pSimmNode1 += nOffset;
314 pSimmNode2 += nOffset;
315 fComp1 = Abc_ObjFaninC0(pNode);
316 fComp2 = Abc_ObjFaninC1(pNode);
317 if ( fComp1 && fComp2 )
318 for ( k = 0; k < nSimWords; k++ )
319 pSimmNode[k] = ~pSimmNode1[k] & ~pSimmNode2[k];
320 else if ( fComp1 && !fComp2 )
321 for ( k = 0; k < nSimWords; k++ )
322 pSimmNode[k] = ~pSimmNode1[k] & pSimmNode2[k];
323 else if ( !fComp1 && fComp2 )
324 for ( k = 0; k < nSimWords; k++ )
325 pSimmNode[k] = pSimmNode1[k] & ~pSimmNode2[k];
326 else // if ( fComp1 && fComp2 )
327 for ( k = 0; k < nSimWords; k++ )
328 pSimmNode[k] = pSimmNode1[k] & pSimmNode2[k];
329}
330
342void Sim_UtilTransferNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset, int fShift )
343{
344 unsigned * pSimmNode, * pSimmNode1;
345 int k, fComp1;
346 // simulate the internal nodes
347 assert( Abc_ObjIsCo(pNode) );
348 pSimmNode = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
349 pSimmNode1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
350 pSimmNode += nOffset + (fShift > 0)*nSimWords;
351 pSimmNode1 += nOffset;
352 fComp1 = Abc_ObjFaninC0(pNode);
353 if ( fComp1 )
354 for ( k = 0; k < nSimWords; k++ )
355 pSimmNode[k] = ~pSimmNode1[k];
356 else
357 for ( k = 0; k < nSimWords; k++ )
358 pSimmNode[k] = pSimmNode1[k];
359}
360
372int Sim_UtilCountSuppSizes( Sim_Man_t * p, int fStruct )
373{
374 Abc_Obj_t * pNode, * pNodeCi;
375 int i, v, Counter;
376 Counter = 0;
377 if ( fStruct )
378 {
379 Abc_NtkForEachCo( p->pNtk, pNode, i )
380 Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
381 Counter += Sim_SuppStrHasVar( p->vSuppStr, pNode, v );
382 }
383 else
384 {
385 Abc_NtkForEachCo( p->pNtk, pNode, i )
386 Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
387 Counter += Sim_SuppFunHasVar( p->vSuppFun, i, v );
388 }
389 return Counter;
390}
391
403int Sim_UtilCountOnes( unsigned * pSimInfo, int nSimWords )
404{
405 unsigned char * pBytes;
406 int nOnes, nBytes, i;
407 pBytes = (unsigned char *)pSimInfo;
408 nBytes = 4 * nSimWords;
409 nOnes = 0;
410 for ( i = 0; i < nBytes; i++ )
411 nOnes += bit_count[ pBytes[i] ];
412 return nOnes;
413}
414
426Vec_Int_t * Sim_UtilCountOnesArray( Vec_Ptr_t * vInfo, int nSimWords )
427{
428 Vec_Int_t * vCounters;
429 unsigned * pSimInfo;
430 int i;
431 vCounters = Vec_IntStart( Vec_PtrSize(vInfo) );
432 Vec_PtrForEachEntry( unsigned *, vInfo, pSimInfo, i )
433 Vec_IntWriteEntry( vCounters, i, Sim_UtilCountOnes(pSimInfo, nSimWords) );
434 return vCounters;
435}
436
448void Sim_UtilSetRandom( unsigned * pPatRand, int nSimWords )
449{
450 int k;
451 for ( k = 0; k < nSimWords; k++ )
452 pPatRand[k] = SIM_RANDOM_UNSIGNED;
453}
454
466void Sim_UtilSetCompl( unsigned * pPatRand, int nSimWords )
467{
468 int k;
469 for ( k = 0; k < nSimWords; k++ )
470 pPatRand[k] = ~pPatRand[k];
471}
472
484void Sim_UtilSetConst( unsigned * pPatRand, int nSimWords, int fConst1 )
485{
486 int k;
487 for ( k = 0; k < nSimWords; k++ )
488 pPatRand[k] = 0;
489 if ( fConst1 )
490 Sim_UtilSetCompl( pPatRand, nSimWords );
491}
492
504int Sim_UtilInfoIsEqual( unsigned * pPats1, unsigned * pPats2, int nSimWords )
505{
506 int k;
507 for ( k = 0; k < nSimWords; k++ )
508 if ( pPats1[k] != pPats2[k] )
509 return 0;
510 return 1;
511}
512
524int Sim_UtilInfoIsImp( unsigned * pPats1, unsigned * pPats2, int nSimWords )
525{
526 int k;
527 for ( k = 0; k < nSimWords; k++ )
528 if ( pPats1[k] & ~pPats2[k] )
529 return 0;
530 return 1;
531}
532
544int Sim_UtilInfoIsClause( unsigned * pPats1, unsigned * pPats2, int nSimWords )
545{
546 int k;
547 for ( k = 0; k < nSimWords; k++ )
548 if ( ~pPats1[k] & ~pPats2[k] )
549 return 0;
550 return 1;
551}
552
564int Sim_UtilCountAllPairs( Vec_Ptr_t * vSuppFun, int nSimWords, Vec_Int_t * vCounters )
565{
566 unsigned * pSupp;
567 int Counter, nOnes, nPairs, i;
568 Counter = 0;
569 Vec_PtrForEachEntry( unsigned *, vSuppFun, pSupp, i )
570 {
571 nOnes = Sim_UtilCountOnes( pSupp, nSimWords );
572 nPairs = nOnes * (nOnes - 1) / 2;
573 Vec_IntWriteEntry( vCounters, i, nPairs );
574 Counter += nPairs;
575 }
576 return Counter;
577}
578
591{
592 int i, k, Index1, Index2;
593 int Counter = 0;
594// int Counter2;
595 Vec_IntForEachEntry( vSupport, i, Index1 )
596 Vec_IntForEachEntryStart( vSupport, k, Index2, Index1+1 )
597 Counter += Extra_BitMatrixLookup1( pMat, i, k );
598// Counter2 = Extra_BitMatrixCountOnesUpper(pMat);
599// assert( Counter == Counter2 );
600 return Counter;
601}
602
615{
616 int i, k, Index1, Index2;
617 Vec_IntForEachEntry( vSupport, i, Index1 )
618 Vec_IntForEachEntryStart( vSupport, k, Index2, Index1+1 )
619 if ( Extra_BitMatrixLookup1( pMat, i, k ) )
620 printf( "(%d,%d) ", i, k );
621 return 0;
622}
623
636{
637 int i;
638 abctime clk;
639clk = Abc_Clock();
640 for ( i = 0; i < p->nOutputs; i++ )
641 {
642 printf( "Output %2d :", i );
643 Sim_UtilCountPairsOnePrint( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms, i), Vec_VecEntryInt(p->vSupports, i) );
644 printf( "\n" );
645 }
646p->timeCount += Abc_Clock() - clk;
647}
648
661{
662 int nPairsTotal, nPairsSym, nPairsNonSym, i;
663 abctime clk;
664clk = Abc_Clock();
665 p->nPairsSymm = 0;
666 p->nPairsNonSymm = 0;
667 for ( i = 0; i < p->nOutputs; i++ )
668 {
669 nPairsTotal = Vec_IntEntry(p->vPairsTotal, i);
670 nPairsSym = Vec_IntEntry(p->vPairsSym, i);
671 nPairsNonSym = Vec_IntEntry(p->vPairsNonSym,i);
672 assert( nPairsTotal >= nPairsSym + nPairsNonSym );
673 if ( nPairsTotal == nPairsSym + nPairsNonSym )
674 {
675 p->nPairsSymm += nPairsSym;
676 p->nPairsNonSymm += nPairsNonSym;
677 continue;
678 }
679 nPairsSym = Sim_UtilCountPairsOne( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms, i), Vec_VecEntryInt(p->vSupports, i) );
680 nPairsNonSym = Sim_UtilCountPairsOne( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrNonSymms,i), Vec_VecEntryInt(p->vSupports, i) );
681 assert( nPairsTotal >= nPairsSym + nPairsNonSym );
682 Vec_IntWriteEntry( p->vPairsSym, i, nPairsSym );
683 Vec_IntWriteEntry( p->vPairsNonSym, i, nPairsNonSym );
684 p->nPairsSymm += nPairsSym;
685 p->nPairsNonSymm += nPairsNonSym;
686// printf( "%d ", nPairsTotal - nPairsSym - nPairsNonSym );
687 }
688//printf( "\n" );
689 p->nPairsRem = p->nPairsTotal-p->nPairsSymm-p->nPairsNonSymm;
690p->timeCount += Abc_Clock() - clk;
691}
692
705{
706 int i;
707 for ( i = 0; i < p->nOutputs; i++ )
708 if ( !Extra_BitMatrixIsDisjoint( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms,i), (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrNonSymms,i) ) )
709 return 0;
710 return 1;
711}
712
716
717
719
int nWords
Definition abcNpn.c:127
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_INT64_T abctime
Definition abc_global.h:332
#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
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
struct Extra_BitMat_t_ Extra_BitMat_t
Definition extra.h:81
int Extra_BitMatrixIsDisjoint(Extra_BitMat_t *p1, Extra_BitMat_t *p2)
int Extra_BitMatrixLookup1(Extra_BitMat_t *p, int i, int k)
void Sim_UtilInfoFree(Vec_Ptr_t *p)
Definition simUtils.c:84
void Sim_UtilSetRandom(unsigned *pPatRand, int nSimWords)
Definition simUtils.c:448
int Sim_UtilInfoCompare(Sim_Man_t *p, Abc_Obj_t *pNode)
Definition simUtils.c:186
int Sim_UtilCountPairsOnePrint(Extra_BitMat_t *pMat, Vec_Int_t *vSupport)
Definition simUtils.c:614
int Sim_UtilInfoIsImp(unsigned *pPats1, unsigned *pPats2, int nSimWords)
Definition simUtils.c:524
Vec_Ptr_t * Sim_UtilInfoAlloc(int nSize, int nWords, int fClean)
FUNCTION DEFINITIONS ///.
Definition simUtils.c:57
void Sim_UtilSimulate(Sim_Man_t *p, int fType)
Definition simUtils.c:209
int Sim_UtilInfoIsClause(unsigned *pPats1, unsigned *pPats2, int nSimWords)
Definition simUtils.c:544
void Sim_UtilSimulateNodeOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords, int nOffset)
Definition simUtils.c:303
void Sim_UtilSetCompl(unsigned *pPatRand, int nSimWords)
Definition simUtils.c:466
void Sim_UtilInfoDetectNews(unsigned *pInfo1, unsigned *pInfo2, int nWords, Vec_Int_t *vDiffs)
Definition simUtils.c:142
int Sim_UtilCountOnes(unsigned *pSimInfo, int nSimWords)
Definition simUtils.c:403
int Sim_UtilMatrsAreDisjoint(Sym_Man_t *p)
Definition simUtils.c:704
void Sim_UtilInfoFlip(Sim_Man_t *p, Abc_Obj_t *pNode)
Definition simUtils.c:165
void Sim_UtilTransferNodeOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords, int nOffset, int fShift)
Definition simUtils.c:342
int Sim_UtilCountSuppSizes(Sim_Man_t *p, int fStruct)
Definition simUtils.c:372
void Sim_UtilSetConst(unsigned *pPatRand, int nSimWords, int fConst1)
Definition simUtils.c:484
Vec_Int_t * Sim_UtilCountOnesArray(Vec_Ptr_t *vInfo, int nSimWords)
Definition simUtils.c:426
void Sim_UtilInfoAdd(unsigned *pInfo1, unsigned *pInfo2, int nWords)
Definition simUtils.c:101
void Sim_UtilSimulateNode(Sim_Man_t *p, Abc_Obj_t *pNode, int fType, int fType1, int fType2)
Definition simUtils.c:232
void Sim_UtilCountPairsAllPrint(Sym_Man_t *p)
Definition simUtils.c:635
void Sim_UtilInfoDetectDiffs(unsigned *pInfo1, unsigned *pInfo2, int nWords, Vec_Int_t *vDiffs)
Definition simUtils.c:119
int Sim_UtilCountPairsOne(Extra_BitMat_t *pMat, Vec_Int_t *vSupport)
Definition simUtils.c:590
int Sim_UtilCountAllPairs(Vec_Ptr_t *vSuppFun, int nSimWords, Vec_Int_t *vCounters)
Definition simUtils.c:564
int Sim_UtilInfoIsEqual(unsigned *pPats1, unsigned *pPats2, int nSimWords)
Definition simUtils.c:504
void Sim_UtilCountPairsAll(Sym_Man_t *p)
Definition simUtils.c:660
struct Sim_Man_t_ Sim_Man_t
Definition sim.h:100
#define Sim_SuppFunHasVar(vSupps, Output, v)
Definition sim.h:169
#define SIM_RANDOM_UNSIGNED
Definition sim.h:158
#define Sim_SuppStrHasVar(vSupps, pNode, v)
Definition sim.h:167
typedefABC_NAMESPACE_HEADER_START struct Sym_Man_t_ Sym_Man_t
INCLUDES ///.
Definition sim.h:48
int Id
Definition abc.h:132
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
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