summaryrefslogtreecommitdiffstats
path: root/src/map/mio
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2013-03-26 20:19:50 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2013-03-26 20:19:50 -0700
commit4c0082990051610f28397067027406ff961ab91f (patch)
tree0b93751477049dba54d257d6ea0146b20a1b51b1 /src/map/mio
parentdfb065fa553e54fe00891fbeefb866be2c6dfa9d (diff)
downloadabc-4c0082990051610f28397067027406ff961ab91f.tar.gz
abc-4c0082990051610f28397067027406ff961ab91f.tar.bz2
abc-4c0082990051610f28397067027406ff961ab91f.zip
Modified SCL gate library to read/write gate formula.
Diffstat (limited to 'src/map/mio')
-rw-r--r--src/map/mio/exp.h70
-rw-r--r--src/map/mio/mio.h1
-rw-r--r--src/map/mio/mioFunc.c2
-rw-r--r--src/map/mio/mioParse.c31
4 files changed, 102 insertions, 2 deletions
diff --git a/src/map/mio/exp.h b/src/map/mio/exp.h
index 766ed38a..73a8f683 100644
--- a/src/map/mio/exp.h
+++ b/src/map/mio/exp.h
@@ -177,7 +177,7 @@ static inline word Exp_Truth6Lit( int nVars, int Lit, word * puFanins, word * pu
if ( Lit == EXP_CONST1 )
return ~0;
if ( Lit < 2 * nVars )
- return (Lit&1) ? ~puFanins[Lit/2] : puFanins[Lit/2];
+ return (Lit&1) ? ~puFanins[Lit/2] : puFanins[Lit/2];
return (Lit&1) ? ~puNodes[Lit/2-nVars] : puNodes[Lit/2-nVars];
}
static inline word Exp_Truth6( int nVars, Vec_Int_t * p, word * puFanins )
@@ -197,11 +197,77 @@ static inline word Exp_Truth6( int nVars, Vec_Int_t * p, word * puFanins )
puNodes = ABC_CALLOC( word, Exp_NodeNum(p) );
for ( i = 0; i < Exp_NodeNum(p); i++ )
puNodes[i] = Exp_Truth6Lit( nVars, Vec_IntEntry(p, 2*i+0), puFanins, puNodes ) &
- Exp_Truth6Lit( nVars, Vec_IntEntry(p, 2*i+1), puFanins, puNodes );
+ Exp_Truth6Lit( nVars, Vec_IntEntry(p, 2*i+1), puFanins, puNodes );
Res = Exp_Truth6Lit( nVars, Vec_IntEntryLast(p), puFanins, puNodes );
ABC_FREE( puNodes );
return Res;
}
+static inline void Exp_TruthLit( int nVars, int Lit, word ** puFanins, word ** puNodes, word * pRes, int nWords )
+{
+ int w;
+ if ( Lit == EXP_CONST0 )
+ for ( w = 0; w < nWords; w++ )
+ pRes[w] = 0;
+ else if ( Lit == EXP_CONST1 )
+ for ( w = 0; w < nWords; w++ )
+ pRes[w] = ~(word)0;
+ else if ( Lit < 2 * nVars )
+ for ( w = 0; w < nWords; w++ )
+ pRes[w] = (Lit&1) ? ~puFanins[Lit/2][w] : puFanins[Lit/2][w];
+ else
+ for ( w = 0; w < nWords; w++ )
+ pRes[w] = (Lit&1) ? ~puNodes[Lit/2-nVars][w] : puNodes[Lit/2-nVars][w];
+}
+static inline void Exp_Truth( int nVars, Vec_Int_t * p, word * pRes )
+{
+ static word Truth6[6] = {
+ ABC_CONST(0xAAAAAAAAAAAAAAAA),
+ ABC_CONST(0xCCCCCCCCCCCCCCCC),
+ ABC_CONST(0xF0F0F0F0F0F0F0F0),
+ ABC_CONST(0xFF00FF00FF00FF00),
+ ABC_CONST(0xFFFF0000FFFF0000),
+ ABC_CONST(0xFFFFFFFF00000000)
+ };
+ word ** puFanins, ** puNodes, * pTemp0, * pTemp1;
+ int i, w, nWords = (nVars <= 6 ? 1 : 1 << (nVars-6));
+ // create elementary variables
+ puFanins = ABC_ALLOC( word *, nVars );
+ for ( i = 0; i < nVars; i++ )
+ puFanins[i] = ABC_ALLOC( word, nWords );
+ // assign elementary truth tables
+ for ( i = 0; i < nVars; i++ )
+ if ( i < 6 )
+ for ( w = 0; w < nWords; w++ )
+ puFanins[i][w] = Truth6[i];
+ else
+ for ( w = 0; w < nWords; w++ )
+ puFanins[i][w] = (w & (1 << (i-6))) ? ~(word)0 : 0;
+ // create intermediate nodes
+ puNodes = ABC_ALLOC( word *, Exp_NodeNum(p) );
+ for ( i = 0; i < Exp_NodeNum(p); i++ )
+ puNodes[i] = ABC_ALLOC( word, nWords );
+ // evaluate the expression
+ pTemp0 = ABC_ALLOC( word, nWords );
+ pTemp1 = ABC_ALLOC( word, nWords );
+ for ( i = 0; i < Exp_NodeNum(p); i++ )
+ {
+ Exp_TruthLit( nVars, Vec_IntEntry(p, 2*i+0), puFanins, puNodes, pTemp0, nWords );
+ Exp_TruthLit( nVars, Vec_IntEntry(p, 2*i+1), puFanins, puNodes, pTemp1, nWords );
+ for ( w = 0; w < nWords; w++ )
+ puNodes[i][w] = pTemp0[w] & pTemp1[w];
+ }
+ ABC_FREE( pTemp0 );
+ ABC_FREE( pTemp1 );
+ // copy the final result
+ Exp_TruthLit( nVars, Vec_IntEntryLast(p), puFanins, puNodes, pRes, nWords );
+ // cleanup
+ for ( i = 0; i < nVars; i++ )
+ ABC_FREE( puFanins[i] );
+ ABC_FREE( puFanins );
+ for ( i = 0; i < Exp_NodeNum(p); i++ )
+ ABC_FREE( puNodes[i] );
+ ABC_FREE( puNodes );
+}
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h
index 72803cd7..ed297a1b 100644
--- a/src/map/mio/mio.h
+++ b/src/map/mio/mio.h
@@ -136,6 +136,7 @@ extern int Mio_LibraryReadExclude( char * ExcludeFile, st__table *
extern int Mio_LibraryParseFormulas( Mio_Library_t * pLib );
/*=== mioParse.c =============================================================*/
extern Vec_Int_t * Mio_ParseFormula( char * pFormInit, char ** ppVarNames, int nVars );
+extern Vec_Wrd_t * Mio_ParseFormulaTruth( char * pFormInit, char ** ppVarNames, int nVars );
extern int Mio_ParseCheckFormula( Mio_Gate_t * pGate, char * pForm );
/*=== mioSop.c =============================================================*/
extern char * Mio_LibDeriveSop( int nVars, Vec_Int_t * vExpr, Vec_Str_t * vStr );
diff --git a/src/map/mio/mioFunc.c b/src/map/mio/mioFunc.c
index c63a3794..67126749 100644
--- a/src/map/mio/mioFunc.c
+++ b/src/map/mio/mioFunc.c
@@ -257,12 +257,14 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate )
// derive expression
pGate->vExpr = Mio_ParseFormula( pGate->pForm, (char **)pPinNames, nPins );
+// Mio_ParseFormulaTruthTest( pGate->pForm, (char **)pPinNames, nPins );
// derive cover
pGate->pSop = Mio_LibDeriveSop( nPins, pGate->vExpr, pGate->pLib->vCube );
pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, pGate->pSop );
// derive truth table
if ( nPins <= 6 )
pGate->uTruth = Exp_Truth6( nPins, pGate->vExpr, NULL );
+
/*
// verify
if ( pGate->nInputs <= 6 )
diff --git a/src/map/mio/mioParse.c b/src/map/mio/mioParse.c
index 21348498..c709e589 100644
--- a/src/map/mio/mioParse.c
+++ b/src/map/mio/mioParse.c
@@ -384,6 +384,37 @@ Vec_Int_t * Mio_ParseFormula( char * pFormInit, char ** ppVarNames, int nVars )
/**Function*************************************************************
+ Synopsis [Derives the TT corresponding to the equation.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Wrd_t * Mio_ParseFormulaTruth( char * pFormInit, char ** ppVarNames, int nVars )
+{
+ Vec_Int_t * vExpr;
+ Vec_Wrd_t * vTruth;
+ // derive expression
+ vExpr = Mio_ParseFormula( pFormInit, ppVarNames, nVars );
+ // convert it into a truth table
+ vTruth = Vec_WrdStart( Abc_Truth6WordNum(nVars) );
+ Exp_Truth( nVars, vExpr, Vec_WrdArray(vTruth) );
+ Vec_IntFree( vExpr );
+ return vTruth;
+}
+void Mio_ParseFormulaTruthTest( char * pFormInit, char ** ppVarNames, int nVars )
+{
+ Vec_Wrd_t * vTruth;
+ vTruth = Mio_ParseFormulaTruth( pFormInit, ppVarNames, nVars );
+// Kit_DsdPrintFromTruth( (unsigned *)Vec_WrdArray(vTruth), nVars ); printf( "\n" );
+ Vec_WrdFree( vTruth );
+}
+
+/**Function*************************************************************
+
Synopsis [Checks if the gate's formula essentially depends on all variables.]
Description []