ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fxuCreate.c File Reference
#include "fxuInt.h"
#include "fxu.h"
Include dependency graph for fxuCreate.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 ///.
 
Fxu_MatrixFxu_CreateMatrix (Fxu_Data_t *pData)
 FUNCTION DEFINITIONS ///.
 
void Fxu_CreateCovers (Fxu_Matrix *p, Fxu_Data_t *pData)
 

Function Documentation

◆ Fxu_CreateCovers()

void Fxu_CreateCovers ( Fxu_Matrix * p,
Fxu_Data_t * pData )

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

Synopsis [Creates the new array of Sop covers from the sparse matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 278 of file fxuCreate.c.

279{
280 Fxu_Cube * pCube, * pCubeFirst, * pCubeNext;
281 char * pSopCover;
282 int iNode, n;
283
284 // get the first cube of the first internal node
285 pCubeFirst = Fxu_CreateCoversFirstCube( p, pData, 0 );
286
287 // go through the internal nodes
288 for ( n = 0; n < pData->nNodesOld; n++ )
289 if ( (pSopCover = (char *)pData->vSops->pArray[n]) )
290 {
291 // get the number of this node
292 iNode = n;
293 // get the next first cube
294 pCubeNext = Fxu_CreateCoversFirstCube( p, pData, iNode + 1 );
295 // check if there any new variables in these cubes
296 for ( pCube = pCubeFirst; pCube != pCubeNext; pCube = pCube->pNext )
297 if ( pCube->lLits.pTail && pCube->lLits.pTail->iVar >= 2 * pData->nNodesOld )
298 break;
299 if ( pCube != pCubeNext )
300 Fxu_CreateCoversNode( p, pData, iNode, pCubeFirst, pCubeNext );
301 // update the first cube
302 pCubeFirst = pCubeNext;
303 }
304
305 // add the covers for the extracted nodes
306 for ( n = 0; n < pData->nNodesNew; n++ )
307 {
308 // get the number of this node
309 iNode = pData->nNodesOld + n;
310 // get the next first cube
311 pCubeNext = Fxu_CreateCoversFirstCube( p, pData, iNode + 1 );
312 // the node should be added
313 Fxu_CreateCoversNode( p, pData, iNode, pCubeFirst, pCubeNext );
314 // update the first cube
315 pCubeFirst = pCubeNext;
316 }
317}
Cube * p
Definition exorList.c:222
struct FxuCube Fxu_Cube
Definition fxuInt.h:66
Fxu_ListLit lLits
Definition fxuInt.h:206
Fxu_Cube * pNext
Definition fxuInt.h:208
Fxu_Lit * pTail
Definition fxuInt.h:110
int iVar
Definition fxuInt.h:228
Here is the caller graph for this function:

◆ Fxu_CreateMatrix()

Fxu_Matrix * Fxu_CreateMatrix ( Fxu_Data_t * pData)

FUNCTION DEFINITIONS ///.

DECLARATIONS ///.

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

Synopsis [Creates the sparse matrix from the array of SOPs.]

Description []

SideEffects []

SeeAlso []

Definition at line 52 of file fxuCreate.c.

53{
54 Fxu_Matrix * p;
55 Fxu_Var * pVar;
56 Fxu_Cube * pCubeFirst, * pCubeNew;
57 Fxu_Cube * pCube1, * pCube2;
58 Vec_Int_t * vFanins;
59 char * pSopCover;
60 char * pSopCube;
61 int * pOrder, nBitsMax;
62 int i, v, c;
63 int nCubesTotal;
64 int nPairsTotal;
65 int nPairsStore;
66 int nCubes;
67 int iCube, iPair;
68 int nFanins;
69
70 // collect all sorts of statistics
71 nCubesTotal = 0;
72 nPairsTotal = 0;
73 nPairsStore = 0;
74 nBitsMax = -1;
75 for ( i = 0; i < pData->nNodesOld; i++ )
76 if ( (pSopCover = (char *)pData->vSops->pArray[i]) )
77 {
78 nCubes = Abc_SopGetCubeNum( pSopCover );
79 nFanins = Abc_SopGetVarNum( pSopCover );
80 assert( nFanins > 1 && nCubes > 0 );
81
82 nCubesTotal += nCubes;
83 nPairsTotal += nCubes * (nCubes - 1) / 2;
84 nPairsStore += nCubes * nCubes;
85 if ( nBitsMax < nFanins )
86 nBitsMax = nFanins;
87 }
88 if ( nBitsMax <= 0 )
89 {
90 printf( "The current network does not have SOPs to perform extraction.\n" );
91 return NULL;
92 }
93
94 if ( nPairsStore > 50000000 )
95 {
96 printf( "The problem is too large to be solved by \"fxu\" (%d cubes and %d cube pairs)\n", nCubesTotal, nPairsStore );
97 return NULL;
98 }
99
100 // start the matrix
102 // create the column labels
103 p->ppVars = ABC_ALLOC( Fxu_Var *, 2 * (pData->nNodesOld + pData->nNodesExt) );
104 for ( i = 0; i < 2 * pData->nNodesOld; i++ )
105 p->ppVars[i] = Fxu_MatrixAddVar( p );
106
107 // allocate storage for all cube pairs at once
108 p->pppPairs = ABC_ALLOC( Fxu_Pair **, nCubesTotal + 100 );
109 p->ppPairs = ABC_ALLOC( Fxu_Pair *, nPairsStore + 100 );
110 memset( p->ppPairs, 0, sizeof(Fxu_Pair *) * nPairsStore );
111 iCube = 0;
112 iPair = 0;
113 for ( i = 0; i < pData->nNodesOld; i++ )
114 if ( (pSopCover = (char *)pData->vSops->pArray[i]) )
115 {
116 // get the number of cubes
117 nCubes = Abc_SopGetCubeNum( pSopCover );
118 // get the new var in the matrix
119 pVar = p->ppVars[2*i+1];
120 // assign the pair storage
121 pVar->nCubes = nCubes;
122 if ( nCubes > 0 )
123 {
124 pVar->ppPairs = p->pppPairs + iCube;
125 pVar->ppPairs[0] = p->ppPairs + iPair;
126 for ( v = 1; v < nCubes; v++ )
127 pVar->ppPairs[v] = pVar->ppPairs[v-1] + nCubes;
128 }
129 // update
130 iCube += nCubes;
131 iPair += nCubes * nCubes;
132 }
133 assert( iCube == nCubesTotal );
134 assert( iPair == nPairsStore );
135
136
137 // allocate room for the reordered literals
138 pOrder = ABC_ALLOC( int, nBitsMax );
139 // create the rows
140 for ( i = 0; i < pData->nNodesOld; i++ )
141 if ( (pSopCover = (char *)pData->vSops->pArray[i]) )
142 {
143 // get the new var in the matrix
144 pVar = p->ppVars[2*i+1];
145 // here we sort the literals of the cover
146 // in the increasing order of the numbers of the corresponding nodes
147 // because literals should be added to the matrix in this order
148 vFanins = (Vec_Int_t *)pData->vFanins->pArray[i];
149 s_pLits = vFanins->pArray;
150 // start the variable order
151 nFanins = Abc_SopGetVarNum( pSopCover );
152 for ( v = 0; v < nFanins; v++ )
153 pOrder[v] = v;
154 // reorder the fanins
155 qsort( (void *)pOrder, (size_t)nFanins, sizeof(int),(int (*)(const void *, const void *))Fxu_CreateMatrixLitCompare);
156 assert( s_pLits[ pOrder[0] ] < s_pLits[ pOrder[nFanins-1] ] );
157 // create the corresponding cubes in the matrix
158 pCubeFirst = NULL;
159 c = 0;
160 Abc_SopForEachCube( pSopCover, nFanins, pSopCube )
161 {
162 // create the cube
163 pCubeNew = Fxu_MatrixAddCube( p, pVar, c++ );
164 Fxu_CreateMatrixAddCube( p, pCubeNew, pSopCube, vFanins, pOrder );
165 if ( pCubeFirst == NULL )
166 pCubeFirst = pCubeNew;
167 pCubeNew->pFirst = pCubeFirst;
168 }
169 // set the first cube of this var
170 pVar->pFirst = pCubeFirst;
171 // create the divisors without preprocessing
172 if ( nPairsTotal <= pData->nPairsMax )
173 {
174 for ( pCube1 = pCubeFirst; pCube1; pCube1 = pCube1->pNext )
175 for ( pCube2 = pCube1? pCube1->pNext: NULL; pCube2; pCube2 = pCube2->pNext )
176 Fxu_MatrixAddDivisor( p, pCube1, pCube2 );
177 }
178 }
179 ABC_FREE( pOrder );
180
181 // consider the case when cube pairs should be preprocessed
182 // before adding them to the set of divisors
183// if ( pData->fVerbose )
184// printf( "The total number of cube pairs is %d.\n", nPairsTotal );
185 if ( nPairsTotal > 10000000 )
186 {
187 printf( "The total number of cube pairs of the network is more than 10,000,000.\n" );
188 printf( "Command \"fx\" takes a long time to run in such cases. It is suggested\n" );
189 printf( "that the user changes the network by reducing the size of logic node and\n" );
190 printf( "consequently the number of cube pairs to be processed by this command.\n" );
191 printf( "It can be achieved as follows: \"st; if -K <num>\" or \"st; renode -s -K <num>\"\n" );
192 printf( "as a proprocessing step, while selecting <num> as approapriate.\n" );
193 return NULL;
194 }
195 if ( nPairsTotal > pData->nPairsMax )
196 if ( !Fxu_PreprocessCubePairs( p, pData->vSops, nPairsTotal, pData->nPairsMax ) )
197 return NULL;
198// if ( pData->fVerbose )
199// printf( "Only %d best cube pairs will be used by the fast extract command.\n", pData->nPairsMax );
200
201 if ( p->lVars.nItems > 1000000 )
202 {
203 printf( "The total number of variables is more than 1,000,000.\n" );
204 printf( "Command \"fx\" takes a long time to run in such cases. It is suggested\n" );
205 printf( "that the user changes the network by reducing the size of logic node and\n" );
206 printf( "consequently the number of cube pairs to be processed by this command.\n" );
207 printf( "It can be achieved as follows: \"st; if -K <num>\" or \"st; renode -s -K <num>\"\n" );
208 printf( "as a proprocessing step, while selecting <num> as approapriate.\n" );
209 return NULL;
210 }
211
212
213 // add the var pairs to the heap
214 Fxu_MatrixComputeSingles( p, pData->fUse0, pData->nSingleMax );
215
216 // print stats
217 if ( pData->fVerbose )
218 {
219 double Density;
220 Density = ((double)p->nEntries) / p->lVars.nItems / p->lCubes.nItems;
221 fprintf( stdout, "Matrix: [vars x cubes] = [%d x %d] ",
222 p->lVars.nItems, p->lCubes.nItems );
223 fprintf( stdout, "Lits = %d Density = %.5f%%\n",
224 p->nEntries, Density );
225 fprintf( stdout, "1-cube divs = %6d. (Total = %6d) ", p->lSingles.nItems, p->nSingleTotal );
226 fprintf( stdout, "2-cube divs = %6d. (Total = %6d)", p->nDivsTotal, nPairsTotal );
227 fprintf( stdout, "\n" );
228 }
229// Fxu_MatrixPrint( stdout, p );
230 return p;
231}
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition abc.h:538
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition abcSop.c:537
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int Fxu_PreprocessCubePairs(Fxu_Matrix *p, Vec_Ptr_t *vCovers, int nPairsTotal, int nPairsMax)
FUNCTION DEFINITIONS ///.
Definition fxuReduce.c:53
Fxu_Var * Fxu_MatrixAddVar(Fxu_Matrix *p)
Definition fxuMatrix.c:161
struct FxuVar Fxu_Var
Definition fxuInt.h:67
Fxu_Matrix * Fxu_MatrixAllocate()
DECLARATIONS ///.
Definition fxuMatrix.c:43
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition fxuInt.h:63
struct FxuPair Fxu_Pair
Definition fxuInt.h:71
void Fxu_MatrixComputeSingles(Fxu_Matrix *p, int fUse0, int nSingleMax)
FUNCTION DEFINITIONS ///.
Definition fxuSingle.c:47
void Fxu_MatrixAddDivisor(Fxu_Matrix *p, Fxu_Cube *pCube1, Fxu_Cube *pCube2)
Definition fxuMatrix.c:301
Fxu_Cube * Fxu_MatrixAddCube(Fxu_Matrix *p, Fxu_Var *pVar, int iCube)
Definition fxuMatrix.c:183
Fxu_Cube * pFirst
Definition fxuInt.h:204
int nCubes
Definition fxuInt.h:216
Fxu_Pair *** ppPairs
Definition fxuInt.h:218
Fxu_Cube * pFirst
Definition fxuInt.h:217
#define assert(ex)
Definition util_old.h:213
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Fxu_PreprocessCubePairs()

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

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}
#define ABC_FALLOC(type, num)
Definition abc_global.h:266
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Fxu_Var * pVar
Definition fxuInt.h:205
Here is the call graph for this function:
Here is the caller graph for this function: