abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dauMerge.c File Reference
#include "dauInt.h"
#include "misc/util/utilTruth.h"

Go to the source code of this file.

Data Structures

struct  Dau_Sto_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Dau_Sto_t_ 
Dau_Sto_t
 DECLARATIONS ///. More...
 

Functions

static void Dau_DsdMergeStoreClean (Dau_Sto_t *pS, int nShared)
 
static void Dau_DsdMergeStoreCleanOutput (Dau_Sto_t *pS)
 
static void Dau_DsdMergeStoreAddToOutput (Dau_Sto_t *pS, char *pBeg, char *pEnd)
 
static void Dau_DsdMergeStoreAddToOutputChar (Dau_Sto_t *pS, char c)
 
static int Dau_DsdMergeStoreStartDef (Dau_Sto_t *pS, char c)
 
static void Dau_DsdMergeStoreAddToDef (Dau_Sto_t *pS, int New, char *pBeg, char *pEnd)
 
static void Dau_DsdMergeStoreAddToDefChar (Dau_Sto_t *pS, int New, char c)
 
static void Dau_DsdMergeStoreStopDef (Dau_Sto_t *pS, int New, char c)
 
static char Dau_DsdMergeStoreCreateDef (Dau_Sto_t *pS, char *pBeg, char *pEnd)
 
static void Dau_DsdMergeStorePrintDefs (Dau_Sto_t *pS)
 
static void Dau_DsdMergeCopy (char *pDsd, int fCompl, char *pRes)
 
static void Dau_DsdMergeReplace (char *pDsd, int *pMatches, int *pMap)
 
static void Dau_DsdMergeMatches (char *pDsd, int *pMatches)
 
static void Dau_DsdMergeVarPres (char *pDsd, int *pMatches, int *pPres, int Mask)
 
static int Dau_DsdMergeCountShared (int *pPres, int Mask)
 
static int Dau_DsdMergeFindShared (char *pDsd0, char *pDsd1, int *pMatches0, int *pMatches1, int *pVarPres)
 
static int Dau_DsdMergeCreateMaps (int *pVarPres, int nShared, int *pOld2New, int *pNew2Old)
 
static void Dau_DsdMergeInlineDefinitions (char *pDsd, int *pMatches, Dau_Sto_t *pS, char *pRes, int nShared)
 
static void Dau_DsdMergePrintWithStatus (char *p, int *pStatus)
 
int Dau_DsdMergeStatus_rec (char *pStr, char **p, int *pMatches, int nShared, int *pStatus)
 
static int Dau_DsdMergeStatus (char *pDsd, int *pMatches, int nShared, int *pStatus)
 
static int Dau_DsdMergeGetStatus (char *pBeg, char *pStr, int *pMatches, int *pStatus)
 
void Dau_DsdMergeSubstitute_rec (Dau_Sto_t *pS, char *pStr, char **p, int *pMatches, int *pStatus, int fWrite)
 
static void Dau_DsdMergeSubstitute (Dau_Sto_t *pS, char *pDsd, int *pMatches, int *pStatus)
 
void Dau_DsdRemoveBraces_rec (char *pStr, char **p, int *pMatches)
 
void Dau_DsdRemoveBraces (char *pDsd, int *pMatches)
 
char * Dau_DsdMerge (char *pDsd0i, int *pPerm0, char *pDsd1i, int *pPerm1, int fCompl0, int fCompl1, int nVars)
 DECLARATIONS ///. More...
 
void Dau_DsdTest66 ()
 

Variables

abctime s_TimeComp [4] = {0}
 

Typedef Documentation

typedef typedefABC_NAMESPACE_IMPL_START struct Dau_Sto_t_ Dau_Sto_t

DECLARATIONS ///.

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

FileName [dauMerge.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware unmapping.]

