1 /**CFile****************************************************************
2 
3   FileName    [simUtils.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Network and node package.]
8 
9   Synopsis    [Various simulation utilities.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: simUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "sim.h"
23 
24 ABC_NAMESPACE_IMPL_START
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 ///                        DECLARATIONS                              ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static 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 
42 ////////////////////////////////////////////////////////////////////////
43 ///                     FUNCTION DEFINITIONS                         ///
44 ////////////////////////////////////////////////////////////////////////
45 
46 /**Function*************************************************************
47 
48   Synopsis    [Allocates simulation information for all nodes.]
49 
50   Description []
51 
52   SideEffects []
53 
54   SeeAlso     []
55 
56 ***********************************************************************/
Sim_UtilInfoAlloc(int nSize,int nWords,int fClean)57 Vec_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, nSize * nWords );
64     if ( fClean )
65         memset( vInfo->pArray[0], 0, sizeof(unsigned) * nSize * nWords );
66     for ( i = 1; i < nSize; i++ )
67         vInfo->pArray[i] = ((unsigned *)vInfo->pArray[i-1]) + nWords;
68     vInfo->nSize = nSize;
69     return vInfo;
70 }
71 
72 /**Function*************************************************************
73 
74   Synopsis    [Allocates simulation information for all nodes.]
75 
76   Description []
77 
78   SideEffects []
79 
80   SeeAlso     []
81 
82 ***********************************************************************/
Sim_UtilInfoFree(Vec_Ptr_t * p)83 void Sim_UtilInfoFree( Vec_Ptr_t * p )
84 {
85     ABC_FREE( p->pArray[0] );
86     Vec_PtrFree( p );
87 }
88 
89 /**Function*************************************************************
90 
91   Synopsis    [Adds the second supp-info the first.]
92 
93   Description []
94 
95   SideEffects []
96 
97   SeeAlso     []
98 
99 ***********************************************************************/
Sim_UtilInfoAdd(unsigned * pInfo1,unsigned * pInfo2,int nWords)100 void Sim_UtilInfoAdd( unsigned * pInfo1, unsigned * pInfo2, int nWords )
101 {
102     int w;
103     for ( w = 0; w < nWords; w++ )
104         pInfo1[w] |= pInfo2[w];
105 }
106 
107 /**Function*************************************************************
108 
109   Synopsis    [Returns the positions where pInfo2 is 1 while pInfo1 is 0.]
110 
111   Description []
112 
113   SideEffects []
114 
115   SeeAlso     []
116 
117 ***********************************************************************/
Sim_UtilInfoDetectDiffs(unsigned * pInfo1,unsigned * pInfo2,int nWords,Vec_Int_t * vDiffs)118 void Sim_UtilInfoDetectDiffs( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
119 {
120     int w, b;
121     unsigned uMask;
122     vDiffs->nSize = 0;
123     for ( w = 0; w < nWords; w++ )
124         if ( (uMask = (pInfo2[w] ^ pInfo1[w])) )
125             for ( b = 0; b < 32; b++ )
126                 if ( uMask & (1 << b) )
127                     Vec_IntPush( vDiffs, 32*w + b );
128 }
129 
130 /**Function*************************************************************
131 
132   Synopsis    [Returns the positions where pInfo2 is 1 while pInfo1 is 0.]
133 
134   Description []
135 
136   SideEffects []
137 
138   SeeAlso     []
139 
140 ***********************************************************************/
Sim_UtilInfoDetectNews(unsigned * pInfo1,unsigned * pInfo2,int nWords,Vec_Int_t * vDiffs)141 void Sim_UtilInfoDetectNews( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
142 {
143     int w, b;
144     unsigned uMask;
145     vDiffs->nSize = 0;
146     for ( w = 0; w < nWords; w++ )
147         if ( (uMask = (pInfo2[w] & ~pInfo1[w])) )
148             for ( b = 0; b < 32; b++ )
149                 if ( uMask & (1 << b) )
150                     Vec_IntPush( vDiffs, 32*w + b );
151 }
152 
153 /**Function*************************************************************
154 
155   Synopsis    [Flips the simulation info of the node.]
156 
157   Description []
158 
159   SideEffects []
160 
161   SeeAlso     []
162 
163 ***********************************************************************/
Sim_UtilInfoFlip(Sim_Man_t * p,Abc_Obj_t * pNode)164 void Sim_UtilInfoFlip( Sim_Man_t * p, Abc_Obj_t * pNode )
165 {
166     unsigned * pSimInfo1, * pSimInfo2;
167     int k;
168     pSimInfo1 = (unsigned *)p->vSim0->pArray[pNode->Id];
169     pSimInfo2 = (unsigned *)p->vSim1->pArray[pNode->Id];
170     for ( k = 0; k < p->nSimWords; k++ )
171         pSimInfo2[k] = ~pSimInfo1[k];
172 }
173 
174 /**Function*************************************************************
175 
176   Synopsis    [Returns 1 if the simulation infos are equal.]
177 
178   Description []
179 
180   SideEffects []
181 
182   SeeAlso     []
183 
184 ***********************************************************************/
Sim_UtilInfoCompare(Sim_Man_t * p,Abc_Obj_t * pNode)185 int Sim_UtilInfoCompare( Sim_Man_t * p, Abc_Obj_t * pNode )
186 {
187     unsigned * pSimInfo1, * pSimInfo2;
188     int k;
189     pSimInfo1 = (unsigned *)p->vSim0->pArray[pNode->Id];
190     pSimInfo2 = (unsigned *)p->vSim1->pArray[pNode->Id];
191     for ( k = 0; k < p->nSimWords; k++ )
192         if ( pSimInfo2[k] != pSimInfo1[k] )
193             return 0;
194     return 1;
195 }
196 
197 /**Function*************************************************************
198 
199   Synopsis    [Simulates the internal nodes.]
200 
201   Description []
202 
203   SideEffects []
204 
205   SeeAlso     []
206 
207 ***********************************************************************/
Sim_UtilSimulate(Sim_Man_t * p,int fType)208 void Sim_UtilSimulate( Sim_Man_t * p, int fType )
209 {
210     Abc_Obj_t * pNode;
211     int i;
212     // simulate the internal nodes
213     Abc_NtkForEachNode( p->pNtk, pNode, i )
214         Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
215     // assign simulation info of the CO nodes
216     Abc_NtkForEachCo( p->pNtk, pNode, i )
217         Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
218 }
219 
220 /**Function*************************************************************
221 
222   Synopsis    [Simulates one node.]
223 
224   Description []
225 
226   SideEffects []
227 
228   SeeAlso     []
229 
230 ***********************************************************************/
Sim_UtilSimulateNode(Sim_Man_t * p,Abc_Obj_t * pNode,int fType,int fType1,int fType2)231 void Sim_UtilSimulateNode( Sim_Man_t * p, Abc_Obj_t * pNode, int fType, int fType1, int fType2 )
232 {
233     unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
234     int k, fComp1, fComp2;
235     // simulate the internal nodes
236     if ( Abc_ObjIsNode(pNode) )
237     {
238         if ( fType )
239             pSimmNode  = (unsigned *)p->vSim1->pArray[ pNode->Id ];
240         else
241             pSimmNode  = (unsigned *)p->vSim0->pArray[ pNode->Id ];
242 
243         if ( fType1 )
244             pSimmNode1 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
245         else
246             pSimmNode1 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
247 
248         if ( fType2 )
249             pSimmNode2 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId1(pNode) ];
250         else
251             pSimmNode2 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId1(pNode) ];
252 
253         fComp1 = Abc_ObjFaninC0(pNode);
254         fComp2 = Abc_ObjFaninC1(pNode);
255         if ( fComp1 && fComp2 )
256             for ( k = 0; k < p->nSimWords; k++ )
257                 pSimmNode[k] = ~pSimmNode1[k] & ~pSimmNode2[k];
258         else if ( fComp1 && !fComp2 )
259             for ( k = 0; k < p->nSimWords; k++ )
260                 pSimmNode[k] = ~pSimmNode1[k] &  pSimmNode2[k];
261         else if ( !fComp1 && fComp2 )
262             for ( k = 0; k < p->nSimWords; k++ )
263                 pSimmNode[k] =  pSimmNode1[k] & ~pSimmNode2[k];
264         else // if ( fComp1 && fComp2 )
265             for ( k = 0; k < p->nSimWords; k++ )
266                 pSimmNode[k] =  pSimmNode1[k] &  pSimmNode2[k];
267     }
268     else
269     {
270         assert( Abc_ObjFaninNum(pNode) == 1 );
271         if ( fType )
272             pSimmNode  = (unsigned *)p->vSim1->pArray[ pNode->Id ];
273         else
274             pSimmNode  = (unsigned *)p->vSim0->pArray[ pNode->Id ];
275 
276         if ( fType1 )
277             pSimmNode1 = (unsigned *)p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
278         else
279             pSimmNode1 = (unsigned *)p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
280 
281         fComp1 = Abc_ObjFaninC0(pNode);
282         if ( fComp1 )
283             for ( k = 0; k < p->nSimWords; k++ )
284                 pSimmNode[k] = ~pSimmNode1[k];
285         else
286             for ( k = 0; k < p->nSimWords; k++ )
287                 pSimmNode[k] =  pSimmNode1[k];
288     }
289 }
290 
291 /**Function*************************************************************
292 
293   Synopsis    [Simulates one node.]
294 
295   Description []
296 
297   SideEffects []
298 
299   SeeAlso     []
300 
301 ***********************************************************************/
Sim_UtilSimulateNodeOne(Abc_Obj_t * pNode,Vec_Ptr_t * vSimInfo,int nSimWords,int nOffset)302 void Sim_UtilSimulateNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset )
303 {
304     unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
305     int k, fComp1, fComp2;
306     // simulate the internal nodes
307     assert( Abc_ObjIsNode(pNode) );
308     pSimmNode  = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
309     pSimmNode1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
310     pSimmNode2 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId1(pNode));
311     pSimmNode  += nOffset;
312     pSimmNode1 += nOffset;
313     pSimmNode2 += nOffset;
314     fComp1 = Abc_ObjFaninC0(pNode);
315     fComp2 = Abc_ObjFaninC1(pNode);
316     if ( fComp1 && fComp2 )
317         for ( k = 0; k < nSimWords; k++ )
318             pSimmNode[k] = ~pSimmNode1[k] & ~pSimmNode2[k];
319     else if ( fComp1 && !fComp2 )
320         for ( k = 0; k < nSimWords; k++ )
321             pSimmNode[k] = ~pSimmNode1[k] &  pSimmNode2[k];
322     else if ( !fComp1 && fComp2 )
323         for ( k = 0; k < nSimWords; k++ )
324             pSimmNode[k] =  pSimmNode1[k] & ~pSimmNode2[k];
325     else // if ( fComp1 && fComp2 )
326         for ( k = 0; k < nSimWords; k++ )
327             pSimmNode[k] =  pSimmNode1[k] &  pSimmNode2[k];
328 }
329 
330 /**Function*************************************************************
331 
332   Synopsis    [Simulates one node.]
333 
334   Description []
335 
336   SideEffects []
337 
338   SeeAlso     []
339 
340 ***********************************************************************/
Sim_UtilTransferNodeOne(Abc_Obj_t * pNode,Vec_Ptr_t * vSimInfo,int nSimWords,int nOffset,int fShift)341 void Sim_UtilTransferNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset, int fShift )
342 {
343     unsigned * pSimmNode, * pSimmNode1;
344     int k, fComp1;
345     // simulate the internal nodes
346     assert( Abc_ObjIsCo(pNode) );
347     pSimmNode  = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
348     pSimmNode1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
349     pSimmNode  += nOffset + (fShift > 0)*nSimWords;
350     pSimmNode1 += nOffset;
351     fComp1 = Abc_ObjFaninC0(pNode);
352     if ( fComp1 )
353         for ( k = 0; k < nSimWords; k++ )
354             pSimmNode[k] = ~pSimmNode1[k];
355     else
356         for ( k = 0; k < nSimWords; k++ )
357             pSimmNode[k] =  pSimmNode1[k];
358 }
359 
360 /**Function*************************************************************
361 
362   Synopsis    [Returns 1 if the simulation infos are equal.]
363 
364   Description []
365 
366   SideEffects []
367 
368   SeeAlso     []
369 
370 ***********************************************************************/
Sim_UtilCountSuppSizes(Sim_Man_t * p,int fStruct)371 int Sim_UtilCountSuppSizes( Sim_Man_t * p, int fStruct )
372 {
373     Abc_Obj_t * pNode, * pNodeCi;
374     int i, v, Counter;
375     Counter = 0;
376     if ( fStruct )
377     {
378         Abc_NtkForEachCo( p->pNtk, pNode, i )
379             Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
380                 Counter += Sim_SuppStrHasVar( p->vSuppStr, pNode, v );
381     }
382     else
383     {
384         Abc_NtkForEachCo( p->pNtk, pNode, i )
385             Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
386                 Counter += Sim_SuppFunHasVar( p->vSuppFun, i, v );
387     }
388     return Counter;
389 }
390 
391 /**Function*************************************************************
392 
393   Synopsis    [Counts the number of 1's in the bitstring.]
394 
395   Description []
396 
397   SideEffects []
398 
399   SeeAlso     []
400 
401 ***********************************************************************/
Sim_UtilCountOnes(unsigned * pSimInfo,int nSimWords)402 int Sim_UtilCountOnes( unsigned * pSimInfo, int nSimWords )
403 {
404     unsigned char * pBytes;
405     int nOnes, nBytes, i;
406     pBytes = (unsigned char *)pSimInfo;
407     nBytes = 4 * nSimWords;
408     nOnes  = 0;
409     for ( i = 0; i < nBytes; i++ )
410         nOnes += bit_count[ pBytes[i] ];
411     return nOnes;
412 }
413 
414 /**Function*************************************************************
415 
416   Synopsis    [Counts the number of 1's in the bitstring.]
417 
418   Description []
419 
420   SideEffects []
421 
422   SeeAlso     []
423 
424 ***********************************************************************/
Sim_UtilCountOnesArray(Vec_Ptr_t * vInfo,int nSimWords)425 Vec_Int_t * Sim_UtilCountOnesArray( Vec_Ptr_t * vInfo, int nSimWords )
426 {
427     Vec_Int_t * vCounters;
428     unsigned * pSimInfo;
429     int i;
430     vCounters = Vec_IntStart( Vec_PtrSize(vInfo) );
431     Vec_PtrForEachEntry( unsigned *, vInfo, pSimInfo, i )
432         Vec_IntWriteEntry( vCounters, i, Sim_UtilCountOnes(pSimInfo, nSimWords) );
433     return vCounters;
434 }
435 
436 /**Function*************************************************************
437 
438   Synopsis    [Returns random patterns.]
439 
440   Description []
441 
442   SideEffects []
443 
444   SeeAlso     []
445 
446 ***********************************************************************/
Sim_UtilSetRandom(unsigned * pPatRand,int nSimWords)447 void Sim_UtilSetRandom( unsigned * pPatRand, int nSimWords )
448 {
449     int k;
450     for ( k = 0; k < nSimWords; k++ )
451         pPatRand[k] = SIM_RANDOM_UNSIGNED;
452 }
453 
454 /**Function*************************************************************
455 
456   Synopsis    [Returns complemented patterns.]
457 
458   Description []
459 
460   SideEffects []
461 
462   SeeAlso     []
463 
464 ***********************************************************************/
Sim_UtilSetCompl(unsigned * pPatRand,int nSimWords)465 void Sim_UtilSetCompl( unsigned * pPatRand, int nSimWords )
466 {
467     int k;
468     for ( k = 0; k < nSimWords; k++ )
469         pPatRand[k] = ~pPatRand[k];
470 }
471 
472 /**Function*************************************************************
473 
474   Synopsis    [Returns constant patterns.]
475 
476   Description []
477 
478   SideEffects []
479 
480   SeeAlso     []
481 
482 ***********************************************************************/
Sim_UtilSetConst(unsigned * pPatRand,int nSimWords,int fConst1)483 void Sim_UtilSetConst( unsigned * pPatRand, int nSimWords, int fConst1 )
484 {
485     int k;
486     for ( k = 0; k < nSimWords; k++ )
487         pPatRand[k] = 0;
488     if ( fConst1 )
489         Sim_UtilSetCompl( pPatRand, nSimWords );
490 }
491 
492 /**Function*************************************************************
493 
494   Synopsis    [Returns 1 if equal.]
495 
496   Description []
497 
498   SideEffects []
499 
500   SeeAlso     []
501 
502 ***********************************************************************/
Sim_UtilInfoIsEqual(unsigned * pPats1,unsigned * pPats2,int nSimWords)503 int Sim_UtilInfoIsEqual( unsigned * pPats1, unsigned * pPats2, int nSimWords )
504 {
505     int k;
506     for ( k = 0; k < nSimWords; k++ )
507         if ( pPats1[k] != pPats2[k] )
508             return 0;
509     return 1;
510 }
511 
512 /**Function*************************************************************
513 
514   Synopsis    [Returns 1 if Node1 implies Node2.]
515 
516   Description []
517 
518   SideEffects []
519 
520   SeeAlso     []
521 
522 ***********************************************************************/
Sim_UtilInfoIsImp(unsigned * pPats1,unsigned * pPats2,int nSimWords)523 int Sim_UtilInfoIsImp( unsigned * pPats1, unsigned * pPats2, int nSimWords )
524 {
525     int k;
526     for ( k = 0; k < nSimWords; k++ )
527         if ( pPats1[k] & ~pPats2[k] )
528             return 0;
529     return 1;
530 }
531 
532 /**Function*************************************************************
533 
534   Synopsis    [Returns 1 if Node1 v Node2 is always true.]
535 
536   Description []
537 
538   SideEffects []
539 
540   SeeAlso     []
541 
542 ***********************************************************************/
Sim_UtilInfoIsClause(unsigned * pPats1,unsigned * pPats2,int nSimWords)543 int Sim_UtilInfoIsClause( unsigned * pPats1, unsigned * pPats2, int nSimWords )
544 {
545     int k;
546     for ( k = 0; k < nSimWords; k++ )
547         if ( ~pPats1[k] & ~pPats2[k] )
548             return 0;
549     return 1;
550 }
551 
552 /**Function*************************************************************
553 
554   Synopsis    [Counts the total number of pairs.]
555 
556   Description []
557 
558   SideEffects []
559 
560   SeeAlso     []
561 
562 ***********************************************************************/
Sim_UtilCountAllPairs(Vec_Ptr_t * vSuppFun,int nSimWords,Vec_Int_t * vCounters)563 int Sim_UtilCountAllPairs( Vec_Ptr_t * vSuppFun, int nSimWords, Vec_Int_t * vCounters )
564 {
565     unsigned * pSupp;
566     int Counter, nOnes, nPairs, i;
567     Counter = 0;
568     Vec_PtrForEachEntry( unsigned *, vSuppFun, pSupp, i )
569     {
570         nOnes  = Sim_UtilCountOnes( pSupp, nSimWords );
571         nPairs = nOnes * (nOnes - 1) / 2;
572         Vec_IntWriteEntry( vCounters, i, nPairs );
573         Counter += nPairs;
574     }
575     return Counter;
576 }
577 
578 /**Function*************************************************************
579 
580   Synopsis    [Counts the number of entries in the array of matrices.]
581 
582   Description []
583 
584   SideEffects []
585 
586   SeeAlso     []
587 
588 ***********************************************************************/
Sim_UtilCountPairsOne(Extra_BitMat_t * pMat,Vec_Int_t * vSupport)589 int Sim_UtilCountPairsOne( Extra_BitMat_t * pMat, Vec_Int_t * vSupport )
590 {
591     int i, k, Index1, Index2;
592     int Counter = 0;
593 //    int Counter2;
594     Vec_IntForEachEntry( vSupport, i, Index1 )
595     Vec_IntForEachEntryStart( vSupport, k, Index2, Index1+1 )
596         Counter += Extra_BitMatrixLookup1( pMat, i, k );
597 //    Counter2 = Extra_BitMatrixCountOnesUpper(pMat);
598 //    assert( Counter == Counter2 );
599     return Counter;
600 }
601 
602 /**Function*************************************************************
603 
604   Synopsis    [Counts the number of entries in the array of matrices.]
605 
606   Description []
607 
608   SideEffects []
609 
610   SeeAlso     []
611 
612 ***********************************************************************/
Sim_UtilCountPairsOnePrint(Extra_BitMat_t * pMat,Vec_Int_t * vSupport)613 int Sim_UtilCountPairsOnePrint( Extra_BitMat_t * pMat, Vec_Int_t * vSupport )
614 {
615     int i, k, Index1, Index2;
616     Vec_IntForEachEntry( vSupport, i, Index1 )
617     Vec_IntForEachEntryStart( vSupport, k, Index2, Index1+1 )
618         if ( Extra_BitMatrixLookup1( pMat, i, k ) )
619             printf( "(%d,%d) ", i, k );
620     return 0;
621 }
622 
623 /**Function*************************************************************
624 
625   Synopsis    [Counts the number of entries in the array of matrices.]
626 
627   Description []
628 
629   SideEffects []
630 
631   SeeAlso     []
632 
633 ***********************************************************************/
Sim_UtilCountPairsAllPrint(Sym_Man_t * p)634 void Sim_UtilCountPairsAllPrint( Sym_Man_t * p )
635 {
636     int i;
637     abctime clk;
638 clk = Abc_Clock();
639     for ( i = 0; i < p->nOutputs; i++ )
640     {
641         printf( "Output %2d :", i );
642         Sim_UtilCountPairsOnePrint( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms, i), Vec_VecEntryInt(p->vSupports, i) );
643         printf( "\n" );
644     }
645 p->timeCount += Abc_Clock() - clk;
646 }
647 
648 /**Function*************************************************************
649 
650   Synopsis    [Counts the number of entries in the array of matrices.]
651 
652   Description []
653 
654   SideEffects []
655 
656   SeeAlso     []
657 
658 ***********************************************************************/
Sim_UtilCountPairsAll(Sym_Man_t * p)659 void Sim_UtilCountPairsAll( Sym_Man_t * p )
660 {
661     int nPairsTotal, nPairsSym, nPairsNonSym, i;
662     abctime clk;
663 clk = Abc_Clock();
664     p->nPairsSymm    = 0;
665     p->nPairsNonSymm = 0;
666     for ( i = 0; i < p->nOutputs; i++ )
667     {
668         nPairsTotal  = Vec_IntEntry(p->vPairsTotal, i);
669         nPairsSym    = Vec_IntEntry(p->vPairsSym,   i);
670         nPairsNonSym = Vec_IntEntry(p->vPairsNonSym,i);
671         assert( nPairsTotal >= nPairsSym + nPairsNonSym );
672         if ( nPairsTotal == nPairsSym + nPairsNonSym )
673         {
674             p->nPairsSymm    += nPairsSym;
675             p->nPairsNonSymm += nPairsNonSym;
676             continue;
677         }
678         nPairsSym    = Sim_UtilCountPairsOne( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms,   i), Vec_VecEntryInt(p->vSupports, i) );
679         nPairsNonSym = Sim_UtilCountPairsOne( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrNonSymms,i), Vec_VecEntryInt(p->vSupports, i) );
680         assert( nPairsTotal >= nPairsSym + nPairsNonSym );
681         Vec_IntWriteEntry( p->vPairsSym,    i, nPairsSym );
682         Vec_IntWriteEntry( p->vPairsNonSym, i, nPairsNonSym );
683         p->nPairsSymm    += nPairsSym;
684         p->nPairsNonSymm += nPairsNonSym;
685 //        printf( "%d ", nPairsTotal - nPairsSym - nPairsNonSym );
686     }
687 //printf( "\n" );
688     p->nPairsRem = p->nPairsTotal-p->nPairsSymm-p->nPairsNonSymm;
689 p->timeCount += Abc_Clock() - clk;
690 }
691 
692 /**Function*************************************************************
693 
694   Synopsis    []
695 
696   Description []
697 
698   SideEffects []
699 
700   SeeAlso     []
701 
702 ***********************************************************************/
Sim_UtilMatrsAreDisjoint(Sym_Man_t * p)703 int Sim_UtilMatrsAreDisjoint( Sym_Man_t * p )
704 {
705     int i;
706     for ( i = 0; i < p->nOutputs; i++ )
707         if ( !Extra_BitMatrixIsDisjoint( (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrSymms,i), (Extra_BitMat_t *)Vec_PtrEntry(p->vMatrNonSymms,i) ) )
708             return 0;
709     return 1;
710 }
711 
712 ////////////////////////////////////////////////////////////////////////
713 ///                       END OF FILE                                ///
714 ////////////////////////////////////////////////////////////////////////
715 
716 
717 ABC_NAMESPACE_IMPL_END
718 
719