abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
superAnd.c File Reference
#include "superInt.h"

Go to the source code of this file.

Data Structures

struct  Super2_ManStruct_t_
 
struct  Super2_LibStruct_t_
 
struct  Super2_GateStruct_t_
 

Macros

#define SUPER_MASK(n)   ((~((unsigned)0)) >> (32-n))
 DECLARATIONS ///. More...
 
#define SUPER_FULL   (~((unsigned)0))
 
#define Super2_IsComplement(p)   (((int)((ABC_PTRUINT_T) (p) & 01)))
 
#define Super2_Regular(p)   ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) & ~01))
 
#define Super2_Not(p)   ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ 01))
 
#define Super2_NotCond(p, c)   ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ (c)))
 
#define Super2_LibForEachGate(Lib, Gate)
 
#define Super2_LibForEachGate2(Lib, Gate2)
 

Typedefs

typedef struct Super2_ManStruct_t_ Super2_Man_t
 
typedef struct Super2_LibStruct_t_ Super2_Lib_t
 
typedef struct Super2_GateStruct_t_ Super2_Gate_t
 

Functions

static Super2_Man_tSuper2_ManStart ()
 
static void Super2_ManStop (Super2_Man_t *pMan)
 
static Super2_Lib_tSuper2_LibStart ()
 
static Super2_Lib_tSuper2_LibDup (Super2_Lib_t *pLib)
 
static void Super2_LibStop (Super2_Lib_t *pLib)
 
static void Super2_LibAddGate (Super2_Lib_t *pLib, Super2_Gate_t *pGate)
 
static Super2_Lib_tSuper2_LibFirst (Super2_Man_t *pMan, int nInputs)
 
static Super2_Lib_tSuper2_LibCompute (Super2_Man_t *pMan, Super2_Lib_t *pLib)
 
static void Super2_LibWrite (Super2_Lib_t *pLib)
 
static void Super2_LibWriteGate (FILE *pFile, Super2_Lib_t *pLib, Super2_Gate_t *pGate)
 
static char * Super2_LibWriteGate_rec (Super2_Gate_t *pGate, int fInv, int Level)
 
static int Super2_LibWriteCompare (char *pStr1, char *pStr2)
 
static int Super2_LibCompareGates (Super2_Gate_t **ppG1, Super2_Gate_t **ppG2)
 
void Super2_Precompute (int nInputs, int nLevels, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 

Variables

static unsigned s_uMaskBit
 
static unsigned s_uMaskAll
 

Macro Definition Documentation

#define Super2_IsComplement (   p)    (((int)((ABC_PTRUINT_T) (p) & 01)))

Definition at line 67 of file superAnd.c.

#define Super2_LibForEachGate (   Lib,
  Gate 
)
Value:
for ( Lib->i = 0; \
Lib->i < Lib->nGates && (Gate = Lib->pGates[Lib->i]); \
Lib->i++ )

Definition at line 73 of file superAnd.c.

#define Super2_LibForEachGate2 (   Lib,
  Gate2 
)
Value:
for ( Lib->k = 0; \
Lib->k < Lib->i && (Gate2 = Lib->pGates[Lib->k]); \
Lib->k++ )

Definition at line 77 of file superAnd.c.

#define Super2_Not (   p)    ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ 01))

Definition at line 69 of file superAnd.c.

#define Super2_NotCond (   p,
 
)    ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ (c)))

Definition at line 70 of file superAnd.c.

#define Super2_Regular (   p)    ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) & ~01))

Definition at line 68 of file superAnd.c.

#define SUPER_FULL   (~((unsigned)0))

Definition at line 30 of file superAnd.c.

#define SUPER_MASK (   n)    ((~((unsigned)0)) >> (32-n))

DECLARATIONS ///.

CFile****************************************************************

