ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioReadPlaMo.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22#include "misc/util/utilTruth.h"
23
25
29
30typedef struct Mop_Man_t_ Mop_Man_t;
42
43static inline int Mop_ManIsSopSymb( char c ) { return c == '0' || c == '1' || c == '-'; }
44static inline int Mop_ManIsSpace( char c ) { return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; }
45
46static inline word * Mop_ManCubeIn( Mop_Man_t * p, int i ) { return Vec_WrdEntryP(p->vWordsIn, p->nWordsIn * i); }
47static inline word * Mop_ManCubeOut( Mop_Man_t * p, int i ) { return Vec_WrdEntryP(p->vWordsOut, p->nWordsOut * i); }
48
52
64Mop_Man_t * Mop_ManAlloc( int nIns, int nOuts, int nCubes )
65{
67 p->nIns = nIns;
68 p->nOuts = nOuts;
69 p->nWordsIn = Abc_Bit6WordNum( 2 * nIns );
70 p->nWordsOut = Abc_Bit6WordNum( nOuts );
71 p->vWordsIn = Vec_WrdStart( 2 * p->nWordsIn * nCubes );
72 p->vWordsOut = Vec_WrdStart( 2 * p->nWordsOut * nCubes );
73 p->vCubes = Vec_IntAlloc( 2 * nCubes );
74 p->vFree = Vec_IntAlloc( 2 * nCubes );
75 return p;
76}
78{
79 Vec_WrdFree( p->vWordsIn );
80 Vec_WrdFree( p->vWordsOut );
81 Vec_IntFree( p->vCubes );
82 Vec_IntFree( p->vFree );
83 ABC_FREE( p );
84}
85
97char * Mop_ManLoadFile( char * pFileName )
98{
99 FILE * pFile;
100 int nFileSize, RetValue;
101 char * pContents;
102 pFile = fopen( pFileName, "rb" );
103 if ( pFile == NULL )
104 {
105 Abc_Print( -1, "Mop_ManLoadFile(): The file is unavailable (absent or open).\n" );
106 return NULL;
107 }
108 fseek( pFile, 0, SEEK_END );
109 nFileSize = ftell( pFile );
110 if ( nFileSize == 0 )
111 {
112 Abc_Print( -1, "Mop_ManLoadFile(): The file is empty.\n" );
113 return NULL;
114 }
115 pContents = ABC_ALLOC( char, nFileSize + 10 );
116 rewind( pFile );
117 RetValue = fread( pContents, nFileSize, 1, pFile );
118 fclose( pFile );
119 strcpy( pContents + nFileSize, "\n" );
120 return pContents;
121}
122
134int Mop_ManReadParams( char * pBuffer, int * pnIns, int * pnOuts )
135{
136 char * pIns = strstr( pBuffer, ".i " );
137 char * pOuts = strstr( pBuffer, ".o " );
138 char * pStr = pBuffer; int nCubes = 0;
139 if ( pIns == NULL || pOuts == NULL )
140 return -1;
141 *pnIns = atoi( pIns + 2 );
142 *pnOuts = atoi( pOuts + 2 );
143 while ( *pStr )
144 nCubes += (*pStr++ == '\n');
145 return nCubes;
146}
147Mop_Man_t * Mop_ManRead( char * pFileName )
148{
149 Mop_Man_t * p;
150 int nIns, nOuts, nCubes, iCube;
151 char * pToken, * pBuffer = Mop_ManLoadFile( pFileName );
152 if ( pBuffer == NULL )
153 return NULL;
154 nCubes = Mop_ManReadParams( pBuffer, &nIns, &nOuts );
155 if ( nCubes == -1 )
156 return NULL;
157 p = Mop_ManAlloc( nIns, nOuts, nCubes );
158 // get the first cube
159 pToken = strtok( pBuffer, "\n" );
160 while ( pToken )
161 {
162 while ( Mop_ManIsSpace(*pToken) )
163 pToken++;
164 if ( Mop_ManIsSopSymb(*pToken) )
165 break;
166 pToken = strtok( NULL, "\n" );
167 }
168 // read cubes
169 for ( iCube = 0; pToken && Mop_ManIsSopSymb(*pToken); iCube++ )
170 {
171 char * pTokenCopy = pToken;
172 int i, o, nVars[2] = {nIns, nOuts};
173 word * pCube[2] = { Mop_ManCubeIn(p, iCube), Mop_ManCubeOut(p, iCube) };
174 for ( o = 0; o < 2; o++ )
175 {
176 while ( Mop_ManIsSpace(*pToken) )
177 pToken++;
178 for ( i = 0; i < nVars[o]; i++, pToken++ )
179 {
180 if ( !Mop_ManIsSopSymb(*pToken) )
181 {
182 printf( "Cannot read cube %d (%s).\n", iCube+1, pTokenCopy );
183 ABC_FREE( pBuffer );
184 Mop_ManStop( p );
185 return NULL;
186 }
187 if ( o == 1 )
188 {
189 if ( *pToken == '1' )
190 Abc_TtSetBit( pCube[o], i );
191 }
192 else if ( *pToken == '0' )
193 Abc_TtSetBit( pCube[o], 2*i );
194 else if ( *pToken == '1' )
195 Abc_TtSetBit( pCube[o], 2*i+1 );
196 }
197 }
198 assert( iCube < nCubes );
199 Vec_IntPush( p->vCubes, iCube );
200 pToken = strtok( NULL, "\n" );
201 }
202 for ( ; iCube < 2 * nCubes; iCube++ )
203 Vec_IntPush( p->vFree, iCube );
204 ABC_FREE( pBuffer );
205 return p;
206}
207void Mop_ManPrintOne( Mop_Man_t * p, int iCube )
208{
209 int k;
210 char Symb[4] = { '-', '0', '1', '?' };
211 word * pCubeIn = Mop_ManCubeIn( p, iCube );
212 word * pCubeOut = Mop_ManCubeOut( p, iCube );
213 for ( k = 0; k < p->nIns; k++ )
214 printf( "%c", Symb[Abc_TtGetQua(pCubeIn, k)] );
215 printf( " " );
216 for ( k = 0; k < p->nOuts; k++ )
217 printf( "%d", Abc_TtGetBit(pCubeOut, k) );
218 printf( "\n" );
219}
221{
222 int i, iCube;
223 printf( ".%d\n", p->nIns );
224 printf( ".%d\n", p->nOuts );
225 Vec_IntForEachEntry( p->vCubes, iCube, i )
226 Mop_ManPrintOne( p, iCube );
227 printf( ".e\n" );
228}
229
241static inline int Mop_ManCountOnes( word * pCube, int nWords )
242{
243 int w, Count = 0;
244 for ( w = 0; w < nWords; w++ )
245 Count += Abc_TtCountOnes( pCube[w] );
246 return Count;
247}
248static inline int Mop_ManCountOutputLits( Mop_Man_t * p )
249{
250 int i, iCube, nOutLits = 0;
251 Vec_IntForEachEntry( p->vCubes, iCube, i )
252 nOutLits += Mop_ManCountOnes( Mop_ManCubeOut(p, iCube), p->nWordsOut );
253 return nOutLits;
254}
255static inline Vec_Wec_t * Mop_ManCreateGroups( Mop_Man_t * p )
256{
257 int i, iCube;
258 Vec_Wec_t * vGroups = Vec_WecStart( p->nIns );
259 Vec_IntForEachEntry( p->vCubes, iCube, i )
260 Vec_WecPush( vGroups, Mop_ManCountOnes(Mop_ManCubeIn(p, iCube), p->nWordsIn), iCube );
261 return vGroups;
262}
263static inline int Mop_ManUnCreateGroups( Mop_Man_t * p, Vec_Wec_t * vGroups )
264{
265 int i, c1, iCube1;
266 int nBefore = Vec_IntSize(p->vCubes);
267 Vec_Int_t * vGroup;
268 Vec_IntClear( p->vCubes );
269 Vec_WecForEachLevel( vGroups, vGroup, i )
270 Vec_IntForEachEntry( vGroup, iCube1, c1 )
271 if ( iCube1 != -1 )
272 Vec_IntPush( p->vCubes, iCube1 );
273 return nBefore - Vec_IntSize(p->vCubes);
274}
275static inline int Mop_ManCheckContain( word * pBig, word * pSmall, int nWords )
276{
277 int w;
278 for ( w = 0; w < nWords; w++ )
279 if ( pSmall[w] != (pSmall[w] & pBig[w]) )
280 return 0;
281 return 1;
282}
283static inline void Mop_ManRemoveEmpty( Mop_Man_t * p )
284{
285 int w, i, k = 0, iCube;
286 Vec_IntForEachEntry( p->vCubes, iCube, i )
287 {
288 word * pCube = Mop_ManCubeOut( p, iCube );
289 for ( w = 0; w < p->nWordsOut; w++ )
290 if ( pCube[w] )
291 break;
292 if ( w < p->nWordsOut )
293 Vec_IntWriteEntry( p->vCubes, k++, iCube );
294 }
295 Vec_IntShrink( p->vCubes, k );
296}
297
310{
311 int i, v, iCube, nVars = 32 * p->nWordsIn;
312 Vec_Int_t * vStats = Vec_IntStart( nVars );
313 Vec_IntForEachEntry( p->vCubes, iCube, i )
314 {
315 word * pCube = Mop_ManCubeIn(p, iCube);
316 int nOutLits = Mop_ManCountOnes( Mop_ManCubeOut(p, iCube), p->nWordsOut );
317 for ( v = 0; v < nVars; v++ )
318 if ( Abc_TtGetQua(pCube, v) )
319 Vec_IntAddToEntry( vStats, v, nOutLits );
320 }
321 return vStats;
322}
323
335// knowing that cubes are distance-1, find the different input variable
336static inline int Mop_ManFindDiffVar( word * pCube1, word * pCube2, int nWords )
337{
338 int w, i;
339 for ( w = 0; w < nWords; w++ )
340 {
341 word Xor = pCube1[w] ^ pCube2[w];
342 for ( i = 0; i < 32; i++ )
343 if ( (Xor >> (i << 1)) & 0x3 )
344 return w * 32 + i;
345 }
346 assert( 0 );
347 return -1;
348}
349// check containment of input parts of two cubes
350static inline int Mop_ManCheckDist1( word * pCube1, word * pCube2, int nWords )
351{
352 int w, fFound1 = 0;
353 for ( w = 0; w < nWords; w++ )
354 {
355 word Xor = pCube1[w] ^ pCube2[w];
356 if ( Xor == 0 ) // equal
357 continue;
358 if ( (Xor ^ (Xor >> 1)) & ABC_CONST(0x5555555555555555) ) // not pairs
359 return 0;
360 Xor &= (Xor >> 1) & ABC_CONST(0x5555555555555555);
361 if ( Xor == 0 ) // not equal and not distance-1
362 return 0;
363 if ( fFound1 ) // distance-2 or more
364 return 0;
365 if ( (Xor & (Xor-1)) ) // distance-2 or more
366 return 0;
367 fFound1 = 1; // distance 1 so far
368 }
369 return fFound1;
370}
371// compresses cubes in the group
372static inline void Map_ManGroupCompact( Vec_Int_t * vGroup )
373{
374 int i, Entry, k = 0;
375 Vec_IntForEachEntry( vGroup, Entry, i )
376 if ( Entry != -1 )
377 Vec_IntWriteEntry( vGroup, k++, Entry );
378 Vec_IntShrink( vGroup, k );
379}
380// takes cubes with identical literal count and removes duplicates
382{
383 int w, c1, c2, iCube1, iCube2, nEqual = 0;
384 Vec_IntForEachEntry( vGroup, iCube1, c1 )
385 if ( iCube1 != -1 )
386 {
387 word * pCube1Out, * pCube1 = Mop_ManCubeIn( p, iCube1 );
388 Vec_IntForEachEntryStart( vGroup, iCube2, c2, c1+1 )
389 if ( iCube2 != -1 )
390 {
391 word * pCube2Out, * pCube2 = Mop_ManCubeIn( p, iCube2 );
392 if ( memcmp(pCube1, pCube2, sizeof(word)*p->nWordsIn) )
393 continue;
394 // merge cubes
395 pCube1Out = Mop_ManCubeOut( p, iCube1 );
396 pCube2Out = Mop_ManCubeOut( p, iCube2 );
397 for ( w = 0; w < p->nWordsOut; w++ )
398 pCube1Out[w] |= pCube2Out[w];
399 Vec_IntWriteEntry( vGroup, c2, -1 );
400 Vec_IntPush( p->vFree, iCube2 );
401 nEqual++;
402 }
403 }
404 if ( nEqual )
405 Map_ManGroupCompact( vGroup );
406 return nEqual;
407}
408// reduces the set of pairs
410{
411 int i, Entry, Entry2;
412 Vec_Int_t * vCounts = Vec_IntStart( nObjs );
413 Vec_Int_t * vPairsNew = Vec_IntAlloc( Vec_IntSize(vPairs) );
414 Vec_IntForEachEntry( vPairs, Entry, i )
415 Vec_IntAddToEntry( vCounts, Entry, 1 );
416 // include pairs which have those that appear only once
417 Vec_IntForEachEntryDouble( vPairs, Entry, Entry2, i )
418 if ( Vec_IntEntry(vCounts, Entry) == 1 || Vec_IntEntry(vCounts, Entry2) == 1 )
419 {
420 if ( Vec_IntEntry(vCounts, Entry) == 1 )
421 Vec_IntPushTwo( vPairsNew, Entry, Entry2 );
422 else
423 Vec_IntPushTwo( vPairsNew, Entry2, Entry );
424 Vec_IntWriteEntry( vCounts, Entry, -1 );
425 Vec_IntWriteEntry( vCounts, Entry2, -1 );
426 }
427 // add those remaining pairs that are both present
428 Vec_IntForEachEntryDouble( vPairs, Entry, Entry2, i )
429 if ( Vec_IntEntry(vCounts, Entry) > 0 && Vec_IntEntry(vCounts, Entry2) > 0 )
430 {
431 Vec_IntPushTwo( vPairsNew, Entry, Entry2 );
432 Vec_IntWriteEntry( vCounts, Entry, -1 );
433 Vec_IntWriteEntry( vCounts, Entry2, -1 );
434 }
435 // add remaining pairs
436 Vec_IntForEachEntryDouble( vPairs, Entry, Entry2, i )
437 if ( Vec_IntEntry(vCounts, Entry) > 0 || Vec_IntEntry(vCounts, Entry2) > 0 )
438 {
439 if ( Vec_IntEntry(vCounts, Entry) > 0 )
440 Vec_IntPushTwo( vPairsNew, Entry, Entry2 );
441 else
442 Vec_IntPushTwo( vPairsNew, Entry2, Entry );
443 Vec_IntWriteEntry( vCounts, Entry, -1 );
444 Vec_IntWriteEntry( vCounts, Entry2, -1 );
445 }
446 Vec_IntFree( vCounts );
447 // verify the result
448 if ( 0 )
449 {
450 Vec_Int_t * vTemp1 = Vec_IntDup( vPairs );
451 Vec_Int_t * vTemp2 = Vec_IntDup( vPairsNew );
452 Vec_IntUniqify( vTemp1 );
453 Vec_IntUniqify( vTemp2 );
454 assert( Vec_IntEqual( vTemp1, vTemp2 ) );
455 Vec_IntFree( vTemp1 );
456 Vec_IntFree( vTemp2 );
457 }
458 return vPairsNew;
459}
460// detects pairs of distance-1 cubes with identical outputs
462{
463 int c1, c2, iCube1, iCube2;
464 Vec_Int_t * vPairs = Vec_IntAlloc( 100 );
465 Vec_IntForEachEntry( vGroup, iCube1, c1 )
466 {
467 word * pCube1Out, * pCube1 = Mop_ManCubeIn( p, iCube1 );
468 Vec_IntForEachEntryStart( vGroup, iCube2, c2, c1+1 )
469 {
470 word * pCube2Out, * pCube2 = Mop_ManCubeIn( p, iCube2 );
471 if ( !Mop_ManCheckDist1(pCube1, pCube2, p->nWordsIn) )
472 continue;
473 pCube1Out = Mop_ManCubeOut( p, iCube1 );
474 pCube2Out = Mop_ManCubeOut( p, iCube2 );
475 if ( !memcmp(pCube1Out, pCube2Out, sizeof(word)*p->nWordsOut) )
476 Vec_IntPushTwo( vPairs, c1, c2 );
477 }
478 }
479 return vPairs;
480}
481// merge distance-1 with identical output part
482int Mop_ManMergeDist1Pairs( Mop_Man_t * p, Vec_Int_t * vGroup, Vec_Int_t * vGroupPrev, Vec_Int_t * vStats, int nLimit )
483{
484 Vec_Int_t * vPairs = Mop_ManFindDist1Pairs( p, vGroup );
485 Vec_Int_t * vPairsNew = Mop_ManCompatiblePairs( vPairs, Vec_IntSize(vGroup) );
486 int nCubes = Vec_IntSize(vGroup) + Vec_IntSize(vGroupPrev);
487 int w, i, c1, c2, iCubeNew, iVar;
488 // move cubes to the previous group
489 word * pCube, * pCube1, * pCube2;
490 Vec_Int_t * vToFree = Vec_IntAlloc( Vec_IntSize(vPairsNew) );
491 Vec_IntForEachEntryDouble( vPairsNew, c1, c2, i )
492 {
493 pCube1 = Mop_ManCubeIn( p, Vec_IntEntry(vGroup, c1) );
494 pCube2 = Mop_ManCubeIn( p, Vec_IntEntry(vGroup, c2) );
495 assert( Mop_ManCheckDist1(pCube1, pCube2, p->nWordsIn) );
496
497 // skip those cubes that have frequently appearing variables
498 iVar = Mop_ManFindDiffVar( pCube1, pCube2, p->nWordsIn );
499 if ( Vec_IntEntry( vStats, iVar ) > nLimit )
500 continue;
501 Vec_IntPush( vToFree, c1 );
502 Vec_IntPush( vToFree, c2 );
503
504 iCubeNew = Vec_IntPop( p->vFree );
505 pCube = Mop_ManCubeIn( p, iCubeNew );
506 for ( w = 0; w < p->nWordsIn; w++ )
507 pCube[w] = pCube1[w] & pCube2[w];
508
509 pCube = Mop_ManCubeOut( p, iCubeNew );
510 pCube1 = Mop_ManCubeOut( p, Vec_IntEntry(vGroup, c1) );
511 pCube2 = Mop_ManCubeOut( p, Vec_IntEntry(vGroup, c2) );
512
513 assert( !memcmp(pCube1, pCube2, sizeof(word)*p->nWordsOut) );
514 for ( w = 0; w < p->nWordsOut; w++ )
515 pCube[w] = pCube1[w];
516
517 Vec_IntPush( vGroupPrev, iCubeNew );
518 }
519// Vec_IntForEachEntry( vPairsNew, c1, i )
520 Vec_IntForEachEntry( vToFree, c1, i )
521 {
522 if ( Vec_IntEntry(vGroup, c1) == -1 )
523 continue;
524 Vec_IntPush( p->vFree, Vec_IntEntry(vGroup, c1) );
525 Vec_IntWriteEntry( vGroup, c1, -1 );
526 }
527 Vec_IntFree( vToFree );
528 if ( Vec_IntSize(vPairsNew) > 0 )
529 Map_ManGroupCompact( vGroup );
530 Vec_IntFree( vPairs );
531 Vec_IntFree( vPairsNew );
532 return nCubes - Vec_IntSize(vGroup) - Vec_IntSize(vGroupPrev);
533}
534// merge distance-1 with contained output part
535int Mop_ManMergeDist1Pairs2( Mop_Man_t * p, Vec_Int_t * vGroup, Vec_Int_t * vGroupPrev )
536{
537 int w, c1, c2, iCube1, iCube2, Count = 0;
538 Vec_IntForEachEntry( vGroup, iCube1, c1 )
539 if ( iCube1 != -1 )
540 {
541 word * pCube1Out, * pCube1 = Mop_ManCubeIn( p, iCube1 );
542 Vec_IntForEachEntryStart( vGroup, iCube2, c2, c1+1 )
543 if ( iCube2 != -1 )
544 {
545 word * pCube2Out, * pCube2 = Mop_ManCubeIn( p, iCube2 );
546 if ( !Mop_ManCheckDist1(pCube1, pCube2, p->nWordsIn) )
547 continue;
548 pCube1Out = Mop_ManCubeOut( p, iCube1 );
549 pCube2Out = Mop_ManCubeOut( p, iCube2 );
550 assert( memcmp(pCube1Out, pCube2Out, sizeof(word)*p->nWordsOut) );
551 if ( Mop_ManCheckContain(pCube1Out, pCube2Out, p->nWordsOut) ) // pCube1 has more outputs
552 {
553 // update the input part
554 for ( w = 0; w < p->nWordsIn; w++ )
555 pCube2[w] &= pCube1[w];
556 // sharp the output part
557 for ( w = 0; w < p->nWordsOut; w++ )
558 pCube1Out[w] &= ~pCube2Out[w];
559 // move to another group
560 Vec_IntPush( vGroupPrev, iCube2 );
561 Vec_IntWriteEntry( vGroup, c2, -1 );
562 Count++;
563 }
564 else if ( Mop_ManCheckContain(pCube2Out, pCube1Out, p->nWordsOut) ) // pCube2 has more outputs
565 {
566 // update the input part
567 for ( w = 0; w < p->nWordsIn; w++ )
568 pCube1[w] &= pCube2[w];
569 // sharp the output part
570 for ( w = 0; w < p->nWordsOut; w++ )
571 pCube2Out[w] &= ~pCube1Out[w];
572 // move to another group
573 Vec_IntPush( vGroupPrev, iCube1 );
574 Vec_IntWriteEntry( vGroup, c1, -1 );
575 Count++;
576 }
577 }
578 }
579 if ( Count )
580 Map_ManGroupCompact( vGroup );
581 return Count;
582}
583int Mop_ManMergeDist1All( Mop_Man_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vStats, int nLimit )
584{
585 Vec_Int_t * vGroup;
586 int i, nEqual, nReduce, Count = 0;
587 Vec_WecForEachLevelReverse( vGroups, vGroup, i )
588 {
589 if ( Vec_IntSize(vGroup) == 0 )
590 continue;
591 if ( i == 0 )
592 {
593 printf( "Detected constant-1 cover.\n" );
594 fflush( stdout );
595 return -1;
596 }
597 nEqual = Mop_ManRemoveIdentical( p, vGroup );
598 nReduce = Mop_ManMergeDist1Pairs( p, vGroup, Vec_WecEntry(vGroups, i-1), vStats, nLimit );
599 //Mop_ManMergeDist1Pairs2( p, vGroup, Vec_WecEntry(vGroups, i-1) );
600 Count += nEqual + nReduce;
601 //printf( "Group %3d : Equal =%5d. Reduce =%5d.\n", i, nEqual, nReduce );
602 }
603 return Count;
604}
605// reduce contained cubes
607{
608 int w, c1, c2, iCube1, iCube2, Count = 0;
609 Vec_IntForEachEntry( vGroup, iCube1, c1 )
610 {
611 word * pCube1Out, * pCube1 = Mop_ManCubeIn( p, iCube1 );
612 Vec_IntForEachEntry( vGroup2, iCube2, c2 )
613 if ( iCube2 != -1 )
614 {
615 word * pCube2Out, * pCube2 = Mop_ManCubeIn( p, iCube2 );
616 if ( !Mop_ManCheckContain(pCube2, pCube1, p->nWordsIn) )
617 continue;
618 pCube1Out = Mop_ManCubeOut( p, iCube1 );
619 pCube2Out = Mop_ManCubeOut( p, iCube2 );
620 for ( w = 0; w < p->nWordsOut; w++ )
621 pCube2Out[w] &= ~pCube1Out[w];
622 for ( w = 0; w < p->nWordsOut; w++ )
623 if ( pCube2Out[w] )
624 break;
625 if ( w < p->nWordsOut ) // has output literals
626 continue;
627 // remove larger cube
628 Vec_IntWriteEntry( vGroup2, c2, -1 );
629 Vec_IntPush( p->vFree, iCube2 );
630 Count++;
631 }
632 }
633 if ( Count )
634 Map_ManGroupCompact( vGroup2 );
635 return Count;
636}
638{
639 Vec_Int_t * vGroup, * vGroup2;
640 int i, k, Count = 0;
641 Vec_WecForEachLevel( vGroups, vGroup, i )
642 {
643 Count += Mop_ManRemoveIdentical( p, vGroup );
644 Vec_WecForEachLevelStart( vGroups, vGroup2, k, i+1 )
645 Count += Mop_ManMergeContainTwo( p, vGroup, vGroup2 );
646 }
647 return Count;
648}
650{
651 abctime clk = Abc_Clock();
652 int nCubes = Vec_IntSize(p->vCubes);
653 Vec_Int_t * vStats = Mop_ManCollectStats( p );
654 Vec_Wec_t * vGroups = Mop_ManCreateGroups( p );
655 int nLimit = ABC_INFINITY; // 5 * Vec_IntSum(vStats) / Vec_IntSize(vStats) + 1;
656 int nOutLits = Mop_ManCountOutputLits( p );
657 int Count1 = Mop_ManMergeContainAll( p, vGroups );
658 int Count2 = Mop_ManMergeDist1All( p, vGroups, vStats, nLimit );
659 int Count3 = Mop_ManMergeContainAll( p, vGroups );
660 int Count4 = Mop_ManMergeDist1All( p, vGroups, vStats, nLimit );
661 int Count5 = Mop_ManMergeContainAll( p, vGroups );
662 int Removed = Mop_ManUnCreateGroups( p, vGroups );
663 int nOutLits2 = Mop_ManCountOutputLits( p );
664 Vec_WecFree( vGroups );
665//Vec_IntPrint( vStats );
666 Vec_IntFree( vStats );
667 assert( Removed == Count1 + Count2 + Count3 );
668 // report
669 printf( "Cubes: %d -> %d. C = %d. M = %d. C = %d. M = %d. C = %d. Output lits: %d -> %d. ",
670 nCubes, Vec_IntSize(p->vCubes), Count1, Count2, Count3, Count4, Count5, nOutLits, nOutLits2 );
671 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
672}
673
674
687{
688 abctime clk = Abc_Clock();
689 Vec_Int_t * vGroup, * vGroup2;
690 int i, k, nOutLits, nOutLits2, nEqual = 0, nContain = 0;
691 Vec_Wec_t * vGroups = Mop_ManCreateGroups( p );
692 // initial stats
693 nOutLits = Mop_ManCountOutputLits( p );
694 // check identical cubes within each group
695 Vec_WecForEachLevel( vGroups, vGroup, i )
696 nEqual += Mop_ManRemoveIdentical( p, vGroup );
697 // check contained cubes
698 Vec_WecForEachLevel( vGroups, vGroup, i )
699 Vec_WecForEachLevelStart( vGroups, vGroup2, k, i+1 )
700 nContain += Mop_ManMergeContainTwo( p, vGroup, vGroup2 );
701 // final stats
702 nOutLits2 = Mop_ManCountOutputLits( p );
703 Mop_ManUnCreateGroups( p, vGroups );
704 Vec_WecFree( vGroups );
705 // report
706 printf( "Total = %d. Reduced %d equal and %d contained cubes. Output lits: %d -> %d. ", Vec_IntSize(p->vCubes), nEqual, nContain, nOutLits, nOutLits2 );
707 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
708}
709
722{
723 int i, k, iCube;
724 Vec_Wec_t * vOuts = Vec_WecStart( p->nOuts );
725 Vec_IntForEachEntry( p->vCubes, iCube, i )
726 if ( iCube != -1 )
727 {
728 word * pCube = Mop_ManCubeOut( p, iCube );
729 for ( k = 0; k < p->nOuts; k++ )
730 if ( Abc_TtGetBit( pCube, k ) )
731 Vec_WecPush( vOuts, k, iCube );
732 }
733 return vOuts;
734}
735Abc_Ntk_t * Mop_ManDerive( Mop_Man_t * p, char * pFileName )
736{
737 int i, k, c, iCube;
738 char Symb[4] = { '-', '0', '1', '?' }; // cube symbols
739 Vec_Str_t * vSop = Vec_StrAlloc( 1000 ); // storage for one SOP
740 Vec_Wec_t * vOuts = Mop_ManCubeCount( p ); // cube count for each output
742 pNtk->pName = Extra_UtilStrsav( pFileName );
743 pNtk->pSpec = Extra_UtilStrsav( pFileName );
744 for ( i = 0; i < p->nIns; i++ )
745 Abc_NtkCreatePi(pNtk);
746 for ( i = 0; i < p->nOuts; i++ )
747 {
748 Vec_Int_t * vThis = Vec_WecEntry( vOuts, i );
749 Abc_Obj_t * pPo = Abc_NtkCreatePo(pNtk);
750 Abc_Obj_t * pNode = Abc_NtkCreateNode(pNtk);
751 Abc_ObjAddFanin( pPo, pNode );
752 if ( Vec_IntSize(vThis) == 0 )
753 {
754 pNode->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 0\n" );
755 continue;
756 }
757 for ( k = 0; k < p->nIns; k++ )
758 Abc_ObjAddFanin( pNode, Abc_NtkPi(pNtk, k) );
759 Vec_StrClear( vSop );
760 Vec_IntForEachEntry( vThis, iCube, c )
761 {
762 word * pCube = Mop_ManCubeIn( p, iCube );
763 for ( k = 0; k < p->nIns; k++ )
764 Vec_StrPush( vSop, Symb[Abc_TtGetQua(pCube, k)] );
765 Vec_StrAppend( vSop, " 1\n" );
766 }
767 Vec_StrPush( vSop, '\0' );
768 pNode->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, Vec_StrArray(vSop) );
769 }
770 Vec_StrFree( vSop );
771 Vec_WecFree( vOuts );
774 return pNtk;
775}
776
788Abc_Ntk_t * Mop_ManTest( char * pFileName, int fMerge, int fVerbose )
789{
790 Abc_Ntk_t * pNtk = NULL;
791 Mop_Man_t * p = Mop_ManRead( pFileName );
792 if ( p == NULL )
793 return NULL;
794 Mop_ManRemoveEmpty( p );
795 //Mop_ManPrint( p );
796 if ( fMerge )
797 Mop_ManReduce2( p );
798 else
799 Mop_ManReduce( p );
800 //Mop_ManPrint( p );
801 pNtk = Mop_ManDerive( p, pFileName );
802 Mop_ManStop( p );
803 return pNtk;
804}
805
809
810
811
813
int nWords
Definition abcNpn.c:127
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:521
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL char * Abc_SopRegister(Mem_Flex_t *pMan, const char *pName)
DECLARATIONS ///.
Definition abcSop.c:62
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:495
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int nEqual
Definition abcCut.c:34
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
char * Extra_UtilStrsav(const char *s)
int Mop_ManRemoveIdentical(Mop_Man_t *p, Vec_Int_t *vGroup)
Vec_Int_t * Mop_ManCollectStats(Mop_Man_t *p)
void Mop_ManReduce2(Mop_Man_t *p)
void Mop_ManPrint(Mop_Man_t *p)
char * Mop_ManLoadFile(char *pFileName)
Definition ioReadPlaMo.c:97
int Mop_ManMergeDist1Pairs(Mop_Man_t *p, Vec_Int_t *vGroup, Vec_Int_t *vGroupPrev, Vec_Int_t *vStats, int nLimit)
Vec_Int_t * Mop_ManCompatiblePairs(Vec_Int_t *vPairs, int nObjs)
void Mop_ManStop(Mop_Man_t *p)
Definition ioReadPlaMo.c:77
int Mop_ManMergeDist1Pairs2(Mop_Man_t *p, Vec_Int_t *vGroup, Vec_Int_t *vGroupPrev)
int Mop_ManMergeContainAll(Mop_Man_t *p, Vec_Wec_t *vGroups)
Vec_Int_t * Mop_ManFindDist1Pairs(Mop_Man_t *p, Vec_Int_t *vGroup)
Vec_Wec_t * Mop_ManCubeCount(Mop_Man_t *p)
Mop_Man_t * Mop_ManAlloc(int nIns, int nOuts, int nCubes)
FUNCTION DEFINITIONS ///.
Definition ioReadPlaMo.c:64
void Mop_ManReduce(Mop_Man_t *p)
Abc_Ntk_t * Mop_ManTest(char *pFileName, int fMerge, int fVerbose)
Mop_Man_t * Mop_ManRead(char *pFileName)
void Mop_ManPrintOne(Mop_Man_t *p, int iCube)
Abc_Ntk_t * Mop_ManDerive(Mop_Man_t *p, char *pFileName)
int Mop_ManMergeContainTwo(Mop_Man_t *p, Vec_Int_t *vGroup, Vec_Int_t *vGroup2)
int Mop_ManReadParams(char *pBuffer, int *pnIns, int *pnOuts)
int Mop_ManMergeDist1All(Mop_Man_t *p, Vec_Wec_t *vGroups, Vec_Int_t *vStats, int nLimit)
typedefABC_NAMESPACE_IMPL_START struct Mop_Man_t_ Mop_Man_t
DECLARATIONS ///.
Definition ioReadPlaMo.c:30
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
char * pSpec
Definition abc.h:159
void * pData
Definition abc.h:145
Vec_Int_t * vCubes
Definition ioReadPlaMo.c:39
Vec_Wrd_t * vWordsOut
Definition ioReadPlaMo.c:38
Vec_Wrd_t * vWordsIn
Definition ioReadPlaMo.c:37
Vec_Int_t * vFree
Definition ioReadPlaMo.c:40
#define assert(ex)
Definition util_old.h:213
int memcmp()
char * strtok()
char * strstr()
char * strcpy()
VOID_HACK rewind()
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
#define Vec_WecForEachLevelReverse(vGlob, vVec, i)
Definition vecWec.h:65
#define Vec_WecForEachLevelStart(vGlob, vVec, i, LevelStart)
Definition vecWec.h:59
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
#define SEEK_END
Definition zconf.h:392