Synopsis [Enumeration of decompositions.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
dauMerge.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Substitution storage.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file dauMerge.c.

Function Documentation

char* Dau_DsdMerge ( char *  pDsd0i,
int *  pPerm0,
char *  pDsd1i,
int *  pPerm1,
int  fCompl0,
int  fCompl1,
int  nVars 
)

DECLARATIONS ///.

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

Synopsis [Performs merging of two DSD formulas.]

Description []

SideEffects []

SeeAlso []

Definition at line 587 of file dauMerge.c.

588 {
589  int fVerbose = 0;
590  int fCheck = 0;
591  static int Counter = 0;
592  static char pRes[DAU_MAX_STR];
593  char pDsd0[DAU_MAX_STR];
594  char pDsd1[DAU_MAX_STR];
595  int pMatches0[DAU_MAX_STR];
596  int pMatches1[DAU_MAX_STR];
597  int pVarPres[DAU_MAX_VAR];
598  int pOld2New[DAU_MAX_VAR];
599  int pNew2Old[DAU_MAX_VAR];
600  int pStatus0[DAU_MAX_STR];
601  int pStatus1[DAU_MAX_STR];
602  int pMatches[DAU_MAX_STR];
603  int nVarsShared, nVarsTotal;
604  Dau_Sto_t S, * pS = &S;
605  word * pTruth, * pt = NULL, * pt0 = NULL, * pt1 = NULL;
606  word pParts[3][DAU_MAX_WORD];
607  int Status;
608  abctime clk = Abc_Clock();
609  Counter++;
610  // create local copies
611  Dau_DsdMergeCopy( pDsd0i, fCompl0, pDsd0 );
612  Dau_DsdMergeCopy( pDsd1i, fCompl1, pDsd1 );
613 if ( fVerbose )
614 printf( "\nAfter copying:\n" );
615 if ( fVerbose )
616 printf( "%s\n", pDsd0 );
617 if ( fVerbose )
618 printf( "%s\n", pDsd1 );
619  // handle constants
620  if ( Dau_DsdIsConst(pDsd0) || Dau_DsdIsConst(pDsd1) )
621  {
622  if ( Dau_DsdIsConst0(pDsd0) )
623  strcpy( pRes, pDsd0 );
624  else if ( Dau_DsdIsConst1(pDsd0) )
625  strcpy( pRes, pDsd1 );
626  else if ( Dau_DsdIsConst0(pDsd1) )
627  strcpy( pRes, pDsd1 );
628  else if ( Dau_DsdIsConst1(pDsd1) )
629  strcpy( pRes, pDsd0 );
630  else assert( 0 );
631  return pRes;
632  }
633 
634  // compute matches
635  Dau_DsdMergeMatches( pDsd0, pMatches0 );
636  Dau_DsdMergeMatches( pDsd1, pMatches1 );
637  // implement permutation
638  Dau_DsdMergeReplace( pDsd0, pMatches0, pPerm0 );
639  Dau_DsdMergeReplace( pDsd1, pMatches1, pPerm1 );
640 if ( fVerbose )
641 printf( "After replacement:\n" );
642 if ( fVerbose )
643 printf( "%s\n", pDsd0 );
644 if ( fVerbose )
645 printf( "%s\n", pDsd1 );
646 
647 
648  if ( fCheck )
649  {
650  pt0 = Dau_DsdToTruth( pDsd0, nVars );
651  Abc_TtCopy( pParts[0], pt0, Abc_TtWordNum(nVars), 0 );
652  }
653  if ( fCheck )
654  {
655  pt1 = Dau_DsdToTruth( pDsd1, nVars );
656  Abc_TtCopy( pParts[1], pt1, Abc_TtWordNum(nVars), 0 );
657  Abc_TtAnd( pParts[2], pParts[0], pParts[1], Abc_TtWordNum(nVars), 0 );
658  }
659 
660  // find shared varaiables
661  nVarsShared = Dau_DsdMergeFindShared(pDsd0, pDsd1, pMatches0, pMatches1, pVarPres);
662  if ( nVarsShared == 0 )
663  {
664  sprintf( pRes, "(%s%s)", pDsd0, pDsd1 );
665 if ( fVerbose )
666 printf( "Disjoint:\n" );
667 if ( fVerbose )
668 printf( "%s\n", pRes );
669 
670  Dau_DsdMergeMatches( pRes, pMatches );
671  Dau_DsdRemoveBraces( pRes, pMatches );
672  Dau_DsdNormalize( pRes );
673 if ( fVerbose )
674 printf( "Normalized:\n" );
675 if ( fVerbose )
676 printf( "%s\n", pRes );
677 
678  s_TimeComp[0] += Abc_Clock() - clk;
679  return pRes;
680  }
681 s_TimeComp[3] += Abc_Clock() - clk;
682  // create variable mapping
683  nVarsTotal = Dau_DsdMergeCreateMaps( pVarPres, nVarsShared, pOld2New, pNew2Old );
684  // perform variable replacement
685  Dau_DsdMergeReplace( pDsd0, pMatches0, pOld2New );
686  Dau_DsdMergeReplace( pDsd1, pMatches1, pOld2New );
687  // find uniqueness status
688  Dau_DsdMergeStatus( pDsd0, pMatches0, nVarsShared, pStatus0 );
689  Dau_DsdMergeStatus( pDsd1, pMatches1, nVarsShared, pStatus1 );
690 if ( fVerbose )
691 printf( "Individual status:\n" );
692 if ( fVerbose )
693 Dau_DsdMergePrintWithStatus( pDsd0, pStatus0 );
694 if ( fVerbose )
695 Dau_DsdMergePrintWithStatus( pDsd1, pStatus1 );
696  // prepare storage
697  Dau_DsdMergeStoreClean( pS, nVarsShared );
698  // perform substitutions
700  Dau_DsdMergeSubstitute( pS, pDsd0, pMatches0, pStatus0 );
701  strcpy( pDsd0, pS->pOutput );
702 if ( fVerbose )
703 printf( "Substitutions:\n" );
704 if ( fVerbose )
705 printf( "%s\n", pDsd0 );
706 
707  // perform substitutions
709  Dau_DsdMergeSubstitute( pS, pDsd1, pMatches1, pStatus1 );
710  strcpy( pDsd1, pS->pOutput );
711 if ( fVerbose )
712 printf( "%s\n", pDsd1 );
713 if ( fVerbose )
715 
716  // create new function
717 // assert( nVarsTotal <= 6 );
718  sprintf( pS->pOutput, "(%s%s)", pDsd0, pDsd1 );
719  pTruth = Dau_DsdToTruth( pS->pOutput, nVarsTotal );
720  Status = Dau_DsdDecompose( pTruth, nVarsTotal, 0, 1, pS->pOutput );
721 //printf( "%d ", Status );
722  if ( Status == -1 ) // did not find 1-step DSD
723  return NULL;
724 // if ( Status > 6 ) // non-DSD part is too large
725 // return NULL;
726  if ( Dau_DsdIsConst(pS->pOutput) )
727  {
728  strcpy( pRes, pS->pOutput );
729  return pRes;
730  }
731 if ( fVerbose )
732 printf( "Decomposition:\n" );
733 if ( fVerbose )
734 printf( "%s\n", pS->pOutput );
735  // substitute definitions
736  Dau_DsdMergeMatches( pS->pOutput, pMatches );
737  Dau_DsdMergeInlineDefinitions( pS->pOutput, pMatches, pS, pRes, nVarsShared );
738 if ( fVerbose )
739 printf( "Inlining:\n" );
740 if ( fVerbose )
741 printf( "%s\n", pRes );
742  // perform variable replacement
743  Dau_DsdMergeMatches( pRes, pMatches );
744  Dau_DsdMergeReplace( pRes, pMatches, pNew2Old );
745  Dau_DsdRemoveBraces( pRes, pMatches );
746 if ( fVerbose )
747 printf( "Replaced:\n" );
748 if ( fVerbose )
749 printf( "%s\n", pRes );
750  Dau_DsdNormalize( pRes );
751 if ( fVerbose )
752 printf( "Normalized:\n" );
753 if ( fVerbose )
754 printf( "%s\n", pRes );
755 
756  if ( fCheck )
757  {
758  pt = Dau_DsdToTruth( pRes, nVars );
759  if ( !Abc_TtEqual( pParts[2], pt, Abc_TtWordNum(nVars) ) )
760  printf( "Dau_DsdMerge(): Verification failed!\n" );
761  }
762 
763  if ( Status == 0 )
764  s_TimeComp[1] += Abc_Clock() - clk;
765  else
766  s_TimeComp[2] += Abc_Clock() - clk;
767  return pRes;
768 }
static int Dau_DsdMergeFindShared(char *pDsd0, char *pDsd1, int *pMatches0, int *pMatches1, int *pVarPres)
Definition: dauMerge.c:204
static void Dau_DsdMergeStoreClean(Dau_Sto_t *pS, int nShared)
Definition: dauMerge.c:57
void Dau_DsdRemoveBraces(char *pDsd, int *pMatches)
Definition: dauMerge.c:554
static void Dau_DsdMergeSubstitute(Dau_Sto_t *pS, char *pDsd, int *pMatches, int *pStatus)
Definition: dauMerge.c:494
static void Dau_DsdMergePrintWithStatus(char *p, int *pStatus)
Definition: dauMerge.c:276
typedefABC_NAMESPACE_IMPL_START struct Dau_Sto_t_ Dau_Sto_t
DECLARATIONS ///.
Definition: dauMerge.c:47
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
Definition: dauDsd.c:1912
word * Dau_DsdToTruth(char *p, int nVars)
Definition: dauDsd.c:609
static void Dau_DsdMergeStorePrintDefs(Dau_Sto_t *pS)
Definition: dauMerge.c:107
static int Dau_DsdIsConst(char *p)
MACRO DEFINITIONS ///.
Definition: dau.h:67
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Dau_DsdMergeInlineDefinitions(char *pDsd, int *pMatches, Dau_Sto_t *pS, char *pRes, int nShared)
Definition: dauMerge.c:232
static void Dau_DsdMergeStoreCleanOutput(Dau_Sto_t *pS)
Definition: dauMerge.c:65
static int Dau_DsdMergeCreateMaps(int *pVarPres, int nShared, int *pOld2New, int *pNew2Old)
Definition: dauMerge.c:211
#define DAU_MAX_STR
Definition: dau.h:43
static void Abc_TtCopy(word *pOut, word *pIn, int nWords, int fCompl)
Definition: utilTruth.h:221
void Dau_DsdNormalize(char *p)
Definition: dauDsd.c:260
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static void Dau_DsdMergeReplace(char *pDsd, int *pMatches, int *pMap)
Definition: dauMerge.c:147
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
char * sprintf()
static int Counter
char * strcpy()
#define DAU_MAX_WORD
Definition: dau.h:44
static int Dau_DsdIsConst1(char *p)
Definition: dau.h:69
static int Abc_TtWordNum(int nVars)
Definition: utilTruth.h:169
static void Dau_DsdMergeMatches(char *pDsd, int *pMatches)
Definition: dauMerge.c:163
static int Abc_TtEqual(word *pIn1, word *pIn2, int nWords)
Definition: utilTruth.h:269
static void Dau_DsdMergeCopy(char *pDsd, int fCompl, char *pRes)
Definition: dauMerge.c:126
abctime s_TimeComp[4]
Definition: dauMerge.c:574
#define assert(ex)
Definition: util_old.h:213
static int Dau_DsdMergeStatus(char *pDsd, int *pMatches, int nShared, int *pStatus)
Definition: dauMerge.c:346
static int Dau_DsdIsConst0(char *p)
Definition: dau.h:68
static void Abc_TtAnd(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
Definition: utilTruth.h:231
ABC_INT64_T abctime
Definition: abc_global.h:278
static shot S[256]
Definition: kitPerm.c:40
static void Dau_DsdMergeCopy ( char *  pDsd,
int  fCompl,
char *  pRes 
)
inlinestatic

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

Synopsis [Creates local copy.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file dauMerge.c.

127 {
128  if ( fCompl && pDsd[0] == '!' )
129  fCompl = 0, pDsd++;
130  if ( Dau_DsdIsConst(pDsd) ) // constant
131  pRes[0] = (fCompl ? (char)((int)pDsd[0] ^ 1) : pDsd[0]), pRes[1] = 0;
132  else
133  sprintf( pRes, "%s%s", fCompl ? "!" : "", pDsd );
134 }
static int Dau_DsdIsConst(char *p)
MACRO DEFINITIONS ///.
Definition: dau.h:67
else
Definition: sparse_int.h:55
char * sprintf()
static int Dau_DsdMergeCountShared ( int *  pPres,
int  Mask 
)
inlinestatic

Definition at line 197 of file dauMerge.c.

198 {
199  int i, Counter = 0;
200  for ( i = 0; i < DAU_MAX_VAR; i++ )
201  Counter += (pPres[i] == Mask);
202  return Counter;
203 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static int Counter
static int Dau_DsdMergeCreateMaps ( int *  pVarPres,
int  nShared,
int *  pOld2New,
int *  pNew2Old 
)
inlinestatic

Definition at line 211 of file dauMerge.c.

212 {
213  int i, Counter = 0, Counter2 = nShared;
214  for ( i = 0; i < DAU_MAX_VAR; i++ )
215  {
216  if ( pVarPres[i] == 0 )
217  continue;
218  if ( pVarPres[i] == 3 )
219  {
220  pOld2New[i] = Counter;
221  pNew2Old[Counter] = i;
222  Counter++;
223  continue;
224  }
225  assert( pVarPres[i] == 1 || pVarPres[i] == 2 );
226  pOld2New[i] = Counter2;
227  pNew2Old[Counter2] = i;
228  Counter2++;
229  }
230  return Counter2;
231 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static int Counter
#define assert(ex)
Definition: util_old.h:213
static int Dau_DsdMergeFindShared ( char *  pDsd0,
char *  pDsd1,
int *  pMatches0,
int *  pMatches1,
int *  pVarPres 
)
inlinestatic

Definition at line 204 of file dauMerge.c.

205 {
206  memset( pVarPres, 0, sizeof(int)*DAU_MAX_VAR );
207  Dau_DsdMergeVarPres( pDsd0, pMatches0, pVarPres, 1 );
208  Dau_DsdMergeVarPres( pDsd1, pMatches1, pVarPres, 2 );
209  return Dau_DsdMergeCountShared( pVarPres, 3 );
210 }
char * memset()
static int Dau_DsdMergeCountShared(int *pPres, int Mask)
Definition: dauMerge.c:197
static void Dau_DsdMergeVarPres(char *pDsd, int *pMatches, int *pPres, int Mask)
Definition: dauMerge.c:178
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static int Dau_DsdMergeGetStatus ( char *  pBeg,
char *  pStr,
int *  pMatches,
int *  pStatus 
)
inlinestatic

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

Synopsis [Extracts the formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 362 of file dauMerge.c.

363 {
364  if ( *pBeg == '!' )
365  pBeg++;
366  while ( (*pBeg >= 'A' && *pBeg <= 'F') || (*pBeg >= '0' && *pBeg <= '9') )
367  pBeg++;
368  if ( *pBeg == '<' )
369  {
370  char * q = pStr + pMatches[pBeg - pStr];
371  if ( *(q+1) == '{' )
372  pBeg = q+1;
373  }
374  return pStatus[pBeg - pStr];
375 }
static void Dau_DsdMergeInlineDefinitions ( char *  pDsd,
int *  pMatches,
Dau_Sto_t pS,
char *  pRes,
int  nShared 
)
inlinestatic

Definition at line 232 of file dauMerge.c.

233 {
234  int i;
235  char * pDef;
236  char * pBegin = pRes;
237  for ( i = 0; pDsd[i]; i++ )
238  {
239  // skip non-DSD block
240  if ( pDsd[i] == '<' && pDsd[pMatches[i]+1] == '{' )
241  {
242  assert( pDsd[pMatches[i]] == '>' );
243  for ( ; i <= pMatches[i]; i++ )
244  *pRes++ = pDsd[i];
245  }
246  if ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
247  while ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
248  *pRes++ = pDsd[i++];
249  // detect variables
250  if ( !(pDsd[i] >= 'a' && pDsd[i] <= 'z') || (pDsd[i] - 'a' < nShared) )
251  {
252  *pRes++ = pDsd[i];
253  continue;
254  }
255  // inline definition
256  assert( pDsd[i]-'a' < DAU_MAX_STR );
257  for ( pDef = pS->pStore[pDsd[i]-'a']; *pDef; pDef++ )
258  *pRes++ = *pDef;
259  }
260  *pRes++ = 0;
261  assert( pRes - pBegin < DAU_MAX_STR );
262 }
#define DAU_MAX_STR
Definition: dau.h:43
#define assert(ex)
Definition: util_old.h:213
static void Dau_DsdMergeMatches ( char *  pDsd,
int *  pMatches 
)
inlinestatic

Definition at line 163 of file dauMerge.c.

164 {
165  int pNested[DAU_MAX_VAR];
166  int i, nNested = 0;
167  for ( i = 0; pDsd[i]; i++ )
168  {
169  pMatches[i] = 0;
170  if ( pDsd[i] == '(' || pDsd[i] == '[' || pDsd[i] == '<' || pDsd[i] == '{' )
171  pNested[nNested++] = i;
172  else if ( pDsd[i] == ')' || pDsd[i] == ']' || pDsd[i] == '>' || pDsd[i] == '}' )
173  pMatches[pNested[--nNested]] = i;
174  assert( nNested < DAU_MAX_VAR );
175  }
176  assert( nNested == 0 );
177 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
#define assert(ex)
Definition: util_old.h:213
static void Dau_DsdMergePrintWithStatus ( char *  p,
int *  pStatus 
)
inlinestatic

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

Synopsis [Computes independence status for each opening paranthesis.]

Description []

SideEffects []

SeeAlso []

Definition at line 276 of file dauMerge.c.

277 {
278  int i;
279  printf( "%s\n", p );
280  for ( i = 0; p[i]; i++ )
281  if ( !(p[i] == '(' || p[i] == '[' || p[i] == '<' || p[i] == '{' || (p[i] >= 'a' && p[i] <= 'z')) )
282  printf( " " );
283  else if ( pStatus[i] >= 0 )
284  printf( "%d", pStatus[i] );
285  else
286  printf( "-" );
287  printf( "\n" );
288 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Dau_DsdMergeReplace ( char *  pDsd,
int *  pMatches,
int *  pMap 
)
inlinestatic

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

Synopsis [Replaces variables according to the mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 147 of file dauMerge.c.

148 {
149  int i;
150  for ( i = 0; pDsd[i]; i++ )
151  {
152  // skip non-DSD block
153  if ( pDsd[i] == '<' && pDsd[pMatches[i]+1] == '{' )
154  i = pMatches[i] + 1;
155  if ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
156  while ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
157  i++;
158  // detect variables
159  if ( pDsd[i] >= 'a' && pDsd[i] <= 'z' )
160  pDsd[i] = 'a' + pMap[ pDsd[i] - 'a' ];
161  }
162 }
static int Dau_DsdMergeStatus ( char *  pDsd,
int *  pMatches,
int  nShared,
int *  pStatus 
)
inlinestatic

Definition at line 346 of file dauMerge.c.

347 {
348  return Dau_DsdMergeStatus_rec( pDsd, &pDsd, pMatches, nShared, pStatus );
349 }
int Dau_DsdMergeStatus_rec(char *pStr, char **p, int *pMatches, int nShared, int *pStatus)
Definition: dauMerge.c:289
int Dau_DsdMergeStatus_rec ( char *  pStr,
char **  p,
int *  pMatches,
int  nShared,
int *  pStatus 
)

Definition at line 289 of file dauMerge.c.

290 {
291  // none pure
292  // 1 one pure
293  // 2 two or more pure
294  // 3 all pure
295  if ( **p == '!' )
296  {
297  pStatus[*p - pStr] = -1;
298  (*p)++;
299  }
300  while ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
301  {
302  pStatus[*p - pStr] = -1;
303  (*p)++;
304  }
305  if ( **p == '<' )
306  {
307  char * q = pStr + pMatches[ *p - pStr ];
308  if ( *(q+1) == '{' )
309  {
310  char * pTemp = *p;
311  *p = q+1;
312  for ( ; pTemp < q+1; pTemp++ )
313  pStatus[pTemp - pStr] = -1;
314  }
315  }
316  if ( **p >= 'a' && **p <= 'z' ) // var
317  return pStatus[*p - pStr] = (**p - 'a' < nShared) ? 0 : 3;
318  if ( **p == '(' || **p == '[' || **p == '<' || **p == '{' ) // and/or/xor
319  {
320  int Status, nPure = 0, nTotal = 0;
321  char * pOld = *p;
322  char * q = pStr + pMatches[ *p - pStr ];
323  assert( *q == **p + 1 + (**p != '(') );
324  for ( (*p)++; *p < q; (*p)++ )
325  {
326  Status = Dau_DsdMergeStatus_rec( pStr, p, pMatches, nShared, pStatus );
327  nPure += (Status == 3);
328  nTotal++;
329  }
330  assert( *p == q );
331  assert( nTotal > 1 );
332  if ( nPure == 0 )
333  Status = 0;
334  else if ( nPure == 1 )
335  Status = 1;
336  else if ( nPure < nTotal )
337  Status = 2;
338  else if ( nPure == nTotal )
339  Status = 3;
340  else assert( 0 );
341  return (pStatus[pOld - pStr] = Status);
342  }
343  assert( 0 );
344  return 0;
345 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Dau_DsdMergeStatus_rec(char *pStr, char **p, int *pMatches, int nShared, int *pStatus)
Definition: dauMerge.c:289
#define assert(ex)
Definition: util_old.h:213
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
static void Dau_DsdMergeStoreAddToDef ( Dau_Sto_t pS,
int  New,
char *  pBeg,
char *  pEnd 
)
inlinestatic

Definition at line 85 of file dauMerge.c.

86 {
87  while ( pBeg < pEnd )
88  *pS->pPosStore[New]++ = *pBeg++;
89 }
static void Dau_DsdMergeStoreAddToDefChar ( Dau_Sto_t pS,
int  New,
char  c 
)
inlinestatic

Definition at line 90 of file dauMerge.c.

91 {
92  *pS->pPosStore[New]++ = c;
93 }
static void Dau_DsdMergeStoreAddToOutput ( Dau_Sto_t pS,
char *  pBeg,
char *  pEnd 
)
inlinestatic

Definition at line 69 of file dauMerge.c.

70 {
71  while ( pBeg < pEnd )
72  *pS->pPosOutput++ = *pBeg++;
73 }
static void Dau_DsdMergeStoreAddToOutputChar ( Dau_Sto_t pS,
char  c 
)
inlinestatic

Definition at line 74 of file dauMerge.c.

75 {
76  *pS->pPosOutput++ = c;
77 }
static void Dau_DsdMergeStoreClean ( Dau_Sto_t pS,
int  nShared 
)
inlinestatic

Definition at line 57 of file dauMerge.c.

58 {
59  int i;
60  pS->iVarUsed = nShared;
61  for ( i = 0; i < DAU_MAX_VAR; i++ )
62  pS->pStore[i][0] = 0;
63 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static void Dau_DsdMergeStoreCleanOutput ( Dau_Sto_t pS)
inlinestatic

Definition at line 65 of file dauMerge.c.

66 {
67  pS->pPosOutput = pS->pOutput;
68 }
static char Dau_DsdMergeStoreCreateDef ( Dau_Sto_t pS,
char *  pBeg,
char *  pEnd 
)
inlinestatic

Definition at line 100 of file dauMerge.c.

101 {
102  int New = Dau_DsdMergeStoreStartDef( pS, 0 );
103  Dau_DsdMergeStoreAddToDef( pS, New, pBeg, pEnd );
104  Dau_DsdMergeStoreStopDef( pS, New, 0 );
105  return New;
106 }
static void Dau_DsdMergeStoreAddToDef(Dau_Sto_t *pS, int New, char *pBeg, char *pEnd)
Definition: dauMerge.c:85
static int Dau_DsdMergeStoreStartDef(Dau_Sto_t *pS, char c)
Definition: dauMerge.c:79
static void Dau_DsdMergeStoreStopDef(Dau_Sto_t *pS, int New, char c)
Definition: dauMerge.c:94
static void Dau_DsdMergeStorePrintDefs ( Dau_Sto_t pS)
inlinestatic

Definition at line 107 of file dauMerge.c.

108 {
109  int i;
110  for ( i = 0; i < DAU_MAX_VAR; i++ )
111  if ( pS->pStore[i][0] )
112  printf( "%c = %s\n", 'a' + i, pS->pStore[i] );
113 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
static int Dau_DsdMergeStoreStartDef ( Dau_Sto_t pS,
char  c 
)
inlinestatic

Definition at line 79 of file dauMerge.c.

80 {
81  pS->pPosStore[pS->iVarUsed] = pS->pStore[pS->iVarUsed];
82  if (c) *pS->pPosStore[pS->iVarUsed]++ = c;
83  return pS->iVarUsed++;
84 }
static void Dau_DsdMergeStoreStopDef ( Dau_Sto_t pS,
int  New,
char  c 
)
inlinestatic

Definition at line 94 of file dauMerge.c.

95 {
96  if (c) *pS->pPosStore[New]++ = c;
97  *pS->pPosStore[New]++ = 0;
98 }
static void Dau_DsdMergeSubstitute ( Dau_Sto_t pS,
char *  pDsd,
int *  pMatches,
int *  pStatus 
)
inlinestatic

Definition at line 494 of file dauMerge.c.

495 {
496 /*
497  int fCompl = 0;
498  if ( pDsd[0] == '!' )
499  {
500  Dau_DsdMergeStoreAddToOutputChar( pS, '!' );
501  pDsd++;
502  fCompl = 1;
503  }
504 */
505  Dau_DsdMergeSubstitute_rec( pS, pDsd, &pDsd, pMatches, pStatus, 1 );
507 }
void Dau_DsdMergeSubstitute_rec(Dau_Sto_t *pS, char *pStr, char **p, int *pMatches, int *pStatus, int fWrite)
Definition: dauMerge.c:376
static void Dau_DsdMergeStoreAddToOutputChar(Dau_Sto_t *pS, char c)
Definition: dauMerge.c:74
void Dau_DsdMergeSubstitute_rec ( Dau_Sto_t pS,
char *  pStr,
char **  p,
int *  pMatches,
int *  pStatus,
int  fWrite 
)

Definition at line 376 of file dauMerge.c.

377 {
378 // assert( **p != '!' );
379 
380  if ( **p == '!' )
381  {
382  if ( fWrite )
384  (*p)++;
385  }
386 
387  while ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
388  {
389  if ( fWrite )
391  (*p)++;
392  }
393  if ( **p == '<' )
394  {
395  char * q = pStr + pMatches[ *p - pStr ];
396  if ( *(q+1) == '{' )
397  {
398  char * pTemp = *p;
399  *p = q+1;
400  if ( fWrite )
401  for ( ; pTemp < q+1; pTemp++ )
402  Dau_DsdMergeStoreAddToOutputChar( pS, *pTemp );
403  }
404  }
405  if ( **p >= 'a' && **p <= 'z' ) // var
406  {
407  if ( fWrite )
409  return;
410  }
411  if ( **p == '(' || **p == '[' || **p == '<' || **p == '{' ) // and/or/xor
412  {
413  int New, StatusFan, Status = pStatus[*p - pStr];
414  char * pBeg, * q = pStr + pMatches[ *p - pStr ];
415  assert( *q == **p + 1 + (**p != '(') );
416  if ( !fWrite )
417  {
418  assert( Status == 3 );
419  *p = q;
420  return;
421  }
422  assert( Status != 3 );
423  if ( Status == 0 ) // none pure
424  {
426  for ( (*p)++; *p < q; (*p)++ )
427  {
428  if ( **p == '!' )
429  {
431  (*p)++;
432  }
433  Dau_DsdMergeSubstitute_rec( pS, pStr, p, pMatches, pStatus, 1 );
434  }
436  assert( *p == q );
437  return;
438  }
439  if ( Status == 1 || **p == '<' || **p == '{' ) // 1 pure
440  {
442  for ( (*p)++; *p < q; (*p)++ )
443  {
444  if ( **p == '!' )
445  {
447  (*p)++;
448  }
449  pBeg = *p;
450  StatusFan = Dau_DsdMergeGetStatus( pBeg, pStr, pMatches, pStatus );
451  Dau_DsdMergeSubstitute_rec( pS, pStr, p, pMatches, pStatus, StatusFan != 3 );
452  if ( StatusFan == 3 )
453  {
454  int New = Dau_DsdMergeStoreCreateDef( pS, pBeg, *p+1 );
455  Dau_DsdMergeStoreAddToOutputChar( pS, (char)('a' + New) );
456  }
457  }
459  assert( *p == q );
460  return;
461  }
462  if ( Status == 2 )
463  {
464  // add more than one defs
466  New = Dau_DsdMergeStoreStartDef( pS, **p );
467  for ( (*p)++; *p < q; (*p)++ )
468  {
469  pBeg = *p;
470  StatusFan = Dau_DsdMergeGetStatus( pBeg, pStr, pMatches, pStatus );
471  if ( **p == '!' )
472  {
473  if ( StatusFan != 3 )
475  else
476  Dau_DsdMergeStoreAddToDefChar( pS, New, '!' );
477  (*p)++;
478  pBeg++;
479  }
480  Dau_DsdMergeSubstitute_rec( pS, pStr, p, pMatches, pStatus, StatusFan != 3 );
481  if ( StatusFan == 3 )
482  Dau_DsdMergeStoreAddToDef( pS, New, pBeg, *p+1 );
483  }
484  Dau_DsdMergeStoreStopDef( pS, New, *q );
485  Dau_DsdMergeStoreAddToOutputChar( pS, (char)('a' + New) );
487  return;
488  }
489  assert( 0 );
490  return;
491  }
492  assert( 0 );
493 }
void Dau_DsdMergeSubstitute_rec(Dau_Sto_t *pS, char *pStr, char **p, int *pMatches, int *pStatus, int fWrite)
Definition: dauMerge.c:376
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Dau_DsdMergeStoreAddToDef(Dau_Sto_t *pS, int New, char *pBeg, char *pEnd)
Definition: dauMerge.c:85
static int Dau_DsdMergeGetStatus(char *pBeg, char *pStr, int *pMatches, int *pStatus)
Definition: dauMerge.c:362
static int Dau_DsdMergeStoreStartDef(Dau_Sto_t *pS, char c)
Definition: dauMerge.c:79
#define assert(ex)
Definition: util_old.h:213
static void Dau_DsdMergeStoreStopDef(Dau_Sto_t *pS, int New, char c)
Definition: dauMerge.c:94
static void Dau_DsdMergeStoreAddToDefChar(Dau_Sto_t *pS, int New, char c)
Definition: dauMerge.c:90
static void Dau_DsdMergeStoreAddToOutputChar(Dau_Sto_t *pS, char c)
Definition: dauMerge.c:74
static char Dau_DsdMergeStoreCreateDef(Dau_Sto_t *pS, char *pBeg, char *pEnd)
Definition: dauMerge.c:100
static void Dau_DsdMergeVarPres ( char *  pDsd,
int *  pMatches,
int *  pPres,
int  Mask 
)
inlinestatic

Definition at line 178 of file dauMerge.c.

179 {
180  int i;
181  for ( i = 0; pDsd[i]; i++ )
182  {
183  // skip non-DSD block
184  if ( pDsd[i] == '<' && pDsd[pMatches[i]+1] == '{' )
185  i = pMatches[i] + 1;
186  if ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
187  while ( (pDsd[i] >= 'A' && pDsd[i] <= 'F') || (pDsd[i] >= '0' && pDsd[i] <= '9') )
188  i++;
189  // skip non-variables
190  if ( !(pDsd[i] >= 'a' && pDsd[i] <= 'z') )
191  continue;
192  // record the mask
193  assert( pDsd[i]-'a' < DAU_MAX_VAR );
194  pPres[pDsd[i]-'a'] |= Mask;
195  }
196 }
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
#define assert(ex)
Definition: util_old.h:213
void Dau_DsdRemoveBraces ( char *  pDsd,
int *  pMatches 
)

Definition at line 554 of file dauMerge.c.

555 {
556  char * q, * p = pDsd;
557  if ( pDsd[1] == 0 )
558  return;
559  Dau_DsdRemoveBraces_rec( pDsd, &pDsd, pMatches );
560  for ( q = p; *p; p++ )
561  if ( *p != ' ' )
562  {
563  if ( *p == '!' && *(q-1) == '!' && p != q )
564  {
565  q--;
566  continue;
567  }
568  *q++ = *p;
569  }
570  *q = 0;
571 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Dau_DsdRemoveBraces_rec(char *pStr, char **p, int *pMatches)
Definition: dauMerge.c:520
void Dau_DsdRemoveBraces_rec ( char *  pStr,
char **  p,
int *  pMatches 
)

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

Synopsis [Removes braces.]

Description []

SideEffects []

SeeAlso []

Definition at line 520 of file dauMerge.c.

521 {
522  if ( **p == '!' )
523  (*p)++;
524  while ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
525  (*p)++;
526  if ( **p == '<' )
527  {
528  char * q = pStr + pMatches[*p - pStr];
529  if ( *(q+1) == '{' )
530  *p = q+1;
531  }
532  if ( **p >= 'a' && **p <= 'z' ) // var
533  return;
534  if ( **p == '(' || **p == '[' || **p == '<' || **p == '{' )
535  {
536  char * q = pStr + pMatches[ *p - pStr ];
537  assert( *q == **p + 1 + (**p != '(') );
538  for ( (*p)++; *p < q; (*p)++ )
539  {
540  int fCompl = (**p == '!');
541  char * pBeg = fCompl ? *p + 1 : *p;
542  Dau_DsdRemoveBraces_rec( pStr, p, pMatches );
543  if ( (!fCompl && *pBeg == '(' && *q == ')') || (*pBeg == '[' && *q == ']') )
544  {
545  assert( **p == ')' || **p == ']' );
546  *pBeg = **p = ' ';
547  }
548  }
549  assert( *p == q );
550  return;
551  }
552  assert( 0 );
553 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Dau_DsdRemoveBraces_rec(char *pStr, char **p, int *pMatches)
Definition: dauMerge.c:520
#define assert(ex)
Definition: util_old.h:213
void Dau_DsdTest66 ( )

Definition at line 771 of file dauMerge.c.

772 {
773  int Perm0[DAU_MAX_VAR] = { 0, 1, 2, 3, 4, 5 };
774 // int pMatches[DAU_MAX_STR];
775 // int pStatus[DAU_MAX_STR];
776 
777 // char * pStr = "(!(!a<bcd>)!(!fe))";
778 // char * pStr = "([acb]<!edf>)";
779 // char * pStr = "!(f!(b!c!(d[ea])))";
780  char * pStr = "[!(a[be])!(c!df)]";
781 // char * pStr = "<(e<bca>)fd>";
782 // char * pStr = "[d8001{abef}c]";
783 // char * pStr1 = "(abc)";
784 // char * pStr2 = "[adf]";
785 // char * pStr1 = "(!abce)";
786 // char * pStr2 = "[adf!b]";
787 // char * pStr1 = "(!abc)";
788 // char * pStr2 = "[ab]";
789 // char * pStr1 = "[d81{abe}c]";
790 // char * pStr1 = "[d<a(bc)(!b!c)>{abe}c]";
791 // char * pStr1 = "[d81{abe}c]";
792 // char * pStr1 = "[d(a[be])c]";
793 // char * pStr2 = "(df)";
794 // char * pStr1 = "(abf)";
795 // char * pStr2 = "(a[(bc)(fde)])";
796 // char * pStr1 = "8001{abc[ef]}";
797 // char * pStr2 = "(abe)";
798 
799  char * pStr1 = "(!(ab)de)";
800  char * pStr2 = "(!(ac)f)";
801 
802  char * pRes;
803  word t = Dau_Dsd6ToTruth( pStr );
804  return;
805 
806 // pStr2 = Dau_DsdDecompose( &t, 6, 0, NULL );
807 // Dau_DsdNormalize( pStr2 );
808 
809 // Dau_DsdMergeMatches( pStr, pMatches );
810 // Dau_DsdMergeStatus( pStr, pMatches, 2, pStatus );
811 // Dau_DsdMergePrintWithStatus( pStr, pStatus );
812 
813  pRes = Dau_DsdMerge( pStr1, Perm0, pStr2, Perm0, 0, 0, 6 );
814 
815  t = 0;
816 }
char * Dau_DsdMerge(char *pDsd0i, int *pPerm0, char *pDsd1i, int *pPerm1, int fCompl0, int fCompl1, int nVars)
DECLARATIONS ///.
Definition: dauMerge.c:587
word Dau_Dsd6ToTruth(char *p)
Definition: dauDsd.c:445
#define DAU_MAX_VAR
INCLUDES ///.
Definition: dau.h:42
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36

Variable Documentation

abctime s_TimeComp[4] = {0}

Definition at line 574 of file dauMerge.c.