ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
dauDsd.c File Reference
#include "dauInt.h"
#include "misc/util/utilTruth.h"
Include dependency graph for dauDsd.c:

Go to the source code of this file.

Classes

struct  Dau_Dsd_t_
 

Typedefs

typedef struct Dau_Dsd_t_ Dau_Dsd_t
 

Functions

int * Dau_DsdComputeMatches (char *p)
 
int Dau_DsdFindVarNum (char *pDsd)
 
void Dau_DsdGenRandPerm (int *pPerm, int nVars)
 
void Dau_DsdPermute (char *pDsd)
 
char * Dau_DsdNormalizeCopy (char *pDest, char *pSour, int *pMarks, int i)
 
int Dau_DsdNormalizeCompare (char *pStr, int *pMarks, int i, int j)
 
int * Dau_DsdNormalizePerm (char *pStr, int *pMarks, int nMarks)
 
void Dau_DsdNormalize_rec (char *pStr, char **p, int *pMatches)
 
void Dau_DsdNormalize (char *pDsd)
 
int Dau_DsdCountAnds_rec (char *pStr, char **p, int *pMatches)
 
int Dau_DsdCountAnds (char *pDsd)
 
word Dau_Dsd6TruthCompose_rec (word Func, word *pFanins, int nVars)
 
word Dau_Dsd6ToTruth_rec (char *pStr, char **p, int *pMatches, word *pTruths)
 
word Dau_Dsd6ToTruth (char *p)
 
