ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fxuReduce.c File Reference
#include "base/abc/abc.h"
#include "fxuInt.h"
#include "fxu.h"
Include dependency graph for fxuReduce.c:

Go to the source code of this file.

Functions

int Fxu_PreprocessCubePairs (Fxu_Matrix *p, Vec_Ptr_t *vCovers, int nPairsTotal, int nPairsMax)
 FUNCTION DEFINITIONS ///.
 

Function Documentation

◆ Fxu_PreprocessCubePairs()

int Fxu_PreprocessCubePairs ( Fxu_Matrix * p,
Vec_Ptr_t * vCovers,
int nPairsTotal,
int nPairsMax )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Precomputes the pairs to use for creating two-cube divisors.]

Description [This procedure takes the matrix with variables and cubes allocated (p), the original covers of the nodes (i-sets) and their number (ppCovers,nCovers). The maximum number of pairs to compute and the total number of pairs in existence. This procedure adds to the storage of divisors exactly the given number of pairs (nPairsMax) while taking first those pairs that have the smallest number of literals in their cube-free form.]

SideEffects []

SeeAlso []

Definition at line 53 of file fxuReduce.c.

54{
55 unsigned char * pnLitsDiff; // storage for the counters of diff literals
56 int * pnPairCounters; // the counters of pairs for each number of diff literals
57 Fxu_Cube * pCubeFirst, * pCubeLast;
58 Fxu_Cube * pCube1, * pCube2;
59 Fxu_Var * pVar;
60 int nCubes, nBitsMax, nSum;
61 int CutOffNum = -1, CutOffQuant = -1; // Suppress "might be used uninitialized"
62 int iPair, iQuant, k, c;
63// abctime clk = Abc_Clock();
64 char * pSopCover;
65 int nFanins;
66
67 assert( nPairsMax < nPairsTotal );
68
69 // allocate storage for counter of diffs
70 pnLitsDiff = ABC_FALLOC( unsigned char, nPairsTotal );
71 // go through the covers and precompute the distances between the pairs
72 iPair = 0;
73 nBitsMax = -1;
74 for ( c = 0; c < vCovers->nSize; c++ )
75 if ( (pSopCover = (char *)vCovers->pArray[c]) )
76 {
77 nFanins = Abc_SopGetVarNum(pSopCover);
78 // precompute the differences
79 Fxu_CountPairDiffs( pSopCover, pnLitsDiff + iPair );
80 // update the counter
81 nCubes = Abc_SopGetCubeNum( pSopCover );
82 iPair += nCubes * (nCubes - 1) / 2;
83 if ( nBitsMax < nFanins )
84 nBitsMax = nFanins;
85 }
86 assert( iPair == nPairsTotal );
87 if ( nBitsMax == -1 )
88 nBitsMax = 0;
89
90 // allocate storage for counters of cube pairs by difference
91 pnPairCounters = ABC_CALLOC( int, 2 * nBitsMax );
92 // count the number of different pairs
93 for ( k = 0; k < nPairsTotal; k++ )
94 pnPairCounters[ pnLitsDiff[k] ]++;
95 // determine what pairs to take starting from the lower
96 // so that there would be exactly pPairsMax pairs
97 if ( pnPairCounters[0] != 0 )
98 {
99 ABC_FREE( pnLitsDiff );
100 ABC_FREE( pnPairCounters );
101 printf( "The SOPs of the nodes contain duplicated cubes. Run \"bdd; sop\" before \"fx\".\n" );
102 return 0;
103 }
104 if ( pnPairCounters[1] != 0 )
105 {
106 ABC_FREE( pnLitsDiff );
107 ABC_FREE( pnPairCounters );
108 printf( "The SOPs of the nodes are not SCC-free. Run \"bdd; sop\" before \"fx\".\n" );
109 return 0;
110 }
111 assert( pnPairCounters[0] == 0 ); // otherwise, covers are not dup-free
112 assert( pnPairCounters[1] == 0 ); // otherwise, covers are not SCC-free
113 nSum = 0;
114 for ( k = 0; k < 2 * nBitsMax; k++ )
115 {
116 nSum += pnPairCounters[k];
117 if ( nSum >= nPairsMax )
118 {
119 CutOffNum = k;
120 CutOffQuant = pnPairCounters[k] - (nSum - nPairsMax);
121 break;
122 }
123 }
124 ABC_FREE( pnPairCounters );
125
126 // set to 0 all the pairs above the cut-off number and quantity
127 iQuant = 0;
128 iPair = 0;
129 for ( k = 0; k < nPairsTotal; k++ )
130 if ( pnLitsDiff[k] > CutOffNum )
131 pnLitsDiff[k] = 0;
132 else if ( pnLitsDiff[k] == CutOffNum )
133 {
134 if ( iQuant++ >= CutOffQuant )
135 pnLitsDiff[k] = 0;
136 else
137 iPair++;
138 }
139 else
140 iPair++;
141 assert( iPair == nPairsMax );
142
143 // collect the corresponding pairs and add the divisors
144 iPair = 0;
145 for ( c = 0; c < vCovers->nSize; c++ )
146 if ( (pSopCover = (char *)vCovers->pArray[c]) )
147 {
148 // get the var
149 pVar = p->ppVars[2*c+1];
150 // get the first cube
151 pCubeFirst = pVar->pFirst;
152 // get the last cube
153 pCubeLast = pCubeFirst;
154 for ( k = 0; k < pVar->nCubes; k++ )
155 pCubeLast = pCubeLast->pNext;
156 assert( pCubeLast == NULL || pCubeLast->pVar != pVar );
157
158 // go through the cube pairs
159 for ( pCube1 = pCubeFirst; pCube1 != pCubeLast; pCube1 = pCube1->pNext )
160 for ( pCube2 = pCube1->pNext; pCube2 != pCubeLast; pCube2 = pCube2->pNext )
161 if ( pnLitsDiff[iPair++] )
162 { // create the divisors for this pair
163 Fxu_MatrixAddDivisor( p, pCube1, pCube2 );
164 }
165 }
166 assert( iPair == nPairsTotal );
167 ABC_FREE( pnLitsDiff );
168//ABC_PRT( "Preprocess", Abc_Clock() - clk );
169 return 1;
170}
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition abcSop.c:537
#define ABC_FALLOC(type, num)
Definition abc_global.h:266
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
Cube * p
Definition exorList.c:222
struct FxuVar Fxu_Var
Definition fxuInt.h:67
struct FxuCube Fxu_Cube
Definition fxuInt.h:66
void Fxu_MatrixAddDivisor(Fxu_Matrix *p, Fxu_Cube *pCube1, Fxu_Cube *pCube2)
Definition fxuMatrix.c:301
Fxu_Cube * pNext
Definition fxuInt.h:208
Fxu_Var * pVar
Definition fxuInt.h:205
int nCubes
Definition fxuInt.h:216
Fxu_Cube * pFirst
Definition fxuInt.h:217
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function: