summaryrefslogtreecommitdiffstats
path: root/src/map/mio/exp.h
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/exp.h
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/exp.h')
-rw-r--r--src/map/mio/exp.h70
1 files changed, 68 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 ///