void Dau_DsdTruth6Compose_rec (word Func, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
 
void Dau_DsdTruthCompose_rec (word *pFunc, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
 
void Dau_DsdToTruth_rec (char *pStr, char **p, int *pMatches, word **pTtElems, word *pRes, int nVars)
 
wordDau_DsdToTruth (char *p, int nVars)
 
void Dau_DsdTest2 ()
 
int Dau_DsdPerform_rec (word t, char *pBuffer, int Pos, int *pVars, int nVars)
 
char * Dau_DsdPerform (word t)
 
void Dau_DsdTest3 ()
 
int Dau_DsdCheck1Step (void *p, word *pTruth, int nVarsInit, int *pVarLevels)
 
int Dau_DsdLevelVar (void *pMan, int iVar)
 
int Dau_Dsd6DecomposeSingleVar (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_Dsd6DecomposeDoubleVars (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_Dsd6DecomposeTripleVars (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_Dsd6DecomposeInternal (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_DsdDecomposeSingleVar (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_DsdDecomposeDoubleVars (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_DsdDecomposeTripleVars (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_DsdDecomposeInternal (Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
 
int Dau_DsdMinBase (word *pTruth, int nVars, int *pVarsNew)
 
int Dau_DsdDecomposeInt (Dau_Dsd_t *p, word *pTruth, int nVarsInit)
 
int Dau_DsdDecompose (word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
 
int Dau_DsdDecomposeLevel (word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes, int *pVarLevels)
 
void Dau_DsdPrintFromTruthFile (FILE *pFile, word *pTruth, int nVarsInit)
 
void Dau_DsdPrintFromTruth (word *pTruth, int nVarsInit)
 
void Dau_DsdPrintFromTruth2 (word *pTruth, int nVarsInit)
 
void Dau_DsdTest44 ()
 
void Dau_DsdTest888 ()
 
void Dau_DsdTest555 ()
 

Typedef Documentation

◆ Dau_Dsd_t

typedef struct Dau_Dsd_t_ Dau_Dsd_t

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

Synopsis [Data-structure to store DSD information.]

Description []

SideEffects []

SeeAlso []

Definition at line 955 of file dauDsd.c.

Function Documentation

◆ Dau_Dsd6DecomposeDoubleVars()

int Dau_Dsd6DecomposeDoubleVars ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1320 of file dauDsd.c.

1321{
1322 abctime clk = Abc_Clock();
1323 while ( 1 )
1324 {
1325 int v, u, nVarsOld;
1326 for ( v = nVars - 1; v > 0; v-- )
1327 {
1328 for ( u = v - 1; u >= 0; u-- )
1329 {
1330 if ( Dau_DsdLookupVarCache( p, pVars[v], pVars[u] ) )
1331 continue;
1332 nVarsOld = nVars;
1333 nVars = Dau_Dsd6DecomposeDoubleVarsOne( p, pTruth, pVars, nVars, v, u );
1334 if ( nVars == 0 )
1335 {
1336 s_Times[1] += Abc_Clock() - clk;
1337 return 0;
1338 }
1339 if ( nVarsOld > nVars )
1340 break;
1341 }
1342 if ( u >= 0 ) // found
1343 break;
1344 }
1345 if ( v == 0 ) // not found
1346 break;
1347 }
1348 s_Times[1] += Abc_Clock() - clk;
1349 return nVars;
1350}
ABC_INT64_T abctime
Definition abc_global.h:332
Cube * p
Definition exorList.c:222
Here is the caller graph for this function:

◆ Dau_Dsd6DecomposeInternal()

int Dau_Dsd6DecomposeInternal ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1461 of file dauDsd.c.

1462{
1463 // decompose single variales on the output side
1464 nVars = Dau_Dsd6DecomposeSingleVar( p, pTruth, pVars, nVars );
1465 if ( nVars == 0 )
1466 return 0;
1467 // decompose double variables on the input side
1468 nVars = Dau_Dsd6DecomposeDoubleVars( p, pTruth, pVars, nVars );
1469 if ( nVars == 0 )
1470 return 0;
1471 // decompose MUX on the output/input side
1472 nVars = Dau_Dsd6DecomposeTripleVars( p, pTruth, pVars, nVars );
1473 if ( nVars == 0 )
1474 return 0;
1475 // write non-decomposable function
1476 return Dau_DsdWritePrime( p, pTruth, pVars, nVars );
1477}
int Dau_Dsd6DecomposeDoubleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1320
int Dau_Dsd6DecomposeSingleVar(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1191
int Dau_Dsd6DecomposeTripleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1419
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_Dsd6DecomposeSingleVar()

int Dau_Dsd6DecomposeSingleVar ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1191 of file dauDsd.c.

1192{
1193 abctime clk = Abc_Clock();
1194 assert( nVars > 1 );
1195 while ( 1 )
1196 {
1197 int v;
1198 for ( v = nVars - 1; v >= 0 && nVars > 1; v-- )
1199 if ( Dau_Dsd6DecomposeSingleVarOne( p, pTruth, pVars, nVars, v ) )
1200 {
1201 nVars--;
1202 break;
1203 }
1204 if ( v == -1 || nVars == 1 )
1205 break;
1206 }
1207 if ( nVars == 1 )
1208 Dau_DsdWriteVar( p, pVars[--nVars], (int)(pTruth[0] & 1) );
1209 s_Times[0] += Abc_Clock() - clk;
1210 return nVars;
1211}
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Dau_Dsd6DecomposeTripleVars()

int Dau_Dsd6DecomposeTripleVars ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1419 of file dauDsd.c.

1420{
1421 abctime clk = Abc_Clock();
1422 while ( 1 )
1423 {
1424 int v;
1425// Kit_DsdPrintFromTruth( (unsigned *)pTruth, 6 ); printf( "\n" );
1426 for ( v = nVars - 1; v >= 0; v-- )
1427 {
1428 unsigned uSupports = Dau_Dsd6FindSupports( p, pTruth, pVars, nVars, v );
1429// Dau_DsdPrintSupports( uSupports, nVars );
1430 if ( (uSupports & (uSupports >> 1) & 0x55555555) == 0 ) // non-overlapping supports
1431 return Dau_Dsd6DecomposeTripleVarsOuter( p, pTruth, pVars, nVars, v );
1432 if ( Abc_TtSuppOnlyOne( uSupports & (~uSupports >> 1) & 0x55555555) &&
1433 Abc_TtSuppOnlyOne(~uSupports & ( uSupports >> 1) & 0x55555555) ) // one unique variable in each cofactor
1434 {
1435 int nVarsNew = Dau_Dsd6DecomposeTripleVarsInner( p, pTruth, pVars, nVars, v, uSupports );
1436 if ( nVarsNew == nVars )
1437 continue;
1438 if ( nVarsNew == 0 )
1439 {
1440 s_Times[2] += Abc_Clock() - clk;
1441 return 0;
1442 }
1443 nVars = Dau_Dsd6DecomposeDoubleVars( p, pTruth, pVars, nVarsNew );
1444 if ( nVars == 0 )
1445 {
1446 s_Times[2] += Abc_Clock() - clk;
1447 return 0;
1448 }
1449 break;
1450 }
1451 }
1452 if ( v == -1 )
1453 {
1454 s_Times[2] += Abc_Clock() - clk;
1455 return nVars;
1456 }
1457 }
1458 assert( 0 );
1459 return -1;
1460}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_Dsd6ToTruth()

word Dau_Dsd6ToTruth ( char * p)

Definition at line 445 of file dauDsd.c.

446{
447 word Res;
448 if ( *p == '0' && *(p+1) == 0 )
449 Res = 0;
450 else if ( *p == '1' && *(p+1) == 0 )
451 Res = ~(word)0;
452 else
453 Res = Dau_Dsd6ToTruth_rec( p, &p, Dau_DsdComputeMatches(p), s_Truths6 );
454 assert( *++p == 0 );
455 return Res;
456}
int * Dau_DsdComputeMatches(char *p)
Definition dauDsd.c:80
word Dau_Dsd6ToTruth_rec(char *pStr, char **p, int *pMatches, word *pTruths)
Definition dauDsd.c:353
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_Dsd6ToTruth_rec()

word Dau_Dsd6ToTruth_rec ( char * pStr,
char ** p,
int * pMatches,
word * pTruths )

Definition at line 353 of file dauDsd.c.

354{
355 int fCompl = 0;
356 if ( **p == '!' )
357 (*p)++, fCompl = 1;
358 if ( **p >= 'a' && **p <= 'f' ) // var
359 {
360 assert( **p - 'a' >= 0 && **p - 'a' < 6 );
361 return fCompl ? ~pTruths[**p - 'a'] : pTruths[**p - 'a'];
362 }
363 if ( **p == '(' ) // and/or
364 {
365 char * q = pStr + pMatches[ *p - pStr ];
366 word Res = ~(word)0;
367 assert( **p == '(' && *q == ')' );
368 for ( (*p)++; *p < q; (*p)++ )
369 Res &= Dau_Dsd6ToTruth_rec( pStr, p, pMatches, pTruths );
370 assert( *p == q );
371 return fCompl ? ~Res : Res;
372 }
373 if ( **p == '[' ) // xor
374 {
375 char * q = pStr + pMatches[ *p - pStr ];
376 word Res = 0;
377 assert( **p == '[' && *q == ']' );
378 for ( (*p)++; *p < q; (*p)++ )
379 Res ^= Dau_Dsd6ToTruth_rec( pStr, p, pMatches, pTruths );
380 assert( *p == q );
381 return fCompl ? ~Res : Res;
382 }
383 if ( **p == '<' ) // mux
384 {
385 int nVars = 0;
386 word Temp[3], * pTemp = Temp, Res;
387 word Fanins[6], * pTruths2;
388 char * pOld = *p;
389 char * q = pStr + pMatches[ *p - pStr ];
390 // read fanins
391 if ( *(q+1) == '{' )
392 {
393 char * q2;
394 *p = q+1;
395 q2 = pStr + pMatches[ *p - pStr ];
396 assert( **p == '{' && *q2 == '}' );
397 for ( nVars = 0, (*p)++; *p < q2; (*p)++, nVars++ )
398 Fanins[nVars] = Dau_Dsd6ToTruth_rec( pStr, p, pMatches, pTruths );
399 assert( *p == q2 );
400 pTruths2 = Fanins;
401 }
402 else
403 pTruths2 = pTruths;
404 // read MUX
405 *p = pOld;
406 q = pStr + pMatches[ *p - pStr ];
407 assert( **p == '<' && *q == '>' );
408 // verify internal variables
409 if ( nVars )
410 for ( ; pOld < q; pOld++ )
411 if ( *pOld >= 'a' && *pOld <= 'z' )
412 assert( *pOld - 'a' < nVars );
413 // derive MAX components
414 for ( (*p)++; *p < q; (*p)++ )
415 *pTemp++ = Dau_Dsd6ToTruth_rec( pStr, p, pMatches, pTruths2 );
416 assert( pTemp == Temp + 3 );
417 assert( *p == q );
418 if ( *(q+1) == '{' ) // and/or
419 {
420 char * q = pStr + pMatches[ ++(*p) - pStr ];
421 assert( **p == '{' && *q == '}' );
422 *p = q;
423 }
424 Res = (Temp[0] & Temp[1]) | (~Temp[0] & Temp[2]);
425 return fCompl ? ~Res : Res;
426 }
427 if ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
428 {
429 word Func, Fanins[6], Res;
430 char * q;
431 int i, nVars = Abc_TtReadHex( &Func, *p );
432 *p += Abc_TtHexDigitNum( nVars );
433 q = pStr + pMatches[ *p - pStr ];
434 assert( **p == '{' && *q == '}' );
435 for ( i = 0, (*p)++; *p < q; (*p)++, i++ )
436 Fanins[i] = Dau_Dsd6ToTruth_rec( pStr, p, pMatches, pTruths );
437 assert( i == nVars );
438 assert( *p == q );
439 Res = Dau_Dsd6TruthCompose_rec( Func, Fanins, nVars );
440 return fCompl ? ~Res : Res;
441 }
442 assert( 0 );
443 return 0;
444}
word Dau_Dsd6TruthCompose_rec(word Func, word *pFanins, int nVars)
Definition dauDsd.c:334
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_Dsd6TruthCompose_rec()

word Dau_Dsd6TruthCompose_rec ( word Func,
word * pFanins,
int nVars )

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

Synopsis [Computes truth table for the DSD formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 334 of file dauDsd.c.

335{
336 word t0, t1;
337 if ( Func == 0 )
338 return 0;
339 if ( Func == ~(word)0 )
340 return ~(word)0;
341 assert( nVars > 0 );
342 if ( --nVars == 0 )
343 {
344 assert( Func == s_Truths6[0] || Func == s_Truths6Neg[0] );
345 return (Func == s_Truths6[0]) ? pFanins[0] : ~pFanins[0];
346 }
347 if ( !Abc_Tt6HasVar(Func, nVars) )
348 return Dau_Dsd6TruthCompose_rec( Func, pFanins, nVars );
349 t0 = Dau_Dsd6TruthCompose_rec( Abc_Tt6Cofactor0(Func, nVars), pFanins, nVars );
350 t1 = Dau_Dsd6TruthCompose_rec( Abc_Tt6Cofactor1(Func, nVars), pFanins, nVars );
351 return (~pFanins[nVars] & t0) | (pFanins[nVars] & t1);
352}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdCheck1Step()

int Dau_DsdCheck1Step ( void * p,
word * pTruth,
int nVarsInit,
int * pVarLevels )

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

Synopsis [Find the best cofactoring variable.]

Description [Return -2 if non-DSD; -1 if full DSD; otherwise, returns cofactoring variables i (i >= 0).]

SideEffects []

SeeAlso []

Definition at line 893 of file dauDsd.c.

894{
895 word pCofTemp[DAU_MAX_WORD];
896 int pVarPrios[DAU_MAX_VAR];
897 int nWords = Abc_TtWordNum(nVarsInit);
898 int nSizeNonDec, nSizeNonDec0, nSizeNonDec1;
899 int i, vBest = -2, nSumCofsBest = ABC_INFINITY, nSumCofs;
900 nSizeNonDec = Dau_DsdDecompose( pTruth, nVarsInit, 0, 0, NULL );
901 if ( nSizeNonDec == 0 )
902 return -1;
903 assert( nSizeNonDec > 0 );
904 // find variable priority
905 for ( i = 0; i < nVarsInit; i++ )
906 pVarPrios[i] = i;
907 if ( pVarLevels )
908 {
909 extern int Dau_DsdLevelVar( void * pMan, int iVar );
910 int pVarLevels[DAU_MAX_VAR];
911 for ( i = 0; i < nVarsInit; i++ )
912 pVarLevels[i] = -Dau_DsdLevelVar( p, i );
913// for ( i = 0; i < nVarsInit; i++ )
914// printf( "%d ", -pVarLevels[i] );
915// printf( "\n" );
916 Vec_IntSelectSortCost2( pVarPrios, nVarsInit, pVarLevels );
917// for ( i = 0; i < nVarsInit; i++ )
918// printf( "%d ", pVarPrios[i] );
919// printf( "\n\n" );
920 }
921 for ( i = 0; i < nVarsInit; i++ )
922 {
923 assert( pVarPrios[i] >= 0 && pVarPrios[i] < nVarsInit );
924 // try first cofactor
925 Abc_TtCofactor0p( pCofTemp, pTruth, nWords, pVarPrios[i] );
926 nSumCofs = Abc_TtSupportSize( pCofTemp, nVarsInit );
927 nSizeNonDec0 = Dau_DsdDecompose( pCofTemp, nVarsInit, 0, 0, NULL );
928 // try second cofactor
929 Abc_TtCofactor1p( pCofTemp, pTruth, nWords, pVarPrios[i] );
930 nSumCofs += Abc_TtSupportSize( pCofTemp, nVarsInit );
931 nSizeNonDec1 = Dau_DsdDecompose( pCofTemp, nVarsInit, 0, 0, NULL );
932 // compare cofactors
933 if ( nSizeNonDec0 || nSizeNonDec1 )
934 continue;
935 if ( nSumCofsBest > nSumCofs )
936 {
937 vBest = pVarPrios[i];
938 nSumCofsBest = nSumCofs;
939 }
940 }
941 return vBest;
942}
int nWords
Definition abcNpn.c:127
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
Definition dauDsd.c:1912
int Dau_DsdLevelVar(void *pMan, int iVar)
Definition dauDsd.c:1018
#define DAU_MAX_WORD
Definition dau.h:44
#define DAU_MAX_VAR
INCLUDES ///.
Definition dau.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdComputeMatches()

int * Dau_DsdComputeMatches ( char * p)

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

Synopsis [DSD formula manipulation.]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file dauDsd.c.

81{
82 static int pMatches[DAU_MAX_STR];
83 int pNested[DAU_MAX_VAR];
84 int v, nNested = 0;
85 for ( v = 0; p[v]; v++ )
86 {
87 pMatches[v] = 0;
88 if ( p[v] == '(' || p[v] == '[' || p[v] == '<' || p[v] == '{' )
89 pNested[nNested++] = v;
90 else if ( p[v] == ')' || p[v] == ']' || p[v] == '>' || p[v] == '}' )
91 pMatches[pNested[--nNested]] = v;
92 assert( nNested < DAU_MAX_VAR );
93 }
94 assert( nNested == 0 );
95 return pMatches;
96}
#define DAU_MAX_STR
Definition dau.h:43
Here is the caller graph for this function:

◆ Dau_DsdCountAnds()

int Dau_DsdCountAnds ( char * pDsd)

Definition at line 316 of file dauDsd.c.

317{
318 if ( pDsd[1] == 0 )
319 return 0;
320 return Dau_DsdCountAnds_rec( pDsd, &pDsd, Dau_DsdComputeMatches(pDsd) );
321}
int Dau_DsdCountAnds_rec(char *pStr, char **p, int *pMatches)
Definition dauDsd.c:279
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdCountAnds_rec()

int Dau_DsdCountAnds_rec ( char * pStr,
char ** p,
int * pMatches )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 279 of file dauDsd.c.

280{
281 if ( **p == '!' )
282 (*p)++;
283 while ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
284 (*p)++;
285 if ( **p == '<' )
286 {
287 char * q = pStr + pMatches[*p - pStr];
288 if ( *(q+1) == '{' )
289 *p = q+1;
290 }
291 if ( **p >= 'a' && **p <= 'z' ) // var
292 return 0;
293 if ( **p == '(' || **p == '[' ) // and/or/xor
294 {
295 int Counter = 0, AddOn = (**p == '(')? 1 : 3;
296 char * q = pStr + pMatches[ *p - pStr ];
297 assert( *q == **p + 1 + (**p != '(') );
298 for ( (*p)++; *p < q; (*p)++ )
299 Counter += AddOn + Dau_DsdCountAnds_rec( pStr, p, pMatches );
300 assert( *p == q );
301 return Counter - AddOn;
302 }
303 if ( **p == '<' || **p == '{' ) // mux
304 {
305 int Counter = 3;
306 char * q = pStr + pMatches[ *p - pStr ];
307 assert( *q == **p + 1 + (**p != '(') );
308 for ( (*p)++; *p < q; (*p)++ )
309 Counter += Dau_DsdCountAnds_rec( pStr, p, pMatches );
310 assert( *p == q );
311 return Counter;
312 }
313 assert( 0 );
314 return 0;
315}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdDecompose()

int Dau_DsdDecompose ( word * pTruth,
int nVarsInit,
int fSplitPrime,
int fWriteTruth,
char * pRes )

Definition at line 1912 of file dauDsd.c.

1913{
1914 Dau_Dsd_t P, * p = &P;
1915 p->fSplitPrime = fSplitPrime;
1916 p->fWriteTruth = fWriteTruth;
1917 p->pVarLevels = NULL;
1918 p->nSizeNonDec = 0;
1919 if ( (pTruth[0] & 1) == 0 && Abc_TtIsConst0(pTruth, Abc_TtWordNum(nVarsInit)) )
1920 { if ( pRes ) pRes[0] = '0', pRes[1] = 0; }
1921 else if ( (pTruth[0] & 1) && Abc_TtIsConst1(pTruth, Abc_TtWordNum(nVarsInit)) )
1922 { if ( pRes ) pRes[0] = '1', pRes[1] = 0; }
1923 else
1924 {
1925 int Status = Dau_DsdDecomposeInt( p, pTruth, nVarsInit );
1926 Dau_DsdRemoveBraces( p->pOutput, Dau_DsdComputeMatches(p->pOutput) );
1927 if ( pRes )
1928 strcpy( pRes, p->pOutput );
1929 assert( fSplitPrime || Status != 1 );
1930 if ( fSplitPrime && Status == 2 )
1931 return -1;
1932 }
1933// assert( p->nSizeNonDec == 0 );
1934 return p->nSizeNonDec;
1935}
typedefABC_NAMESPACE_IMPL_START struct Dau_Dsd_t_ Dau_Dsd_t
DECLARATIONS ///.
Definition dauArray.c:29
int Dau_DsdDecomposeInt(Dau_Dsd_t *p, word *pTruth, int nVarsInit)
Definition dauDsd.c:1897
void Dau_DsdRemoveBraces(char *pDsd, int *pMatches)
Definition dauMerge.c:554
int * Dau_DsdComputeMatches(char *p)
Definition dauDsd.c:80
char * strcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdDecomposeDoubleVars()

int Dau_DsdDecomposeDoubleVars ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1697 of file dauDsd.c.

1698{
1699 abctime clk = Abc_Clock();
1700 while ( 1 )
1701 {
1702 int v, u, nVarsOld;
1703 for ( v = nVars - 1; v > 0; v-- )
1704 {
1705 for ( u = v - 1; u >= 0; u-- )
1706 {
1707 if ( Dau_DsdLookupVarCache( p, pVars[v], pVars[u] ) )
1708 continue;
1709 nVarsOld = nVars;
1710 nVars = Dau_DsdDecomposeDoubleVarsOne( p, pTruth, pVars, nVars, v, u );
1711 if ( nVars == 0 )
1712 {
1713 s_Times[1] += Abc_Clock() - clk;
1714 return 0;
1715 }
1716 if ( nVarsOld > nVars )
1717 break;
1718 }
1719 if ( u >= 0 ) // found
1720 break;
1721 }
1722 if ( v == 0 ) // not found
1723 break;
1724 }
1725 s_Times[1] += Abc_Clock() - clk;
1726 return nVars;
1727}
Here is the caller graph for this function:

◆ Dau_DsdDecomposeInt()

int Dau_DsdDecomposeInt ( Dau_Dsd_t * p,
word * pTruth,
int nVarsInit )

Definition at line 1897 of file dauDsd.c.

1898{
1899 int Status = 0, nVars, pVars[16];
1900 Dau_DsdInitialize( p, nVarsInit );
1901 nVars = Dau_DsdMinBase( pTruth, nVarsInit, pVars );
1902 assert( nVars > 0 && nVars <= nVarsInit );
1903 if ( nVars == 1 )
1904 Dau_DsdWriteVar( p, pVars[0], (int)(pTruth[0] & 1) );
1905 else if ( nVars <= 6 )
1906 Status = Dau_Dsd6DecomposeInternal( p, pTruth, pVars, nVars );
1907 else
1908 Status = Dau_DsdDecomposeInternal( p, pTruth, pVars, nVars );
1909 Dau_DsdFinalize( p );
1910 return Status;
1911}
int Dau_DsdDecomposeInternal(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1854
int Dau_Dsd6DecomposeInternal(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1461
int Dau_DsdMinBase(word *pTruth, int nVars, int *pVarsNew)
Definition dauDsd.c:1883
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdDecomposeInternal()

int Dau_DsdDecomposeInternal ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1854 of file dauDsd.c.

1855{
1856 // decompose single variales on the output side
1857 nVars = Dau_DsdDecomposeSingleVar( p, pTruth, pVars, nVars );
1858 if ( nVars == 0 )
1859 return 0;
1860 // decompose double variables on the input side
1861 nVars = Dau_DsdDecomposeDoubleVars( p, pTruth, pVars, nVars );
1862 if ( nVars == 0 )
1863 return 0;
1864 // decompose MUX on the output/input side
1865 nVars = Dau_DsdDecomposeTripleVars( p, pTruth, pVars, nVars );
1866 if ( nVars == 0 )
1867 return 0;
1868 // write non-decomposable function
1869 return Dau_DsdWritePrime( p, pTruth, pVars, nVars );
1870}
int Dau_DsdDecomposeTripleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1812
int Dau_DsdDecomposeDoubleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1697
int Dau_DsdDecomposeSingleVar(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
Definition dauDsd.c:1550
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdDecomposeLevel()

int Dau_DsdDecomposeLevel ( word * pTruth,
int nVarsInit,
int fSplitPrime,
int fWriteTruth,
char * pRes,
int * pVarLevels )

Definition at line 1936 of file dauDsd.c.

1937{
1938 Dau_Dsd_t P, * p = &P;
1939 p->fSplitPrime = fSplitPrime;
1940 p->fWriteTruth = fWriteTruth;
1941 p->pVarLevels = pVarLevels;
1942 p->nSizeNonDec = 0;
1943 if ( (pTruth[0] & 1) == 0 && Abc_TtIsConst0(pTruth, Abc_TtWordNum(nVarsInit)) )
1944 { if ( pRes ) pRes[0] = '0', pRes[1] = 0; }
1945 else if ( (pTruth[0] & 1) && Abc_TtIsConst1(pTruth, Abc_TtWordNum(nVarsInit)) )
1946 { if ( pRes ) pRes[0] = '1', pRes[1] = 0; }
1947 else
1948 {
1949 int Status = Dau_DsdDecomposeInt( p, pTruth, nVarsInit );
1950 Dau_DsdRemoveBraces( p->pOutput, Dau_DsdComputeMatches(p->pOutput) );
1951 if ( pRes )
1952 strcpy( pRes, p->pOutput );
1953 assert( fSplitPrime || Status != 1 );
1954 if ( fSplitPrime && Status == 2 )
1955 return -1;
1956 }
1957// assert( p->nSizeNonDec == 0 );
1958 return p->nSizeNonDec;
1959}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdDecomposeSingleVar()

int Dau_DsdDecomposeSingleVar ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1550 of file dauDsd.c.

1551{
1552 abctime clk = Abc_Clock();
1553 assert( nVars > 1 );
1554 while ( 1 )
1555 {
1556 int v;
1557 for ( v = nVars - 1; v >= 0 && nVars > 1; v-- )
1558 if ( Dau_DsdDecomposeSingleVarOne( p, pTruth, pVars, nVars, v ) )
1559 {
1560 nVars--;
1561 break;
1562 }
1563 if ( v == -1 || nVars == 1 )
1564 break;
1565 }
1566 if ( nVars == 1 )
1567 Dau_DsdWriteVar( p, pVars[--nVars], (int)(pTruth[0] & 1) );
1568 s_Times[0] += Abc_Clock() - clk;
1569 return nVars;
1570}
Here is the caller graph for this function:

◆ Dau_DsdDecomposeTripleVars()

int Dau_DsdDecomposeTripleVars ( Dau_Dsd_t * p,
word * pTruth,
int * pVars,
int nVars )

Definition at line 1812 of file dauDsd.c.

1813{
1814 abctime clk = Abc_Clock();
1815 while ( 1 )
1816 {
1817 int v;
1818// Kit_DsdPrintFromTruth( (unsigned *)pTruth, 6 ); printf( "\n" );
1819 for ( v = nVars - 1; v >= 0; v-- )
1820 {
1821 unsigned uSupports = Dau_DsdFindSupports( p, pTruth, pVars, nVars, v );
1822// Dau_DsdPrintSupports( uSupports, nVars );
1823 if ( (uSupports & (uSupports >> 1) & 0x55555555) == 0 ) // non-overlapping supports
1824 return Dau_DsdDecomposeTripleVarsOuter( p, pTruth, pVars, nVars, v );
1825 if ( Abc_TtSuppOnlyOne( uSupports & (~uSupports >> 1) & 0x55555555) &&
1826 Abc_TtSuppOnlyOne(~uSupports & ( uSupports >> 1) & 0x55555555) ) // one unique variable in each cofactor
1827 {
1828 int nVarsNew = Dau_DsdDecomposeTripleVarsInner( p, pTruth, pVars, nVars, v, uSupports );
1829 if ( nVarsNew == nVars )
1830 continue;
1831 if ( nVarsNew == 0 )
1832 {
1833 s_Times[2] += Abc_Clock() - clk;
1834 return 0;
1835 }
1836 nVars = Dau_DsdDecomposeDoubleVars( p, pTruth, pVars, nVarsNew );
1837 if ( nVars == 0 )
1838 {
1839 s_Times[2] += Abc_Clock() - clk;
1840 return 0;
1841 }
1842 break;
1843 }
1844 }
1845 if ( v == -1 )
1846 {
1847 s_Times[2] += Abc_Clock() - clk;
1848 return nVars;
1849 }
1850 }
1851 assert( 0 );
1852 return -1;
1853}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdFindVarNum()

int Dau_DsdFindVarNum ( char * pDsd)

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

Synopsis [Generate random permutation.]

Description []

SideEffects []

SeeAlso []

Definition at line 109 of file dauDsd.c.

110{
111 int vMax = 0;
112 pDsd--;
113 while ( *++pDsd )
114 if ( *pDsd >= 'a' && *pDsd <= 'z' )
115 vMax = Abc_MaxInt( vMax, *pDsd - 'a' );
116 return vMax + 1;
117}
Here is the caller graph for this function:

◆ Dau_DsdGenRandPerm()

void Dau_DsdGenRandPerm ( int * pPerm,
int nVars )

Definition at line 118 of file dauDsd.c.

119{
120 int v, vNew;
121 for ( v = 0; v < nVars; v++ )
122 pPerm[v] = v;
123 for ( v = 0; v < nVars; v++ )
124 {
125 vNew = rand() % nVars;
126 ABC_SWAP( int, pPerm[v], pPerm[vNew] );
127 }
128}
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
Here is the caller graph for this function:

◆ Dau_DsdLevelVar()

int Dau_DsdLevelVar ( void * pMan,
int iVar )

Definition at line 1018 of file dauDsd.c.

1019{
1020 Dau_Dsd_t * p = (Dau_Dsd_t *)pMan;
1021 char * pStr;
1022 int LevelMax = 0, Level;
1023 for ( pStr = p->pVarDefs[iVar]; *pStr; pStr++ )
1024 {
1025 if ( *pStr >= 'a' + p->nVarsInit && *pStr < 'a' + p->nVarsUsed )
1026 Level = 1 + Dau_DsdLevelVar( p, *pStr - 'a' );
1027 else
1028 Level = p->pVarLevels[*pStr - 'a'];
1029 LevelMax = Abc_MaxInt( LevelMax, Level );
1030 }
1031 return LevelMax;
1032}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdMinBase()

int Dau_DsdMinBase ( word * pTruth,
int nVars,
int * pVarsNew )

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

Synopsis [Fast DSD for truth tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 1883 of file dauDsd.c.

1884{
1885 int v;
1886 for ( v = 0; v < nVars; v++ )
1887 pVarsNew[v] = v;
1888 for ( v = nVars - 1; v >= 0; v-- )
1889 {
1890 if ( Abc_TtHasVar( pTruth, nVars, v ) )
1891 continue;
1892 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1893 pVarsNew[v] = pVarsNew[--nVars];
1894 }
1895 return nVars;
1896}
Here is the caller graph for this function:

◆ Dau_DsdNormalize()

void Dau_DsdNormalize ( char * pDsd)

Definition at line 260 of file dauDsd.c.

261{
262 if ( pDsd[1] != 0 )
263 Dau_DsdNormalize_rec( pDsd, &pDsd, Dau_DsdComputeMatches(pDsd) );
264}
void Dau_DsdNormalize_rec(char *pStr, char **p, int *pMatches)
Definition dauDsd.c:205
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdNormalize_rec()

void Dau_DsdNormalize_rec ( char * pStr,
char ** p,
int * pMatches )

Definition at line 205 of file dauDsd.c.

206{
207 static char pBuffer[DAU_MAX_STR];
208 if ( **p == '!' )
209 (*p)++;
210 while ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
211 (*p)++;
212 if ( **p == '<' )
213 {
214 char * q = pStr + pMatches[*p - pStr];
215 if ( *(q+1) == '{' )
216 *p = q+1;
217 }
218 if ( **p >= 'a' && **p <= 'z' ) // var
219 return;
220 if ( **p == '(' || **p == '[' ) // and/or/xor
221 {
222 char * pStore, * pOld = *p + 1;
223 char * q = pStr + pMatches[ *p - pStr ];
224 int i, * pPerm, nMarks = 0, pMarks[DAU_MAX_VAR+1];
225 assert( *q == **p + 1 + (**p != '(') );
226 for ( (*p)++; *p < q; (*p)++ )
227 {
228 pMarks[nMarks++] = *p - pStr;
229 Dau_DsdNormalize_rec( pStr, p, pMatches );
230 }
231 pMarks[nMarks] = *p - pStr;
232 assert( *p == q );
233 // add to buffer in good order
234 pPerm = Dau_DsdNormalizePerm( pStr, pMarks, nMarks );
235 // copy to the buffer
236 pStore = pBuffer;
237 for ( i = 0; i < nMarks; i++ )
238 pStore = Dau_DsdNormalizeCopy( pStore, pStr, pMarks, pPerm[i] );
239 assert( pStore - pBuffer == *p - pOld );
240 memcpy( pOld, pBuffer, (size_t)(pStore - pBuffer) );
241 return;
242 }
243 if ( **p == '<' || **p == '{' ) // mux
244 {
245 char * q = pStr + pMatches[ *p - pStr ];
246 assert( *q == **p + 1 + (**p != '(') );
247 if ( (**p == '<') && (*(q+1) == '{') )
248 {
249 *p = q+1;
250 Dau_DsdNormalize_rec( pStr, p, pMatches );
251 return;
252 }
253 for ( (*p)++; *p < q; (*p)++ )
254 Dau_DsdNormalize_rec( pStr, p, pMatches );
255 assert( *p == q );
256 return;
257 }
258 assert( 0 );
259}
int * Dau_DsdNormalizePerm(char *pStr, int *pMarks, int nMarks)
Definition dauDsd.c:189
char * Dau_DsdNormalizeCopy(char *pDest, char *pSour, int *pMarks, int i)
Definition dauDsd.c:151
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdNormalizeCompare()

int Dau_DsdNormalizeCompare ( char * pStr,
int * pMarks,
int i,
int j )

Definition at line 158 of file dauDsd.c.

159{
160 char * pStr1 = pStr + pMarks[i];
161 char * pStr2 = pStr + pMarks[j];
162 char * pLimit1 = pStr + pMarks[i+1];
163 char * pLimit2 = pStr + pMarks[j+1];
164 for ( ; pStr1 < pLimit1 && pStr2 < pLimit2; pStr1++, pStr2++ )
165 {
166 if ( !(*pStr1 >= 'a' && *pStr1 <= 'z') )
167 {
168 pStr2--;
169 continue;
170 }
171 if ( !(*pStr2 >= 'a' && *pStr2 <= 'z') )
172 {
173 pStr1--;
174 continue;
175 }
176 if ( *pStr1 < *pStr2 )
177 return -1;
178 if ( *pStr1 > *pStr2 )
179 return 1;
180 }
181 assert( pStr1 < pLimit1 || pStr2 < pLimit2 );
182 if ( pStr1 == pLimit1 )
183 return -1;
184 if ( pStr2 == pLimit2 )
185 return 1;
186 assert( 0 );
187 return 0;
188}
Here is the caller graph for this function:

◆ Dau_DsdNormalizeCopy()

char * Dau_DsdNormalizeCopy ( char * pDest,
char * pSour,
int * pMarks,
int i )

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

Synopsis [Normalize the ordering of components.]

Description []

SideEffects []

SeeAlso []

Definition at line 151 of file dauDsd.c.

152{
153 int s;
154 for ( s = pMarks[i]; s < pMarks[i+1]; s++ )
155 *pDest++ = pSour[s];
156 return pDest;
157}
Here is the caller graph for this function:

◆ Dau_DsdNormalizePerm()

int * Dau_DsdNormalizePerm ( char * pStr,
int * pMarks,
int nMarks )

Definition at line 189 of file dauDsd.c.

190{
191 static int pPerm[DAU_MAX_VAR];
192 int i, k;
193 for ( i = 0; i < nMarks; i++ )
194 pPerm[i] = i;
195 for ( i = 0; i < nMarks; i++ )
196 {
197 int iBest = i;
198 for ( k = i + 1; k < nMarks; k++ )
199 if ( Dau_DsdNormalizeCompare( pStr, pMarks, pPerm[iBest], pPerm[k] ) == 1 )
200 iBest = k;
201 ABC_SWAP( int, pPerm[i], pPerm[iBest] );
202 }
203 return pPerm;
204}
int Dau_DsdNormalizeCompare(char *pStr, int *pMarks, int i, int j)
Definition dauDsd.c:158
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdPerform()

char * Dau_DsdPerform ( word t)

Definition at line 828 of file dauDsd.c.

829{
830 static char pBuffer[DAU_MAX_STR];
831 int pVarsNew[6] = {0, 1, 2, 3, 4, 5};
832 int Pos = 0;
833 if ( t == 0 )
834 pBuffer[Pos++] = '0';
835 else if ( t == ~(word)0 )
836 pBuffer[Pos++] = '1';
837 else
838 Pos = Dau_DsdPerform_rec( t, pBuffer, Pos, pVarsNew, 6 );
839 pBuffer[Pos++] = 0;
840// printf( "%d ", strlen(pBuffer) );
841// printf( "%s ->", pBuffer );
842 Dau_DsdRemoveBraces( pBuffer, Dau_DsdComputeMatches(pBuffer) );
843// printf( " %s\n", pBuffer );
844 return pBuffer;
845}
int Dau_DsdPerform_rec(word t, char *pBuffer, int Pos, int *pVars, int nVars)
Definition dauDsd.c:673
ush Pos
Definition deflate.h:88
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdPerform_rec()

int Dau_DsdPerform_rec ( word t,
char * pBuffer,
int Pos,
int * pVars,
int nVars )

Definition at line 673 of file dauDsd.c.

674{
675 char pNest[10];
676 word Cof0[6], Cof1[6], Cof[4];
677 int pVarsNew[6], nVarsNew, PosStart;
678 int v, u, vBest, CountBest;
680 // perform support minimization
681 nVarsNew = 0;
682 for ( v = 0; v < nVars; v++ )
683 if ( Abc_Tt6HasVar( t, pVars[v] ) )
684 pVarsNew[ nVarsNew++ ] = pVars[v];
685 assert( nVarsNew > 0 );
686 // special case when function is a var
687 if ( nVarsNew == 1 )
688 {
689 if ( t == s_Truths6[ pVarsNew[0] ] )
690 {
691 pBuffer[Pos++] = 'a' + pVarsNew[0];
692 return Pos;
693 }
694 if ( t == ~s_Truths6[ pVarsNew[0] ] )
695 {
696 pBuffer[Pos++] = '!';
697 pBuffer[Pos++] = 'a' + pVarsNew[0];
698 return Pos;
699 }
700 assert( 0 );
701 return Pos;
702 }
703 // decompose on the output side
704 for ( v = 0; v < nVarsNew; v++ )
705 {
706 Cof0[v] = Abc_Tt6Cofactor0( t, pVarsNew[v] );
707 Cof1[v] = Abc_Tt6Cofactor1( t, pVarsNew[v] );
708 assert( Cof0[v] != Cof1[v] );
709 if ( Cof0[v] == 0 ) // ax
710 {
711 pBuffer[Pos++] = '(';
712 pBuffer[Pos++] = 'a' + pVarsNew[v];
713 Pos = Dau_DsdPerform_rec( Cof1[v], pBuffer, Pos, pVarsNew, nVarsNew );
714 pBuffer[Pos++] = ')';
715 return Pos;
716 }
717 if ( Cof0[v] == ~(word)0 ) // !(ax)
718 {
719 pBuffer[Pos++] = '!';
720 pBuffer[Pos++] = '(';
721 pBuffer[Pos++] = 'a' + pVarsNew[v];
722 Pos = Dau_DsdPerform_rec( ~Cof1[v], pBuffer, Pos, pVarsNew, nVarsNew );
723 pBuffer[Pos++] = ')';
724 return Pos;
725 }
726 if ( Cof1[v] == 0 ) // !ax
727 {
728 pBuffer[Pos++] = '(';
729 pBuffer[Pos++] = '!';
730 pBuffer[Pos++] = 'a' + pVarsNew[v];
731 Pos = Dau_DsdPerform_rec( Cof0[v], pBuffer, Pos, pVarsNew, nVarsNew );
732 pBuffer[Pos++] = ')';
733 return Pos;
734 }
735 if ( Cof1[v] == ~(word)0 ) // !(!ax)
736 {
737 pBuffer[Pos++] = '!';
738 pBuffer[Pos++] = '(';
739 pBuffer[Pos++] = '!';
740 pBuffer[Pos++] = 'a' + pVarsNew[v];
741 Pos = Dau_DsdPerform_rec( ~Cof0[v], pBuffer, Pos, pVarsNew, nVarsNew );
742 pBuffer[Pos++] = ')';
743 return Pos;
744 }
745 if ( Cof0[v] == ~Cof1[v] ) // a^x
746 {
747 pBuffer[Pos++] = '[';
748 pBuffer[Pos++] = 'a' + pVarsNew[v];
749 Pos = Dau_DsdPerform_rec( Cof0[v], pBuffer, Pos, pVarsNew, nVarsNew );
750 pBuffer[Pos++] = ']';
751 return Pos;
752 }
753 }
754 // decompose on the input side
755 for ( v = 0; v < nVarsNew; v++ )
756 for ( u = v+1; u < nVarsNew; u++ )
757 {
758 Cof[0] = Abc_Tt6Cofactor0( Cof0[v], pVarsNew[u] );
759 Cof[1] = Abc_Tt6Cofactor1( Cof0[v], pVarsNew[u] );
760 Cof[2] = Abc_Tt6Cofactor0( Cof1[v], pVarsNew[u] );
761 Cof[3] = Abc_Tt6Cofactor1( Cof1[v], pVarsNew[u] );
762 if ( Cof[0] == Cof[1] && Cof[0] == Cof[2] ) // vu
763 {
764 PosStart = Pos;
765 sprintf( pNest, "(%c%c)", 'a' + pVarsNew[v], 'a' + pVarsNew[u] );
766 Pos = Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[3]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer, Pos, pVarsNew, nVarsNew );
767 Pos = Dau_DsdPerformReplace( pBuffer, PosStart, Pos, 'a' + pVarsNew[u], pNest );
768 return Pos;
769 }
770 if ( Cof[0] == Cof[1] && Cof[0] == Cof[3] ) // v!u
771 {
772 PosStart = Pos;
773 sprintf( pNest, "(%c!%c)", 'a' + pVarsNew[v], 'a' + pVarsNew[u] );
774 Pos = Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[2]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer, Pos, pVarsNew, nVarsNew );
775 Pos = Dau_DsdPerformReplace( pBuffer, PosStart, Pos, 'a' + pVarsNew[u], pNest );
776 return Pos;
777 }
778 if ( Cof[0] == Cof[2] && Cof[0] == Cof[3] ) // !vu
779 {
780 PosStart = Pos;
781 sprintf( pNest, "(!%c%c)", 'a' + pVarsNew[v], 'a' + pVarsNew[u] );
782 Pos = Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[1]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer, Pos, pVarsNew, nVarsNew );
783 Pos = Dau_DsdPerformReplace( pBuffer, PosStart, Pos, 'a' + pVarsNew[u], pNest );
784 return Pos;
785 }
786 if ( Cof[1] == Cof[2] && Cof[1] == Cof[3] ) // !v!u
787 {
788 PosStart = Pos;
789 sprintf( pNest, "(!%c!%c)", 'a' + pVarsNew[v], 'a' + pVarsNew[u] );
790 Pos = Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[0]) | (~s_Truths6[pVarsNew[u]] & Cof[1]), pBuffer, Pos, pVarsNew, nVarsNew );
791 Pos = Dau_DsdPerformReplace( pBuffer, PosStart, Pos, 'a' + pVarsNew[u], pNest );
792 return Pos;
793 }
794 if ( Cof[0] == Cof[3] && Cof[1] == Cof[2] ) // v+u
795 {
796 PosStart = Pos;
797 sprintf( pNest, "[%c%c]", 'a' + pVarsNew[v], 'a' + pVarsNew[u] );
798 Pos = Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[1]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer, Pos, pVarsNew, nVarsNew );
799 Pos = Dau_DsdPerformReplace( pBuffer, PosStart, Pos, 'a' + pVarsNew[u], pNest );
800 return Pos;
801 }
802 }
803 // find best variable for MUX decomposition
804 vBest = -1;
805 CountBest = 10;
806 for ( v = 0; v < nVarsNew; v++ )
807 {
808 int CountCur = 0;
809 for ( u = 0; u < nVarsNew; u++ )
810 if ( u != v && Abc_Tt6HasVar(Cof0[v], pVarsNew[u]) && Abc_Tt6HasVar(Cof1[v], pVarsNew[u]) )
811 CountCur++;
812 if ( CountBest > CountCur )
813 {
814 CountBest = CountCur;
815 vBest = v;
816 }
817 if ( CountCur == 0 )
818 break;
819 }
820 // perform MUX decomposition
821 pBuffer[Pos++] = '<';
822 pBuffer[Pos++] = 'a' + pVarsNew[vBest];
823 Pos = Dau_DsdPerform_rec( Cof1[vBest], pBuffer, Pos, pVarsNew, nVarsNew );
824 Pos = Dau_DsdPerform_rec( Cof0[vBest], pBuffer, Pos, pVarsNew, nVarsNew );
825 pBuffer[Pos++] = '>';
826 return Pos;
827}
char * sprintf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdPermute()

void Dau_DsdPermute ( char * pDsd)

Definition at line 129 of file dauDsd.c.

130{
131 int pPerm[16];
132 int nVars = Dau_DsdFindVarNum( pDsd );
133 Dau_DsdGenRandPerm( pPerm, nVars );
134 pDsd--;
135 while ( *++pDsd )
136 if ( *pDsd >= 'a' && *pDsd < 'a' + nVars )
137 *pDsd = 'a' + pPerm[*pDsd - 'a'];
138}
int Dau_DsdFindVarNum(char *pDsd)
Definition dauDsd.c:109
void Dau_DsdGenRandPerm(int *pPerm, int nVars)
Definition dauDsd.c:118
Here is the call graph for this function:

◆ Dau_DsdPrintFromTruth()

void Dau_DsdPrintFromTruth ( word * pTruth,
int nVarsInit )

Definition at line 1968 of file dauDsd.c.

1969{
1970 char pRes[DAU_MAX_STR];
1971 word pTemp[DAU_MAX_WORD];
1972 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1973 Dau_DsdDecompose( pTemp, nVarsInit, 0, 1, pRes );
1974 fprintf( stdout, "%s\n", pRes );
1975}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdPrintFromTruth2()

void Dau_DsdPrintFromTruth2 ( word * pTruth,
int nVarsInit )

Definition at line 1976 of file dauDsd.c.

1977{
1978 char pRes[DAU_MAX_STR];
1979 word pTemp[DAU_MAX_WORD];
1980 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1981 Dau_DsdDecompose( pTemp, nVarsInit, 0, 1, pRes );
1982 fprintf( stdout, "%s", pRes );
1983}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdPrintFromTruthFile()

void Dau_DsdPrintFromTruthFile ( FILE * pFile,
word * pTruth,
int nVarsInit )

Definition at line 1960 of file dauDsd.c.

1961{
1962 char pRes[DAU_MAX_STR];
1963 word pTemp[DAU_MAX_WORD];
1964 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1965 Dau_DsdDecompose( pTemp, nVarsInit, 0, 1, pRes );
1966 fprintf( pFile, "%s\n", pRes );
1967}
Here is the call graph for this function:

◆ Dau_DsdTest2()

void Dau_DsdTest2 ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 637 of file dauDsd.c.

638{
639// char * p = Abc_UtilStrsav( "!(ab!(de[cf]))" );
640// char * p = Abc_UtilStrsav( "!(a![d<ecf>]b)" );
641// word t = Dau_Dsd6ToTruth( p );
642}

◆ Dau_DsdTest3()

void Dau_DsdTest3 ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 858 of file dauDsd.c.

859{
860// word t = s_Truths6[0] & s_Truths6[1] & s_Truths6[2];
861// word t = ~s_Truths6[0] | (s_Truths6[1] ^ ~s_Truths6[2]);
862// word t = (s_Truths6[1] & s_Truths6[2]) | (s_Truths6[0] & s_Truths6[3]);
863// word t = (~s_Truths6[1] & ~s_Truths6[2]) | (s_Truths6[0] ^ s_Truths6[3]);
864// word t = ((~s_Truths6[1] & ~s_Truths6[2]) | (s_Truths6[0] ^ s_Truths6[3])) ^ s_Truths6[5];
865// word t = ((s_Truths6[1] & ~s_Truths6[2]) ^ (s_Truths6[0] & s_Truths6[3])) & s_Truths6[5];
866// word t = (~(~s_Truths6[0] & ~s_Truths6[4]) & s_Truths6[2]) | (~s_Truths6[1] & ~s_Truths6[0] & ~s_Truths6[4]);
867// word t = 0x0000000000005F3F;
868// word t = 0xF3F5030503050305;
869// word t = (s_Truths6[0] & s_Truths6[1] & (s_Truths6[2] ^ s_Truths6[4])) | (~s_Truths6[0] & ~s_Truths6[1] & ~(s_Truths6[2] ^ s_Truths6[4]));
870// word t = 0x05050500f5f5f5f3;
871 word t = ABC_CONST(0x9ef7a8d9c7193a0f);
872 char * p = Dau_DsdPerform( t );
873 word t2 = Dau_Dsd6ToTruth( p );
874 if ( t != t2 )
875 printf( "Verification failed.\n" );
876}
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
char * Dau_DsdPerform(word t)
Definition dauDsd.c:828
word Dau_Dsd6ToTruth(char *p)
Definition dauDsd.c:445
Here is the call graph for this function:

◆ Dau_DsdTest44()

void Dau_DsdTest44 ( )

Definition at line 1985 of file dauDsd.c.

1986{
1987 char pRes[DAU_MAX_STR];
1988// char * pStr = "(!(!a<bcd>)!(!fe))";
1989// char * pStr = "([acb]<!edf>)";
1990// char * pStr = "!(f!(b!c!(d[ea])))";
1991// char * pStr = "[!(a[be])!(c!df)]";
1992// char * pStr = "<(e<bca>)fd>";
1993// char * pStr = "[d8001{abef}c]";
1994 char * pStr = "[dc<a(cbd)(!c!b!d)>{abef}]";
1995// char * pStr3;
1996 word t = Dau_Dsd6ToTruth( pStr );
1997// return;
1998 int nNonDec = Dau_DsdDecompose( &t, 6, 1, 1, pRes );
1999// Dau_DsdNormalize( pStr2 );
2000// Dau_DsdExtract( pStr, 2, 0 );
2001 t = 0;
2002 nNonDec = 0;
2003}
Here is the call graph for this function:

◆ Dau_DsdTest555()

void Dau_DsdTest555 ( )

Definition at line 2040 of file dauDsd.c.

2041{
2042 int nVars = 10;
2043 int nWords = Abc_TtWordNum(nVars);
2044 char * pFileName = "_npn/npn/dsd10.txt";
2045 FILE * pFile = fopen( pFileName, "rb" );
2046 word Tru[2][DAU_MAX_WORD], * pTruth;
2047 char pBuffer[DAU_MAX_STR];
2048 char pRes[DAU_MAX_STR];
2049 int nSizeNonDec;
2050 int i, Counter = 0;
2051 abctime clk = Abc_Clock(), clkDec = 0, clk2;
2052// return;
2053
2054 while ( fgets( pBuffer, DAU_MAX_STR, pFile ) != NULL )
2055 {
2056 char * pStr2 = pBuffer + strlen(pBuffer)-1;
2057 if ( *pStr2 == '\n' )
2058 *pStr2-- = 0;
2059 if ( *pStr2 == '\r' )
2060 *pStr2-- = 0;
2061 if ( pBuffer[0] == 'V' || pBuffer[0] == 0 )
2062 continue;
2063 Counter++;
2064
2065 for ( i = 0; i < 1; i++ )
2066 {
2067// Dau_DsdPermute( pBuffer );
2068 pTruth = Dau_DsdToTruth( pBuffer[0] == '*' ? pBuffer + 1 : pBuffer, nVars );
2069 Abc_TtCopy( Tru[0], pTruth, nWords, 0 );
2070 Abc_TtCopy( Tru[1], pTruth, nWords, 0 );
2071 clk2 = Abc_Clock();
2072 nSizeNonDec = Dau_DsdDecompose( Tru[1], nVars, 0, 1, pRes );
2073 clkDec += Abc_Clock() - clk2;
2074 Dau_DsdNormalize( pRes );
2075// pStr2 = Dau_DsdPerform( t ); nSizeNonDec = 0;
2076 assert( nSizeNonDec == 0 );
2077 pTruth = Dau_DsdToTruth( pRes, nVars );
2078 if ( !Abc_TtEqual( pTruth, Tru[0], nWords ) )
2079 {
2080 // Kit_DsdPrintFromTruth( (unsigned *)&t, 6 );
2081 // printf( " " );
2082 // Kit_DsdPrintFromTruth( (unsigned *)&t2, 6 );
2083 printf( "%s -> %s \n", pBuffer, pRes );
2084 printf( "Verification failed.\n" );
2085 }
2086 }
2087 }
2088 printf( "Finished trying %d decompositions. ", Counter );
2089 Abc_PrintTime( 1, "Time", clkDec );
2090 Abc_PrintTime( 1, "Total", Abc_Clock() - clk );
2091
2092 Abc_PrintTime( 1, "Time1", s_Times[0] );
2093 Abc_PrintTime( 1, "Time2", s_Times[1] );
2094 Abc_PrintTime( 1, "Time3", s_Times[2] );
2095
2096 fclose( pFile );
2097}
word * Dau_DsdToTruth(char *p, int nVars)
Definition dauDsd.c:609
void Dau_DsdNormalize(char *pDsd)
Definition dauDsd.c:260
int strlen()
Here is the call graph for this function:

◆ Dau_DsdTest888()

void Dau_DsdTest888 ( )

Definition at line 2007 of file dauDsd.c.

2008{
2009 char pDsd[DAU_MAX_STR];
2010 int nVars = 9;
2011// char * pStr = "[(abc)(def)(ghi)]";
2012// char * pStr = "[a!b!(c!d[e(fg)hi])]";
2013// char * pStr = "[(abc)(def)]";
2014// char * pStr = "[(abc)(def)]";
2015// char * pStr = "[abcdefg]";
2016// char * pStr = "[<abc>(de[ghi])]";
2017 char * pStr = "(<abc>(<def><ghi>))";
2018 word * pTruth = Dau_DsdToTruth( pStr, 9 );
2019 int i, Status;
2020// Kit_DsdPrintFromTruth( (unsigned *)pTruth, 9 ); printf( "\n" );
2021/*
2022 for ( i = 0; i < 6; i++ )
2023 {
2024 unsigned uSupp = Dau_Dsd6FindSupports( NULL, pTruth, NULL, 6, i );
2025 Dau_DsdPrintSupports( uSupp, 6 );
2026 }
2027*/
2028/*
2029 printf( "\n" );
2030 for ( i = 0; i < nVars; i++ )
2031 {
2032 unsigned uSupp = Dau_DsdFindSupports( NULL, pTruth, NULL, nVars, i );
2033 Dau_DsdPrintSupports( uSupp, nVars );
2034 }
2035*/
2036 Status = Dau_DsdDecompose( pTruth, nVars, 0, 0, pDsd );
2037 i = 0;
2038}
Here is the call graph for this function:

◆ Dau_DsdToTruth()

word * Dau_DsdToTruth ( char * p,
int nVars )

Definition at line 609 of file dauDsd.c.

610{
611 int nWords = Abc_TtWordNum( nVars );
612 word ** pTtElems = Dau_DsdTtElems();
613 word * pRes = pTtElems[DAU_MAX_VAR];
614 assert( nVars <= DAU_MAX_VAR );
615 if ( Dau_DsdIsConst0(p) )
616 Abc_TtConst0( pRes, nWords );
617 else if ( Dau_DsdIsConst1(p) )
618 Abc_TtConst1( pRes, nWords );
619 else
620 Dau_DsdToTruth_rec( p, &p, Dau_DsdComputeMatches(p), pTtElems, pRes, nVars );
621 assert( *++p == 0 );
622 return pRes;
623}
void Dau_DsdToTruth_rec(char *pStr, char **p, int *pMatches, word **pTtElems, word *pRes, int nVars)
Definition dauDsd.c:535
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdToTruth_rec()

void Dau_DsdToTruth_rec ( char * pStr,
char ** p,
int * pMatches,
word ** pTtElems,
word * pRes,
int nVars )

Definition at line 535 of file dauDsd.c.

536{
537 int nWords = Abc_TtWordNum( nVars );
538 int fCompl = 0;
539 if ( **p == '!' )
540 (*p)++, fCompl = 1;
541 if ( **p >= 'a' && **p <= 'z' ) // var
542 {
543 assert( **p - 'a' >= 0 && **p - 'a' < nVars );
544 Abc_TtCopy( pRes, pTtElems[**p - 'a'], nWords, fCompl );
545 return;
546 }
547 if ( **p == '(' ) // and/or
548 {
549 char * q = pStr + pMatches[ *p - pStr ];
550 word pTtTemp[DAU_MAX_WORD];
551 assert( **p == '(' && *q == ')' );
552 Abc_TtConst1( pRes, nWords );
553 for ( (*p)++; *p < q; (*p)++ )
554 {
555 Dau_DsdToTruth_rec( pStr, p, pMatches, pTtElems, pTtTemp, nVars );
556 Abc_TtAnd( pRes, pRes, pTtTemp, nWords, 0 );
557 }
558 assert( *p == q );
559 if ( fCompl ) Abc_TtNot( pRes, nWords );
560 return;
561 }
562 if ( **p == '[' ) // xor
563 {
564 char * q = pStr + pMatches[ *p - pStr ];
565 word pTtTemp[DAU_MAX_WORD];
566 assert( **p == '[' && *q == ']' );
567 Abc_TtConst0( pRes, nWords );
568 for ( (*p)++; *p < q; (*p)++ )
569 {
570 Dau_DsdToTruth_rec( pStr, p, pMatches, pTtElems, pTtTemp, nVars );
571 Abc_TtXor( pRes, pRes, pTtTemp, nWords, 0 );
572 }
573 assert( *p == q );
574 if ( fCompl ) Abc_TtNot( pRes, nWords );
575 return;
576 }
577 if ( **p == '<' ) // mux
578 {
579 char * q = pStr + pMatches[ *p - pStr ];
580 word pTtTemp[3][DAU_MAX_WORD];
581 int i;
582 assert( **p == '<' && *q == '>' );
583 for ( i = 0, (*p)++; *p < q; (*p)++, i++ )
584 Dau_DsdToTruth_rec( pStr, p, pMatches, pTtElems, pTtTemp[i], nVars );
585 assert( i == 3 );
586 Abc_TtMux( pRes, pTtTemp[0], pTtTemp[1], pTtTemp[2], nWords );
587 assert( *p == q );
588 if ( fCompl ) Abc_TtNot( pRes, nWords );
589 return;
590 }
591 if ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') )
592 {
593 word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], pFunc[DAU_MAX_WORD];
594 char * q;
595 int i, nVarsF = Abc_TtReadHex( pFunc, *p );
596 *p += Abc_TtHexDigitNum( nVarsF );
597 q = pStr + pMatches[ *p - pStr ];
598 assert( **p == '{' && *q == '}' );
599 for ( i = 0, (*p)++; *p < q; (*p)++, i++ )
600 Dau_DsdToTruth_rec( pStr, p, pMatches, pTtElems, pFanins[i], nVars );
601 assert( i == nVarsF );
602 assert( *p == q );
603 Dau_DsdTruthCompose_rec( pFunc, pFanins, pRes, nVarsF, nWords );
604 if ( fCompl ) Abc_TtNot( pRes, nWords );
605 return;
606 }
607 assert( 0 );
608}
void Dau_DsdTruthCompose_rec(word *pFunc, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
Definition dauDsd.c:501
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdTruth6Compose_rec()

void Dau_DsdTruth6Compose_rec ( word Func,
word pFanins[DAU_MAX_VAR][DAU_MAX_WORD],
word * pRes,
int nVars,
int nWordsR )

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

Synopsis [Computes truth table for the DSD formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 469 of file dauDsd.c.

470{
471 if ( Func == 0 )
472 {
473 Abc_TtConst0( pRes, nWordsR );
474 return;
475 }
476 if ( Func == ~(word)0 )
477 {
478 Abc_TtConst1( pRes, nWordsR );
479 return;
480 }
481 assert( nVars > 0 );
482 if ( --nVars == 0 )
483 {
484 assert( Func == s_Truths6[0] || Func == s_Truths6Neg[0] );
485 Abc_TtCopy( pRes, pFanins[0], nWordsR, Func == s_Truths6Neg[0] );
486 return;
487 }
488 if ( !Abc_Tt6HasVar(Func, nVars) )
489 {
490 Dau_DsdTruth6Compose_rec( Func, pFanins, pRes, nVars, nWordsR );
491 return;
492 }
493 {
494 word pTtTemp[2][DAU_MAX_WORD];
495 Dau_DsdTruth6Compose_rec( Abc_Tt6Cofactor0(Func, nVars), pFanins, pTtTemp[0], nVars, nWordsR );
496 Dau_DsdTruth6Compose_rec( Abc_Tt6Cofactor1(Func, nVars), pFanins, pTtTemp[1], nVars, nWordsR );
497 Abc_TtMux( pRes, pFanins[nVars], pTtTemp[1], pTtTemp[0], nWordsR );
498 return;
499 }
500}
void Dau_DsdTruth6Compose_rec(word Func, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
Definition dauDsd.c:469
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dau_DsdTruthCompose_rec()

void Dau_DsdTruthCompose_rec ( word * pFunc,
word pFanins[DAU_MAX_VAR][DAU_MAX_WORD],
word * pRes,
int nVars,
int nWordsR )

Definition at line 501 of file dauDsd.c.

502{
503 int nWordsF;
504 if ( nVars <= 6 )
505 {
506 Dau_DsdTruth6Compose_rec( pFunc[0], pFanins, pRes, nVars, nWordsR );
507 return;
508 }
509 nWordsF = Abc_TtWordNum( nVars );
510 assert( nWordsF > 1 );
511 if ( Abc_TtIsConst0(pFunc, nWordsF) )
512 {
513 Abc_TtConst0( pRes, nWordsR );
514 return;
515 }
516 if ( Abc_TtIsConst1(pFunc, nWordsF) )
517 {
518 Abc_TtConst1( pRes, nWordsR );
519 return;
520 }
521 if ( !Abc_TtHasVar( pFunc, nVars, nVars-1 ) )
522 {
523 Dau_DsdTruthCompose_rec( pFunc, pFanins, pRes, nVars-1, nWordsR );
524 return;
525 }
526 {
527 word pTtTemp[2][DAU_MAX_WORD];
528 nVars--;
529 Dau_DsdTruthCompose_rec( pFunc, pFanins, pTtTemp[0], nVars, nWordsR );
530 Dau_DsdTruthCompose_rec( pFunc + nWordsF/2, pFanins, pTtTemp[1], nVars, nWordsR );
531 Abc_TtMux( pRes, pFanins[nVars], pTtTemp[1], pTtTemp[0], nWordsR );
532 return;
533 }
534}
Here is the call graph for this function:
Here is the caller graph for this function: