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

Go to the source code of this file.

Functions

static int Extra_TruthCanonN_rec (int nVars, unsigned char *pt, unsigned **pptRes, char **ppfRes, int Flag)
 
int Extra_TruthCanonFastN (int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
 
void Map_Var3Print ()
 
void Map_Var3Test ()
 
void Map_Var4Test ()
 

Variables

static
ABC_NAMESPACE_IMPL_START
unsigned 
s_Truths3 [256]
 
static char s_Phases3 [256][9]
 

Function Documentation

int Extra_TruthCanonFastN ( int  nVarsMax,
int  nVarsReal,
unsigned *  pt,
unsigned **  pptRes,
char **  ppfRes 
)

AutomaticEnd Function********************************************************************

Synopsis [Computes the N-canonical form of the Boolean function up to 6 inputs.]

Description [The N-canonical form is defined as the truth table with the minimum integer value. This function exhaustively enumerates through the complete set of 2^N phase assignments. Returns pointers to the static storage to the truth table and phases. This data should be used before the function is called again.]

SideEffects []

SeeAlso []

Definition at line 374 of file extraUtilCanon.c.

375 {
376  static unsigned uTruthStore6[2];
377  int RetValue;
378  assert( nVarsMax <= 6 );
379  assert( nVarsReal <= nVarsMax );
380  RetValue = Extra_TruthCanonN_rec( nVarsReal <= 3? 3: nVarsReal, (unsigned char *)pt, pptRes, ppfRes, 0 );
381  if ( nVarsMax == 6 && nVarsReal < nVarsMax )
382  {
383  uTruthStore6[0] = **pptRes;
384  uTruthStore6[1] = **pptRes;
385  *pptRes = uTruthStore6;
386  }
387  return RetValue;
388 }
static int Extra_TruthCanonN_rec(int nVars, unsigned char *pt, unsigned **pptRes, char **ppfRes, int Flag)
#define assert(ex)
Definition: util_old.h:213
int Extra_TruthCanonN_rec ( int  nVars,
unsigned char *  pt,
unsigned **  pptRes,
char **  ppfRes,
int  Flag 
)
static

AutomaticStart

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

Synopsis [Recursive implementation of the above.]

Description []

SideEffects [This procedure has a bug, which shows on Solaris. Most likely has something to do with the casts, i.g *((unsigned *)pt0)]

SeeAlso []

Definition at line 406 of file extraUtilCanon.c.

407 {
408  static unsigned uTruthStore[7][2][2];
409  static char uPhaseStore[7][2][64];
410 
411  unsigned char * pt0, * pt1;
412  unsigned * ptRes0, * ptRes1, * ptRes;
413  unsigned uInit0, uInit1, uTruth0, uTruth1, uTemp;
414  char * pfRes0, * pfRes1, * pfRes;
415  int nf0, nf1, nfRes, i, nVarsN;
416 
417  // table lookup for three vars
418  if ( nVars == 3 )
419  {
420  *pptRes = &s_Truths3[*pt];
421  *ppfRes = s_Phases3[*pt]+1;
422  return s_Phases3[*pt][0];
423  }
424 
425  // number of vars for the next call
426  nVarsN = nVars-1;
427  // truth table for the next call
428  pt0 = pt;
429  pt1 = pt + (1 << nVarsN) / 8;
430  // 5-var truth tables for this call
431 // uInit0 = *((unsigned *)pt0);
432 // uInit1 = *((unsigned *)pt1);
433  if ( nVarsN == 3 )
434  {
435  uInit0 = (pt0[0] << 24) | (pt0[0] << 16) | (pt0[0] << 8) | pt0[0];
436  uInit1 = (pt1[0] << 24) | (pt1[0] << 16) | (pt1[0] << 8) | pt1[0];
437  }
438  else if ( nVarsN == 4 )
439  {
440  uInit0 = (pt0[1] << 24) | (pt0[0] << 16) | (pt0[1] << 8) | pt0[0];
441  uInit1 = (pt1[1] << 24) | (pt1[0] << 16) | (pt1[1] << 8) | pt1[0];
442  }
443  else
444  {
445  uInit0 = (pt0[3] << 24) | (pt0[2] << 16) | (pt0[1] << 8) | pt0[0];
446  uInit1 = (pt1[3] << 24) | (pt1[2] << 16) | (pt1[1] << 8) | pt1[0];
447  }
448 
449  // storage for truth tables and phases
450  ptRes = uTruthStore[nVars][Flag];
451  pfRes = uPhaseStore[nVars][Flag];
452 
453  // solve trivial cases
454  if ( uInit1 == 0 )
455  {
456  nf0 = Extra_TruthCanonN_rec( nVarsN, pt0, &ptRes0, &pfRes0, 0 );
457  uTruth1 = uInit1;
458  uTruth0 = *ptRes0;
459  nfRes = 0;
460  for ( i = 0; i < nf0; i++ )
461  pfRes[nfRes++] = pfRes0[i];
462  goto finish;
463  }
464  if ( uInit0 == 0 )
465  {
466  nf1 = Extra_TruthCanonN_rec( nVarsN, pt1, &ptRes1, &pfRes1, 1 );
467  uTruth1 = uInit0;
468  uTruth0 = *ptRes1;
469  nfRes = 0;
470  for ( i = 0; i < nf1; i++ )
471  pfRes[nfRes++] = pfRes1[i] | (1<<nVarsN);
472  goto finish;
473  }
474 
475  if ( uInit1 == 0xFFFFFFFF )
476  {
477  nf0 = Extra_TruthCanonN_rec( nVarsN, pt0, &ptRes0, &pfRes0, 0 );
478  uTruth1 = *ptRes0;
479  uTruth0 = uInit1;
480  nfRes = 0;
481  for ( i = 0; i < nf0; i++ )
482  pfRes[nfRes++] = pfRes0[i] | (1<<nVarsN);
483  goto finish;
484  }
485  if ( uInit0 == 0xFFFFFFFF )
486  {
487  nf1 = Extra_TruthCanonN_rec( nVarsN, pt1, &ptRes1, &pfRes1, 1 );
488  uTruth1 = *ptRes1;
489  uTruth0 = uInit0;
490  nfRes = 0;
491  for ( i = 0; i < nf1; i++ )
492  pfRes[nfRes++] = pfRes1[i];
493  goto finish;
494  }
495 
496  // solve the problem for cofactors
497  nf0 = Extra_TruthCanonN_rec( nVarsN, pt0, &ptRes0, &pfRes0, 0 );
498  nf1 = Extra_TruthCanonN_rec( nVarsN, pt1, &ptRes1, &pfRes1, 1 );
499 
500  // combine the result
501  if ( *ptRes1 < *ptRes0 )
502  {
503  uTruth0 = 0xFFFFFFFF;
504  nfRes = 0;
505  for ( i = 0; i < nf1; i++ )
506  {
507  uTemp = Extra_TruthPolarize( uInit0, pfRes1[i], nVarsN );
508  if ( uTruth0 > uTemp )
509  {
510  nfRes = 0;
511  uTruth0 = uTemp;
512  pfRes[nfRes++] = pfRes1[i];
513  }
514  else if ( uTruth0 == uTemp )
515  pfRes[nfRes++] = pfRes1[i];
516  }
517  uTruth1 = *ptRes1;
518  }
519  else if ( *ptRes1 > *ptRes0 )
520  {
521  uTruth0 = 0xFFFFFFFF;
522  nfRes = 0;
523  for ( i = 0; i < nf0; i++ )
524  {
525  uTemp = Extra_TruthPolarize( uInit1, pfRes0[i], nVarsN );
526  if ( uTruth0 > uTemp )
527  {
528  nfRes = 0;
529  uTruth0 = uTemp;
530  pfRes[nfRes++] = pfRes0[i] | (1<<nVarsN);
531  }
532  else if ( uTruth0 == uTemp )
533  pfRes[nfRes++] = pfRes0[i] | (1<<nVarsN);
534  }
535  uTruth1 = *ptRes0;
536  }
537  else
538  {
539  assert( nf0 == nf1 );
540  nfRes = 0;
541  for ( i = 0; i < nf1; i++ )
542  pfRes[nfRes++] = pfRes1[i];
543  for ( i = 0; i < nf0; i++ )
544  pfRes[nfRes++] = pfRes0[i] | (1<<nVarsN);
545  uTruth0 = Extra_TruthPolarize( uInit0, pfRes1[0], nVarsN );
546  uTruth1 = *ptRes0;
547  }
548 
549 finish :
550  if ( nVarsN == 3 )
551  {
552  uTruth0 &= 0xFF;
553  uTruth1 &= 0xFF;
554  uTemp = (uTruth1 << 8) | uTruth0;
555  *ptRes = (uTemp << 16) | uTemp;
556  }
557  else if ( nVarsN == 4 )
558  {
559  uTruth0 &= 0xFFFF;
560  uTruth1 &= 0xFFFF;
561  *ptRes = (uTruth1 << 16) | uTruth0;
562  }
563  else if ( nVarsN == 5 )
564  {
565  *(ptRes+0) = uTruth0;
566  *(ptRes+1) = uTruth1;
567  }
568 
569  *pptRes = ptRes;
570  *ppfRes = pfRes;
571  return nfRes;
572 }
static int Extra_TruthCanonN_rec(int nVars, unsigned char *pt, unsigned **pptRes, char **ppfRes, int Flag)
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
static ABC_NAMESPACE_IMPL_START unsigned s_Truths3[256]
static char s_Phases3[256][9]
#define assert(ex)
Definition: util_old.h:213
void Map_Var3Print ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 585 of file extraUtilCanon.c.

586 {
587  extern void Extra_Truth3VarN( unsigned ** puCanons, char *** puPhases, char ** ppCounters );
588 
589  unsigned * uCanons;
590  char ** uPhases;
591  char * pCounters;
592  int i, k;
593 
594  Extra_Truth3VarN( &uCanons, &uPhases, &pCounters );
595 
596  for ( i = 0; i < 256; i++ )
597  {
598  if ( i % 8 == 0 )
599  printf( "\n" );
600  Extra_PrintHex( stdout, uCanons + i, 5 );
601  printf( ", " );
602  }
603  printf( "\n" );
604 
605  for ( i = 0; i < 256; i++ )
606  {
607  printf( "%3d */ { %2d, ", i, pCounters[i] );
608  for ( k = 0; k < pCounters[i]; k++ )
609  printf( "%s%d", k? ", ":"", uPhases[i][k] );
610  printf( " }\n" );
611  }
612  printf( "\n" );
613 }
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
void Extra_Truth3VarN(unsigned **puCanons, char ***puPhases, char **ppCounters)
void Map_Var3Test ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 626 of file extraUtilCanon.c.

627 {
628  extern void Extra_Truth3VarN( unsigned ** puCanons, char *** puPhases, char ** ppCounters );
629 
630  unsigned * uCanons;
631  char ** uPhases;
632  char * pCounters;
633  int i;
634  unsigned * ptRes;
635  char * pfRes;
636  unsigned uTruth;
637  int Count;
638 
639  Extra_Truth3VarN( &uCanons, &uPhases, &pCounters );
640 
641  for ( i = 0; i < 256; i++ )
642  {
643  uTruth = i;
644  Count = Extra_TruthCanonFastN( 5, 3, &uTruth, &ptRes, &pfRes );
645  }
646 }
int Extra_TruthCanonFastN(int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
void Extra_Truth3VarN(unsigned **puCanons, char ***puPhases, char **ppCounters)
void Map_Var4Test ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 659 of file extraUtilCanon.c.

660 {
661  extern void Extra_Truth4VarN( unsigned short ** puCanons, char *** puPhases, char ** ppCounters, int PhaseMax );
662 
663  unsigned short * uCanons;
664  char ** uPhases;
665  char * pCounters;
666  int i;
667  unsigned * ptRes;
668  char * pfRes;
669  unsigned uTruth;
670  int Count;
671 
672  Extra_Truth4VarN( &uCanons, &uPhases, &pCounters, 16 );
673 
674  for ( i = 0; i < 256*256; i++ )
675  {
676  uTruth = i;
677  Count = Extra_TruthCanonFastN( 5, 4, &uTruth, &ptRes, &pfRes );
678  }
679 }
int Extra_TruthCanonFastN(int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
void Extra_Truth4VarN(unsigned short **puCanons, char ***puPhases, char **ppCounters, int nPhasesMax)

Variable Documentation

char s_Phases3[256][9]
static

Definition at line 79 of file extraUtilCanon.c.

ABC_NAMESPACE_IMPL_START unsigned s_Truths3[256]
static

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

FileName [extraUtilMisc.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Computing canonical forms of Boolean functions using truth tables.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
extraUtilMisc.c,v 1.0 2003/09/01 00:00:00 alanmi Exp

]

Definition at line 43 of file extraUtilCanon.c.