29#define SUPER_MASK(n) ((~((unsigned)0)) >> (32-n))
30#define SUPER_FULL (~((unsigned)0))
67#define Super2_IsComplement(p) (((int)((ABC_PTRUINT_T) (p) & 01)))
68#define Super2_Regular(p) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) & ~01))
69#define Super2_Not(p) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ 01))
70#define Super2_NotCond(p,c) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ (c)))
73#define Super2_LibForEachGate( Lib, Gate ) \
75 Lib->i < Lib->nGates && (Gate = Lib->pGates[Lib->i]); \
77#define Super2_LibForEachGate2( Lib, Gate2 ) \
79 Lib->k < Lib->i && (Gate2 = Lib->pGates[Lib->k]); \
94static char * Super2_LibWriteGate_rec(
Super2_Gate_t * pGate,
int fInv,
int Level );
95static int Super2_LibWriteCompare(
char * pStr1,
char * pStr2 );
123 pMan = Super2_ManStart();
126 pLibCur = Super2_LibFirst( pMan, nInputs );
129printf(
"Computing supergates for %d inputs and %d levels:\n", nInputs, nLevels );
130 for ( Level = 1; Level <= nLevels; Level++ )
133 pLibNext = Super2_LibCompute( pMan, pLibCur );
135 Super2_LibStop( pLibCur );
137printf(
"Level %d: Tried = %7d. Computed = %7d. ", Level, pMan->
nTried, pLibCur->
nGates );
138ABC_PRT(
"Runtime", Abc_Clock() - clk );
142printf(
"Writing the output file...\n" );
145 Super2_LibWrite( pLibCur );
146 Super2_LibStop( pLibCur );
149 Super2_ManStop( pMan );
227 pLibNew = Super2_LibStart();
294 pLib = Super2_LibStart();
298 pLib->
nMints = (1 << nInputs);
300 pLib->
nGates = nInputs + 1;
308 for ( v = 0; v < nInputs; v++ )
316 for ( m = 0; m < pLib->
nMints; m++ )
317 for ( v = 0; v < nInputs; v++ )
340 unsigned uTruth, uTruthR, uTruth1, uTruth2, uTruth1c, uTruth2c;
343 pLibNew = Super2_LibDup( pLib );
353 if (
stmm_lookup( pMan->
tTable, (
char *)(ABC_PTRUINT_T)uTruthR, (
char **)&pGate2 ) )
355 printf(
"New gate:\n" );
356 Super2_LibWriteGate( stdout, pLibNew, pGate1 );
357 printf(
"Gate in the table:\n" );
358 Super2_LibWriteGate( stdout, pLibNew, pGate2 );
361 stmm_insert( pMan->
tTable, (
char *)(ABC_PTRUINT_T)uTruthR, (
char *)(ABC_PTRUINT_T)pGate1 );
371 if ( pLib->
i && pLib->
i % 300 == 0 )
373 printf(
"Tried %5d first gates...\n", pLib->
i );
381 uTruth1c = Mask & ~uTruth1;
382 uTruth2c = Mask & ~uTruth2;
385 uTruth = uTruth1 & uTruth2;
386 uTruthR = ((uTruth & pLibNew->
uMaskBit)? Mask & ~uTruth : uTruth);
391 pGateNew->
pOne = pGate1;
392 pGateNew->
pTwo = pGate2;
393 pGateNew->
uTruth = uTruth;
395 Super2_LibAddGate( pLibNew, pGateNew );
399 uTruth = uTruth1c & uTruth2;
400 uTruthR = ((uTruth & pLibNew->
uMaskBit)? Mask & ~uTruth : uTruth);
406 pGateNew->
pTwo = pGate2;
407 pGateNew->
uTruth = uTruth;
409 Super2_LibAddGate( pLibNew, pGateNew );
413 uTruth = uTruth1 & uTruth2c;
414 uTruthR = ((uTruth & pLibNew->
uMaskBit)? Mask & ~uTruth : uTruth);
419 pGateNew->
pOne = pGate1;
421 pGateNew->
uTruth = uTruth;
423 Super2_LibAddGate( pLibNew, pGateNew );
427 uTruth = uTruth1c & uTruth2c;
428 uTruthR = ((uTruth & pLibNew->
uMaskBit)? Mask & ~uTruth : uTruth);
435 pGateNew->
uTruth = uTruth;
437 Super2_LibAddGate( pLibNew, pGateNew );
447static unsigned s_uMaskBit;
448static unsigned s_uMaskAll;
470 printf(
"Cannot write file for %d levels.\n", pLib->
nLevels );
479 (int (*)(
const void *,
const void *)) Super2_LibCompareGates );
481ABC_PRT(
"Sorting", Abc_Clock() - clk );
486 pFile = fopen( FileName,
"w" );
487 fprintf( pFile,
"# AND2/INV supergates derived on %s.\n",
Extra_TimeStamp() );
488 fprintf( pFile,
"# Command line: \"super2 -i %d -l %d\".\n", pLib->
nInputs, pLib->
nLevels );
489 fprintf( pFile,
"# The number of inputs = %6d.\n", pLib->
nInputs );
490 fprintf( pFile,
"# The number of levels = %6d.\n", pLib->
nLevels );
491 fprintf( pFile,
"# The number of supergates = %6d.\n", pLib->
nGates );
492 fprintf( pFile,
"# The total functions = %6d.\n", (1<<(pLib->
nMints-1)) );
493 fprintf( pFile,
"\n" );
494 fprintf( pFile,
"%6d\n", pLib->
nGates );
498 Super2_LibWriteGate( pFile, pLib, pGate );
501 printf(
"The supergates are written into file \"%s\" ", FileName );
502 printf(
"(%0.2f MB).\n", ((
double)
Extra_FileSize(FileName))/(1<<20) );
520 unsigned uTruth1, uTruth2;
522 uTruth1 = (pG1->
uTruth & s_uMaskBit)? s_uMaskAll & ~pG1->
uTruth : pG1->uTruth;
523 uTruth2 = (pG2->
uTruth & s_uMaskBit)? s_uMaskAll & ~pG2->
uTruth : pG2->uTruth;
525 if ( uTruth1 < uTruth2 )
549 uTruth = (fInv? ~pGate->uTruth : pGate->
uTruth);
559 fprintf( pFile,
" " );
561 fprintf( pFile,
"%s", Super2_LibWriteGate_rec( pGate, fInv, pLib->
nLevels ) );
562 fprintf( pFile,
"\n" );
577char * Super2_LibWriteGate_rec(
Super2_Gate_t * pGate,
int fInv,
int Level )
579 static char Buff01[ 3], Buff02[ 3];
580 static char Buff11[ 6], Buff12[ 6];
581 static char Buff21[ 12], Buff22[ 12];
582 static char Buff31[ 25], Buff32[ 25];
583 static char Buff41[ 50], Buff42[ 50];
584 static char Buff51[100], Buff52[100];
585 static char * pBuffs1[6] = { Buff01, Buff11, Buff21, Buff31, Buff41, Buff51 };
586 static char * pBuffs2[6] = { Buff02, Buff12, Buff22, Buff32, Buff42, Buff52 };
588 char * pBuffer1 = pBuffs1[Level];
589 char * pBuffer2 = pBuffs2[Level];
591 int fInvNext1, fInvNext2;
596 if ( pGate->
pOne == NULL )
600 pBuffer1[0] = (fInv?
'1':
'0');
606 pBuffer1[0] = (fInv?
'A' + ((int)(ABC_PTRUINT_T)pGate->
pTwo):
'a' + ((int)(ABC_PTRUINT_T)pGate->
pTwo));
617 pBranch = Super2_LibWriteGate_rec(pGateNext1, fInvNext1, Level - 1);
619 strcpy( pBuffer1, pBranch );
624 pBranch = Super2_LibWriteGate_rec(pGateNext2, fInvNext2, Level - 1);
627 if ( fInvNext1 ^ fInvNext2 )
629 if ( fInvNext1 > fInvNext2 )
630 sprintf( pBuffer2,
"%c%s%s%c", (fInv?
'<':
'('), pBuffer1, pBranch, (fInv?
'>':
')') );
632 sprintf( pBuffer2,
"%c%s%s%c", (fInv?
'<':
'('), pBranch, pBuffer1, (fInv?
'>':
')') );
637 RetValue = Super2_LibWriteCompare( pBuffer1, pBranch );
639 sprintf( pBuffer2,
"%c%s%s%c", (fInv?
'<':
'('), pBuffer1, pBranch, (fInv?
'>':
')') );
642 sprintf( pBuffer2,
"%c%s%s%c", (fInv?
'<':
'('), pBranch, pBuffer1, (fInv?
'>':
')') );
644 printf(
"Strange!\n" );
661int Super2_LibWriteCompare(
char * pStr1,
char * pStr2 )
666 while ( *pStr1 && *pStr1 <
'A' )
668 while ( *pStr2 && *pStr2 <
'A' )
672 if ( *pStr1 == 0 || *pStr2 == 0 )
680 if ( *pStr1 == *pStr2 )
687 if ( *pStr1 < *pStr2 )
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
int st__ptrhash(const char *, int)
int st__ptrcmp(const char *, const char *)
int stmm_insert(stmm_table *table, char *key, char *value)
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
void stmm_free_table(stmm_table *table)
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
int stmm_lookup(stmm_table *table, char *key, char **value)
#define Super2_IsComplement(p)
struct Super2_ManStruct_t_ Super2_Man_t
#define Super2_Regular(p)
struct Super2_GateStruct_t_ Super2_Gate_t
#define Super2_LibForEachGate2(Lib, Gate2)
#define SUPER_MASK(n)
DECLARATIONS ///.
void Super2_Precompute(int nInputs, int nLevels, int fVerbose)
FUNCTION DEFINITIONS ///.
struct Super2_LibStruct_t_ Super2_Lib_t
#define Super2_LibForEachGate(Lib, Gate)