FileName [superAnd.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [Pre-computation of supergates.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - September 8, 2003.]

Revision [

Id:
superAnd.c,v 1.3 2004/06/28 14:20:25 alanmi Exp

]

Definition at line 29 of file superAnd.c.

Typedef Documentation

Definition at line 35 of file superAnd.c.

Definition at line 34 of file superAnd.c.

Definition at line 33 of file superAnd.c.

Function Documentation

void Super2_LibAddGate ( Super2_Lib_t pLib,
Super2_Gate_t pGate 
)
static

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

Synopsis [Add gate to the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file superAnd.c.

251 {
252  if ( pLib->nGates == pLib->nGatesAlloc )
253  {
254  pLib->pGates = ABC_REALLOC( Super2_Gate_t *, pLib->pGates, 3 * pLib->nGatesAlloc );
255  pLib->nGatesAlloc *= 3;
256  }
257  pLib->pGates[ pLib->nGates++ ] = pGate;
258 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
Super2_Gate_t ** pGates
Definition: superAnd.c:53
int Super2_LibCompareGates ( Super2_Gate_t **  ppG1,
Super2_Gate_t **  ppG2 
)
static

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

Synopsis [Writes the gate into the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 516 of file superAnd.c.

517 {
518  Super2_Gate_t * pG1 = *ppG1;
519  Super2_Gate_t * pG2 = *ppG2;
520  unsigned uTruth1, uTruth2;
521 
522  uTruth1 = (pG1->uTruth & s_uMaskBit)? s_uMaskAll & ~pG1->uTruth : pG1->uTruth;
523  uTruth2 = (pG2->uTruth & s_uMaskBit)? s_uMaskAll & ~pG2->uTruth : pG2->uTruth;
524 
525  if ( uTruth1 < uTruth2 )
526  return -1;
527  return 1;
528 }
static unsigned s_uMaskAll
Definition: superAnd.c:448
static unsigned s_uMaskBit
Definition: superAnd.c:447
Super2_Lib_t * Super2_LibCompute ( Super2_Man_t pMan,
Super2_Lib_t pLib 
)
static

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

Synopsis [Precomputes one level of supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 334 of file superAnd.c.

335 {
336  Super2_Lib_t * pLibNew;
337  Super2_Gate_t * pGate1, * pGate2, * pGateNew;
338  Super2_Gate_t ** ppGate;
339  unsigned Mask = SUPER_MASK(pLib->nMints);
340  unsigned uTruth, uTruthR, uTruth1, uTruth2, uTruth1c, uTruth2c;
341 
342  // start the new library
343  pLibNew = Super2_LibDup( pLib );
344 
345  // reset the hash table
346  stmm_free_table( pMan->tTable );
348  // set the starting things into the hash table
349  Super2_LibForEachGate( pLibNew, pGate1 )
350  {
351  uTruthR = ((pGate1->uTruth & pLibNew->uMaskBit)? Mask & ~pGate1->uTruth : pGate1->uTruth);
352 
353  if ( stmm_lookup( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char **)&pGate2 ) )
354  {
355  printf( "New gate:\n" );
356  Super2_LibWriteGate( stdout, pLibNew, pGate1 );
357  printf( "Gate in the table:\n" );
358  Super2_LibWriteGate( stdout, pLibNew, pGate2 );
359  assert( 0 );
360  }
361  stmm_insert( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char *)(ABC_PTRUINT_T)pGate1 );
362  }
363 
364 
365  // set the number of gates tried
366  pMan->nTried = pLibNew->nGates;
367 
368  // go through the gate pairs
369  Super2_LibForEachGate( pLib, pGate1 )
370  {
371  if ( pLib->i && pLib->i % 300 == 0 )
372  {
373  printf( "Tried %5d first gates...\n", pLib->i );
374  fflush( stdout );
375  }
376 
377  Super2_LibForEachGate2( pLib, pGate2 )
378  {
379  uTruth1 = pGate1->uTruth;
380  uTruth2 = pGate2->uTruth;
381  uTruth1c = Mask & ~uTruth1;
382  uTruth2c = Mask & ~uTruth2;
383 
384  // none complemented
385  uTruth = uTruth1 & uTruth2;
386  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
387 
388  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
389  {
390  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
391  pGateNew->pOne = pGate1;
392  pGateNew->pTwo = pGate2;
393  pGateNew->uTruth = uTruth;
394  *ppGate = pGateNew;
395  Super2_LibAddGate( pLibNew, pGateNew );
396  }
397 
398  // one complemented
399  uTruth = uTruth1c & uTruth2;
400  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
401 
402  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
403  {
404  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
405  pGateNew->pOne = Super2_Not(pGate1);
406  pGateNew->pTwo = pGate2;
407  pGateNew->uTruth = uTruth;
408  *ppGate = pGateNew;
409  Super2_LibAddGate( pLibNew, pGateNew );
410  }
411 
412  // another complemented
413  uTruth = uTruth1 & uTruth2c;
414  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
415 
416  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
417  {
418  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
419  pGateNew->pOne = pGate1;
420  pGateNew->pTwo = Super2_Not(pGate2);
421  pGateNew->uTruth = uTruth;
422  *ppGate = pGateNew;
423  Super2_LibAddGate( pLibNew, pGateNew );
424  }
425 
426  // both complemented
427  uTruth = uTruth1c & uTruth2c;
428  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
429 
430  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
431  {
432  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
433  pGateNew->pOne = Super2_Not(pGate1);
434  pGateNew->pTwo = Super2_Not(pGate2);
435  pGateNew->uTruth = uTruth;
436  *ppGate = pGateNew;
437  Super2_LibAddGate( pLibNew, pGateNew );
438  }
439 
440  pMan->nTried += 4;
441  }
442  }
443  return pLibNew;
444 }
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
#define SUPER_MASK(n)
DECLARATIONS ///.
Definition: superAnd.c:29
int stmm_insert(stmm_table *table, char *key, char *value)
Definition: stmm.c:200
#define Super2_LibForEachGate2(Lib, Gate2)
Definition: superAnd.c:77
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static Super2_Lib_t * Super2_LibDup(Super2_Lib_t *pLib)
Definition: superAnd.c:224
unsigned uMaskBit
Definition: superAnd.c:54
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMem
Definition: superAnd.c:39
static void Super2_LibWriteGate(FILE *pFile, Super2_Lib_t *pLib, Super2_Gate_t *pGate)
Definition: superAnd.c:541
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition: stmm.c:134
static void Super2_LibAddGate(Super2_Lib_t *pLib, Super2_Gate_t *pGate)
Definition: superAnd.c:250
#define Super2_Not(p)
Definition: superAnd.c:69
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition: stmm.c:266
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
#define Super2_LibForEachGate(Lib, Gate)
Definition: superAnd.c:73
Super2_Gate_t * pTwo
Definition: superAnd.c:61
#define assert(ex)
Definition: util_old.h:213
stmm_table * tTable
Definition: superAnd.c:40
Super2_Gate_t * pOne
Definition: superAnd.c:60
int st__ptrhash(const char *, int)
Definition: st.c:468
Super2_Lib_t * Super2_LibDup ( Super2_Lib_t pLib)
static

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

Synopsis [Duplicates the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 224 of file superAnd.c.

225 {
226  Super2_Lib_t * pLibNew;
227  pLibNew = Super2_LibStart();
228  pLibNew->nInputs = pLib->nInputs;
229  pLibNew->nMints = pLib->nMints;
230  pLibNew->nLevels = pLib->nLevels;
231  pLibNew->nGates = pLib->nGates;
232  pLibNew->uMaskBit = pLib->uMaskBit;
233  pLibNew->nGatesAlloc = 1000 + pLib->nGatesAlloc;
234  pLibNew->pGates = ABC_ALLOC( Super2_Gate_t *, pLibNew->nGatesAlloc );
235  memcpy( pLibNew->pGates, pLib->pGates, pLibNew->nGates * sizeof(Super2_Gate_t *) );
236  return pLibNew;
237 }
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned uMaskBit
Definition: superAnd.c:54
static Super2_Lib_t * Super2_LibStart()
Definition: superAnd.c:205
Super2_Gate_t ** pGates
Definition: superAnd.c:53
Super2_Lib_t * Super2_LibFirst ( Super2_Man_t pMan,
int  nInputs 
)
static

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

Synopsis [Derives the starting supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 288 of file superAnd.c.

289 {
290  Super2_Lib_t * pLib;
291  int v, m;
292 
293  // start the library
294  pLib = Super2_LibStart();
295 
296  // create the starting supergates
297  pLib->nInputs = nInputs;
298  pLib->nMints = (1 << nInputs);
299  pLib->nLevels = 0;
300  pLib->nGates = nInputs + 1;
301  pLib->nGatesAlloc = nInputs + 1;
302  pLib->uMaskBit = (1 << (pLib->nMints-1));
303  pLib->pGates = ABC_ALLOC( Super2_Gate_t *, nInputs + 1 );
304  // add the constant 0
305  pLib->pGates[0] = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
306  memset( pLib->pGates[0], 0, sizeof(Super2_Gate_t) );
307  // add the elementary gates
308  for ( v = 0; v < nInputs; v++ )
309  {
310  pLib->pGates[v+1] = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
311  memset( pLib->pGates[v+1], 0, sizeof(Super2_Gate_t) );
312  pLib->pGates[v+1]->pTwo = (Super2_Gate_t *)(ABC_PTRUINT_T)v;
313  }
314 
315  // set up their truth tables
316  for ( m = 0; m < pLib->nMints; m++ )
317  for ( v = 0; v < nInputs; v++ )
318  if ( m & (1 << v) )
319  pLib->pGates[v+1]->uTruth |= (1 << m);
320  return pLib;
321 }
char * memset()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned uMaskBit
Definition: superAnd.c:54
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMem
Definition: superAnd.c:39
Super2_Gate_t * pTwo
Definition: superAnd.c:61
static Super2_Lib_t * Super2_LibStart()
Definition: superAnd.c:205
Super2_Gate_t ** pGates
Definition: superAnd.c:53
Super2_Lib_t * Super2_LibStart ( )
static

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

Synopsis [Starts the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file superAnd.c.

206 {
207  Super2_Lib_t * pLib;
208  pLib = ABC_ALLOC( Super2_Lib_t, 1 );
209  memset( pLib, 0, sizeof(Super2_Lib_t) );
210  return pLib;
211 }
char * memset()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Super2_LibStop ( Super2_Lib_t pLib)
static

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

Synopsis [Stops the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 271 of file superAnd.c.

272 {
273  ABC_FREE( pLib->pGates );
274  ABC_FREE( pLib );
275 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
Super2_Gate_t ** pGates
Definition: superAnd.c:53
void Super2_LibWrite ( Super2_Lib_t pLib)
static

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

Synopsis [Writes the library into the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 461 of file superAnd.c.

462 {
463  Super2_Gate_t * pGate;
464  FILE * pFile;
465  char FileName[100];
466  abctime clk;
467 
468  if ( pLib->nLevels > 5 )
469  {
470  printf( "Cannot write file for %d levels.\n", pLib->nLevels );
471  return;
472  }
473 
474 clk = Abc_Clock();
475  // sort the supergates by truth table
476  s_uMaskBit = pLib->uMaskBit;
477  s_uMaskAll = SUPER_MASK(pLib->nMints);
478  qsort( (void *)pLib->pGates, pLib->nGates, sizeof(Super2_Gate_t *),
479  (int (*)(const void *, const void *)) Super2_LibCompareGates );
480  assert( Super2_LibCompareGates( pLib->pGates, pLib->pGates + pLib->nGates - 1 ) < 0 );
481 ABC_PRT( "Sorting", Abc_Clock() - clk );
482 
483 
484  // start the file
485  sprintf( FileName, "superI%dL%d", pLib->nInputs, pLib->nLevels );
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 );
495 
496  // print the gates
497  Super2_LibForEachGate( pLib, pGate )
498  Super2_LibWriteGate( pFile, pLib, pGate );
499  fclose( pFile );
500 
501  printf( "The supergates are written into file \"%s\" ", FileName );
502  printf( "(%0.2f MB).\n", ((double)Extra_FileSize(FileName))/(1<<20) );
503 }
static unsigned s_uMaskAll
Definition: superAnd.c:448
#define SUPER_MASK(n)
DECLARATIONS ///.
Definition: superAnd.c:29
static unsigned s_uMaskBit
Definition: superAnd.c:447
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned uMaskBit
Definition: superAnd.c:54
static void Super2_LibWriteGate(FILE *pFile, Super2_Lib_t *pLib, Super2_Gate_t *pGate)
Definition: superAnd.c:541
int Extra_FileSize(char *pFileName)
static int Super2_LibCompareGates(Super2_Gate_t **ppG1, Super2_Gate_t **ppG2)
Definition: superAnd.c:516
char * sprintf()
#define Super2_LibForEachGate(Lib, Gate)
Definition: superAnd.c:73
#define ABC_PRT(a, t)
Definition: abc_global.h:220
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
Super2_Gate_t ** pGates
Definition: superAnd.c:53
int Super2_LibWriteCompare ( char *  pStr1,
char *  pStr2 
)
static

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

Synopsis [Compares the two branches of the tree.]

Description []

SideEffects []

SeeAlso []

Definition at line 661 of file superAnd.c.

662 {
663  while ( 1 )
664  {
665  // skip extra symbols
666  while ( *pStr1 && *pStr1 < 'A' )
667  pStr1++;
668  while ( *pStr2 && *pStr2 < 'A' )
669  pStr2++;
670 
671  // check if any one is finished
672  if ( *pStr1 == 0 || *pStr2 == 0 )
673  {
674  if ( *pStr2 )
675  return 1;
676  return -1;
677  }
678 
679  // compare
680  if ( *pStr1 == *pStr2 )
681  {
682  pStr1++;
683  pStr2++;
684  }
685  else
686  {
687  if ( *pStr1 < *pStr2 )
688  return 1;
689  return -1;
690  }
691  }
692  return 0;
693 }
void Super2_LibWriteGate ( FILE *  pFile,
Super2_Lib_t pLib,
Super2_Gate_t pGate 
)
static

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

Synopsis [Writes the gate into the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 541 of file superAnd.c.

542 {
543 // unsigned uTruthR;
544  unsigned uTruth;
545  int fInv;
546 
547  // check whether the gate need complementation
548  fInv = (int)(pGate->uTruth & pLib->uMaskBit);
549  uTruth = (fInv? ~pGate->uTruth : pGate->uTruth);
550 /*
551  // reverse the truth table
552  uTruthR = 0;
553  for ( m = 0; m < pLib->nMints; m++ )
554  if ( uTruth & (1 << m) )
555  uTruthR |= (1 << (pLib->nMints-1-m));
556 */
557  // write the truth table
558  Extra_PrintBinary( pFile, &uTruth, pLib->nMints );
559  fprintf( pFile, " " );
560  // write the symbolic expression
561  fprintf( pFile, "%s", Super2_LibWriteGate_rec( pGate, fInv, pLib->nLevels ) );
562  fprintf( pFile, "\n" );
563 }
unsigned uMaskBit
Definition: superAnd.c:54
static char * Super2_LibWriteGate_rec(Super2_Gate_t *pGate, int fInv, int Level)
Definition: superAnd.c:577
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
char * Super2_LibWriteGate_rec ( Super2_Gate_t pGate,
int  fInv,
int  Level 
)
static

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

Synopsis [Recursively writes the gate into the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 577 of file superAnd.c.

578 {
579  static char Buff01[ 3], Buff02[ 3]; // Max0 = 1
580  static char Buff11[ 6], Buff12[ 6]; // Max1 = 2*Max0 + 2 = 4
581  static char Buff21[ 12], Buff22[ 12]; // Max2 = 2*Max1 + 2 = 10
582  static char Buff31[ 25], Buff32[ 25]; // Max3 = 2*Max2 + 2 = 22
583  static char Buff41[ 50], Buff42[ 50]; // Max4 = 2*Max3 + 2 = 46
584  static char Buff51[100], Buff52[100]; // Max5 = 2*Max4 + 2 = 94
585  static char * pBuffs1[6] = { Buff01, Buff11, Buff21, Buff31, Buff41, Buff51 };
586  static char * pBuffs2[6] = { Buff02, Buff12, Buff22, Buff32, Buff42, Buff52 };
587  char * pBranch;
588  char * pBuffer1 = pBuffs1[Level];
589  char * pBuffer2 = pBuffs2[Level];
590  Super2_Gate_t * pGateNext1, * pGateNext2;
591  int fInvNext1, fInvNext2;
592  int RetValue;
593 
594  // consider the last level
595  assert( Level >= 0 );
596  if ( pGate->pOne == NULL )
597  {
598  if ( pGate->uTruth == 0 )
599  {
600  pBuffer1[0] = (fInv? '1': '0');
601  pBuffer1[1] = '$';
602  pBuffer1[2] = 0;
603  }
604  else
605  {
606  pBuffer1[0] = (fInv? 'A' + ((int)(ABC_PTRUINT_T)pGate->pTwo): 'a' + ((int)(ABC_PTRUINT_T)pGate->pTwo));
607  pBuffer1[1] = 0;
608  }
609  return pBuffer1;
610  }
611  assert( Level > 0 );
612 
613 
614  // get the left branch
615  pGateNext1 = Super2_Regular(pGate->pOne);
616  fInvNext1 = Super2_IsComplement(pGate->pOne);
617  pBranch = Super2_LibWriteGate_rec(pGateNext1, fInvNext1, Level - 1);
618  // copy into Buffer1
619  strcpy( pBuffer1, pBranch );
620 
621  // get the right branch
622  pGateNext2 = Super2_Regular(pGate->pTwo);
623  fInvNext2 = Super2_IsComplement(pGate->pTwo);
624  pBranch = Super2_LibWriteGate_rec(pGateNext2, fInvNext2, Level - 1);
625 
626  // consider the case when comparison is not necessary
627  if ( fInvNext1 ^ fInvNext2 )
628  {
629  if ( fInvNext1 > fInvNext2 )
630  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBuffer1, pBranch, (fInv? '>': ')') );
631  else
632  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBranch, pBuffer1, (fInv? '>': ')') );
633  }
634  else
635  {
636  // compare the two branches
637  RetValue = Super2_LibWriteCompare( pBuffer1, pBranch );
638  if ( RetValue == 1 )
639  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBuffer1, pBranch, (fInv? '>': ')') );
640  else // if ( RetValue == -1 )
641  {
642  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBranch, pBuffer1, (fInv? '>': ')') );
643  if ( RetValue == 0 )
644  printf( "Strange!\n" );
645  }
646  }
647  return pBuffer2;
648 }
static char * Super2_LibWriteGate_rec(Super2_Gate_t *pGate, int fInv, int Level)
Definition: superAnd.c:577
if(last==0)
Definition: sparse_int.h:34
char * sprintf()
char * strcpy()
#define Super2_IsComplement(p)
Definition: superAnd.c:67
#define assert(ex)
Definition: util_old.h:213
#define Super2_Regular(p)
Definition: superAnd.c:68
static int Super2_LibWriteCompare(char *pStr1, char *pStr2)
Definition: superAnd.c:661
Super2_Gate_t * pOne
Definition: superAnd.c:60
Super2_Man_t * Super2_ManStart ( )
static

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

Synopsis [Starts the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 166 of file superAnd.c.

167 {
168  Super2_Man_t * pMan;
169  pMan = ABC_ALLOC( Super2_Man_t, 1 );
170  memset( pMan, 0, sizeof(Super2_Man_t) );
171  pMan->pMem = Extra_MmFixedStart( sizeof(Super2_Gate_t) );
173  return pMan;
174 }
char * memset()
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Extra_MmFixed_t * pMem
Definition: superAnd.c:39
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
stmm_table * tTable
Definition: superAnd.c:40
int st__ptrhash(const char *, int)
Definition: st.c:468
void Super2_ManStop ( Super2_Man_t pMan)
static

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

Synopsis [Stops the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 187 of file superAnd.c.

188 {
189  Extra_MmFixedStop( pMan->pMem );
190  stmm_free_table( pMan->tTable );
191  ABC_FREE( pMan );
192 }
void Extra_MmFixedStop(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMem
Definition: superAnd.c:39
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
#define ABC_FREE(obj)
Definition: abc_global.h:232
stmm_table * tTable
Definition: superAnd.c:40
void Super2_Precompute ( int  nInputs,
int  nLevels,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

INCLUDES ///.

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

Synopsis [Precomputes the library of AND2 gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 113 of file superAnd.c.

114 {
115  Super2_Man_t * pMan;
116  Super2_Lib_t * pLibCur, * pLibNext;
117  int Level;
118  abctime clk;
119 
120  assert( nInputs < 6 );
121 
122  // start the manager
123  pMan = Super2_ManStart();
124 
125  // get the starting supergates
126  pLibCur = Super2_LibFirst( pMan, nInputs );
127 
128  // perform the computation of supergates
129 printf( "Computing supergates for %d inputs and %d levels:\n", nInputs, nLevels );
130  for ( Level = 1; Level <= nLevels; Level++ )
131  {
132 clk = Abc_Clock();
133  pLibNext = Super2_LibCompute( pMan, pLibCur );
134  pLibNext->nLevels = Level;
135  Super2_LibStop( pLibCur );
136  pLibCur = pLibNext;
137 printf( "Level %d: Tried = %7d. Computed = %7d. ", Level, pMan->nTried, pLibCur->nGates );
138 ABC_PRT( "Runtime", Abc_Clock() - clk );
139 fflush( stdout );
140  }
141 
142 printf( "Writing the output file...\n" );
143 fflush( stdout );
144  // write them into a file
145  Super2_LibWrite( pLibCur );
146  Super2_LibStop( pLibCur );
147 
148  // stop the manager
149  Super2_ManStop( pMan );
150 }
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Super2_LibWrite(Super2_Lib_t *pLib)
Definition: superAnd.c:461
static Super2_Lib_t * Super2_LibCompute(Super2_Man_t *pMan, Super2_Lib_t *pLib)
Definition: superAnd.c:334
static Super2_Man_t * Super2_ManStart()
Definition: superAnd.c:166
static void Super2_LibStop(Super2_Lib_t *pLib)
Definition: superAnd.c:271
static Super2_Lib_t * Super2_LibFirst(Super2_Man_t *pMan, int nInputs)
Definition: superAnd.c:288
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static void Super2_ManStop(Super2_Man_t *pMan)
Definition: superAnd.c:187
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278

Variable Documentation

unsigned s_uMaskAll
static

Definition at line 448 of file superAnd.c.

unsigned s_uMaskBit
static

Definition at line 447 of file superAnd.c.