ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mapperTruth.c
Go to the documentation of this file.
1
18
19#include "mapperInt.h"
20
22
23
27
28static void Map_TruthsCut( Map_Man_t * pMan, Map_Cut_t * pCut );
29extern void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] );
30static void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited );
31
35
48{
49 ProgressBar * pProgress;
50 Map_Node_t * pNode;
51 Map_Cut_t * pCut;
52 int nNodes, i;
53 // compute the cuts for the POs
54 nNodes = pMan->vMapObjs->nSize;
55 pProgress = Extra_ProgressBarStart( stdout, nNodes );
56 for ( i = 0; i < nNodes; i++ )
57 {
58 pNode = pMan->vMapObjs->pArray[i];
59 if ( !Map_NodeIsAnd( pNode ) )
60 continue;
61 assert( pNode->pCuts );
62 assert( pNode->pCuts->nLeaves == 1 );
63
64 // match the simple cut
65 pNode->pCuts->M[0].uPhase = 0;
66 pNode->pCuts->M[0].pSupers = pMan->pSuperLib->pSuperInv;
67 pNode->pCuts->M[0].uPhaseBest = 0;
68 pNode->pCuts->M[0].pSuperBest = pMan->pSuperLib->pSuperInv;
69
70 pNode->pCuts->M[1].uPhase = 0;
71 pNode->pCuts->M[1].pSupers = pMan->pSuperLib->pSuperInv;
72 pNode->pCuts->M[1].uPhaseBest = 1;
73 pNode->pCuts->M[1].pSuperBest = pMan->pSuperLib->pSuperInv;
74
75 // match the rest of the cuts
76 for ( pCut = pNode->pCuts->pNext; pCut; pCut = pCut->pNext )
77 Map_TruthsCut( pMan, pCut );
78 Extra_ProgressBarUpdate( pProgress, i, "Tables ..." );
79 }
80 Extra_ProgressBarStop( pProgress );
81}
82
94void Map_TruthsCut( Map_Man_t * p, Map_Cut_t * pCut )
95{
96// unsigned uCanon1, uCanon2;
97 unsigned uTruth[2], uCanon[2];
98 unsigned char uPhases[16];
99 unsigned * uCanon2;
100 char * pPhases2;
101 int fUseFast = 1;
102 int fUseSlow = 0;
103 int fUseRec = 0; // this does not work for Solaris
104
105 extern int Map_CanonCompute( int nVarsMax, int nVarsReal, unsigned * pt, unsigned ** pptRes, char ** ppfRes );
106
107 // generally speaking, 1-input cut can be matched into a wire!
108 if ( pCut->nLeaves == 1 )
109 return;
110/*
111 if ( p->nVarsMax == 5 )
112 {
113 uTruth[0] = pCut->uTruth;
114 uTruth[1] = pCut->uTruth;
115 }
116 else
117*/
118 Map_TruthsCutOne( p, pCut, uTruth );
119
120
121 // compute the canonical form for the positive phase
122 if ( fUseFast )
123 Map_CanonComputeFast( p, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
124 else if ( fUseSlow )
125 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
126 else if ( fUseRec )
127 {
128// Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
129 Extra_TruthCanonFastN( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
130/*
131 if ( uCanon[0] != uCanon2[0] || uPhases[0] != pPhases2[0] )
132 {
133 int k = 0;
134 Map_CanonCompute( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
135 }
136*/
137 uCanon[0] = uCanon2[0];
138 uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
139 uPhases[0] = pPhases2[0];
140 }
141 else
142 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
143 pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
144 pCut->M[1].uPhase = uPhases[0];
145 p->nCanons++;
146
147//uCanon1 = uCanon[0] & 0xFFFF;
148
149 // compute the canonical form for the negative phase
150 uTruth[0] = ~uTruth[0];
151 uTruth[1] = ~uTruth[1];
152 if ( fUseFast )
153 Map_CanonComputeFast( p, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
154 else if ( fUseSlow )
155 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
156 else if ( fUseRec )
157 {
158// Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
159 Extra_TruthCanonFastN( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
160/*
161 if ( uCanon[0] != uCanon2[0] || uPhases[0] != pPhases2[0] )
162 {
163 int k = 0;
164 Map_CanonCompute( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
165 }
166*/
167 uCanon[0] = uCanon2[0];
168 uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
169 uPhases[0] = pPhases2[0];
170 }
171 else
172 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
173 pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
174 pCut->M[0].uPhase = uPhases[0];
175 p->nCanons++;
176
177//uCanon2 = uCanon[0] & 0xFFFF;
178//assert( p->nVarsMax == 4 );
179//Rwt_Man4ExploreCount( uCanon1 < uCanon2 ? uCanon1 : uCanon2 );
180
181 // restore the truth table
182 uTruth[0] = ~uTruth[0];
183 uTruth[1] = ~uTruth[1];
184}
185
197void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] )
198{
199 unsigned uTruth1[2], uTruth2[2];
200 Map_Cut_t * pTemp = NULL; // Suppress "might be used uninitialized"
201 int i;
202 // mark the cut leaves
203 for ( i = 0; i < pCut->nLeaves; i++ )
204 {
205 pTemp = pCut->ppLeaves[i]->pCuts;
206 pTemp->fMark = 1;
207 pTemp->M[0].uPhaseBest = p->uTruths[i][0];
208 pTemp->M[1].uPhaseBest = p->uTruths[i][1];
209 }
210 assert( pCut->fMark == 0 );
211
212 // collect the cuts in the cut cone
213 p->vVisited->nSize = 0;
214 Map_CutsCollect_rec( pCut, p->vVisited );
215 assert( p->vVisited->nSize > 0 );
216 pCut->nVolume = p->vVisited->nSize;
217
218 // compute the tables and unmark
219 for ( i = 0; i < pCut->nLeaves; i++ )
220 {
221 pTemp = pCut->ppLeaves[i]->pCuts;
222 pTemp->fMark = 0;
223 }
224 for ( i = 0; i < p->vVisited->nSize; i++ )
225 {
226 // get the cut
227 pTemp = (Map_Cut_t *)p->vVisited->pArray[i];
228 pTemp->fMark = 0;
229 // get truth table of the first branch
230 if ( Map_CutIsComplement(pTemp->pOne) )
231 {
232 uTruth1[0] = ~Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
233 uTruth1[1] = ~Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
234 }
235 else
236 {
237 uTruth1[0] = Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
238 uTruth1[1] = Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
239 }
240 // get truth table of the second branch
241 if ( Map_CutIsComplement(pTemp->pTwo) )
242 {
243 uTruth2[0] = ~Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
244 uTruth2[1] = ~Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
245 }
246 else
247 {
248 uTruth2[0] = Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
249 uTruth2[1] = Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
250 }
251 // get the truth table of the output
252 if ( !pTemp->Phase )
253 {
254 pTemp->M[0].uPhaseBest = uTruth1[0] & uTruth2[0];
255 pTemp->M[1].uPhaseBest = uTruth1[1] & uTruth2[1];
256 }
257 else
258 {
259 pTemp->M[0].uPhaseBest = ~(uTruth1[0] & uTruth2[0]);
260 pTemp->M[1].uPhaseBest = ~(uTruth1[1] & uTruth2[1]);
261 }
262 }
263 uTruth[0] = pTemp->M[0].uPhaseBest;
264 uTruth[1] = pTemp->M[1].uPhaseBest;
265}
266
278void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited )
279{
280 if ( pCut->fMark )
281 return;
282 Map_CutsCollect_rec( Map_CutRegular(pCut->pOne), vVisited );
283 Map_CutsCollect_rec( Map_CutRegular(pCut->pTwo), vVisited );
284 assert( pCut->fMark == 0 );
285 pCut->fMark = 1;
286 Map_NodeVecPush( vVisited, (Map_Node_t *)pCut );
287}
288
289/*
290 {
291 unsigned * uCanon2;
292 char * pPhases2;
293
294 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
295 Map_CanonCompute( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
296 if ( uCanon2[0] != uCanon[0] )
297 {
298 int v = 0;
299 Map_CanonCompute( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
300 Map_CanonComputeFast( p, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
301 }
302// else
303// {
304// printf( "Correct.\n" );
305// }
306 }
307*/
308
312
313
315
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int Extra_TruthCanonFastN(int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
void Map_NodeVecPush(Map_NodeVec_t *p, Map_Node_t *Entry)
Definition mapperVec.c:190
#define Map_CutRegular(p)
Definition mapperInt.h:69
#define Map_CutIsComplement(p)
Definition mapperInt.h:68
void Map_MappingTruths(Map_Man_t *pMan)
FUNCTION DEFINITIONS ///.
Definition mapperTruth.c:47
void Map_TruthsCutOne(Map_Man_t *p, Map_Cut_t *pCut, unsigned uTruth[])
typedefABC_NAMESPACE_HEADER_START struct Map_ManStruct_t_ Map_Man_t
INCLUDES ///.
Definition mapper.h:40
struct Map_CutStruct_t_ Map_Cut_t
Definition mapper.h:43
int Map_CanonComputeSlow(unsigned uTruths[][2], int nVarsMax, int nVarsReal, unsigned uTruth[], unsigned char *puPhases, unsigned uTruthRes[])
FUNCTION DEFINITIONS ///.
Definition mapperCanon.c:48
Map_Super_t * Map_SuperTableLookupC(Map_SuperLib_t *pLib, unsigned uTruth[])
int Map_CanonComputeFast(Map_Man_t *p, int nVarsMax, int nVarsReal, unsigned uTruth[], unsigned char *puPhases, unsigned uTruthRes[])
int Map_NodeIsAnd(Map_Node_t *p)
struct Map_NodeVecStruct_t_ Map_NodeVec_t
Definition mapper.h:42
struct Map_NodeStruct_t_ Map_Node_t
Definition mapper.h:41
Map_Cut_t * pTwo
Definition mapperInt.h:268
Map_Match_t M[2]
Definition mapperInt.h:275
Map_Node_t * ppLeaves[6]
Definition mapperInt.h:269
Map_Cut_t * pOne
Definition mapperInt.h:267
Map_Cut_t * pNext
Definition mapperInt.h:266
Map_Super_t * pSupers
Definition mapperInt.h:253
Map_Super_t * pSuperBest
Definition mapperInt.h:257
unsigned uPhaseBest
Definition mapperInt.h:256
Map_Cut_t * pCuts
Definition mapperInt.h:244
#define assert(ex)
Definition util_old.h:213