ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fxuReduce.c
Go to the documentation of this file.
1
18
19#include "base/abc/abc.h"
20#include "fxuInt.h"
21#include "fxu.h"
22
24
25
29
30static int Fxu_CountPairDiffs( char * pCover, unsigned char pDiffs[] );
31
35
53int Fxu_PreprocessCubePairs( Fxu_Matrix * p, Vec_Ptr_t * vCovers, int nPairsTotal, int nPairsMax )
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}
171
172
189int Fxu_CountPairDiffs( char * pCover, unsigned char pDiffs[] )
190{
191 char * pCube1, * pCube2;
192 int nOnes, nCubePairs, nFanins, v;
193 nCubePairs = 0;
194 nFanins = Abc_SopGetVarNum(pCover);
195 Abc_SopForEachCube( pCover, nFanins, pCube1 )
196 Abc_SopForEachCube( pCube1, nFanins, pCube2 )
197 {
198 if ( pCube1 == pCube2 )
199 continue;
200 nOnes = 0;
201 for ( v = 0; v < nFanins; v++ )
202 nOnes += (pCube1[v] != pCube2[v]);
203 pDiffs[nCubePairs++] = nOnes;
204 }
205 return 1;
206}
207
211
212
214
#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_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
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
struct FxuVar Fxu_Var
Definition fxuInt.h:67
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition fxuInt.h:63
struct FxuCube Fxu_Cube
Definition fxuInt.h:66
void Fxu_MatrixAddDivisor(Fxu_Matrix *p, Fxu_Cube *pCube1, Fxu_Cube *pCube2)
Definition fxuMatrix.c:301
int Fxu_PreprocessCubePairs(Fxu_Matrix *p, Vec_Ptr_t *vCovers, int nPairsTotal, int nPairsMax)
FUNCTION DEFINITIONS ///.
Definition fxuReduce.c:53
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
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42