summaryrefslogtreecommitdiffstats
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/if/if.h12
-rw-r--r--src/map/if/ifDsd.c44
-rw-r--r--src/map/if/ifTune.c85
3 files changed, 126 insertions, 15 deletions
diff --git a/src/map/if/if.h b/src/map/if/if.h
index a94a5fe8..909a54ce 100644
--- a/src/map/if/if.h
+++ b/src/map/if/if.h
@@ -81,6 +81,7 @@ typedef struct If_Set_t_ If_Set_t;
typedef struct If_LibLut_t_ If_LibLut_t;
typedef struct If_LibBox_t_ If_LibBox_t;
typedef struct If_DsdMan_t_ If_DsdMan_t;
+typedef struct Ifn_Ntk_t_ Ifn_Ntk_t;
typedef struct Ifif_Par_t_ Ifif_Par_t;
struct Ifif_Par_t_
@@ -560,6 +561,8 @@ extern int If_DsdManSuppSize( If_DsdMan_t * p, int iDsd );
extern int If_DsdManCheckDec( If_DsdMan_t * p, int iDsd );
extern int If_DsdManReadMark( If_DsdMan_t * p, int iDsd );
extern void If_DsdManSetNewAsUseless( If_DsdMan_t * p );
+extern word If_DsdManGetFuncPerm( If_DsdMan_t * p, int iDsd );
+extern char * If_DsdManGetCellStr( If_DsdMan_t * p );
extern unsigned If_DsdManCheckXY( If_DsdMan_t * p, int iDsd, int LutSize, int fDerive, unsigned uMaskNot, int fHighEffort, int fVerbose );
extern int If_CutDsdBalanceEval( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig );
extern int If_CutDsdBalancePinDelays( If_Man_t * p, If_Cut_t * pCut, char * pPerm );
@@ -624,7 +627,14 @@ extern void If_CutRotatePins( If_Man_t * p, If_Cut_t * pCut );
extern int If_CutComputeTruth( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_t * pCut1, int fCompl0, int fCompl1 );
extern int If_CutComputeTruthPerm( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_t * pCut1, int fCompl0, int fCompl1 );
/*=== ifTune.c ===========================================================*/
-extern void * If_ManSatBuildFromCell( char * pStr, Vec_Int_t ** pvPiVars, Vec_Int_t ** pvPoVars, void ** ppNtk );
+extern Ifn_Ntk_t * Ifn_NtkParse( char * pStr );
+extern int Ifn_NtkMatch( Ifn_Ntk_t * p, word * pTruth, int nVars, int nConfls, int fVerbose, int fVeryVerbose, word * pPerm );
+extern void Ifn_NtkPrint( Ifn_Ntk_t * p );
+extern int Ifn_NtkLutSizeMax( Ifn_Ntk_t * p );
+extern int Ifn_NtkInputNum( Ifn_Ntk_t * p );
+extern void * If_ManSatBuildFromCell( char * pStr, Vec_Int_t ** pvPiVars, Vec_Int_t ** pvPoVars, Ifn_Ntk_t ** ppNtk );
+extern int If_ManSatFindCofigBits( void * pSat, Vec_Int_t * vPiVars, Vec_Int_t * vPoVars, word * pTruth, int nVars, word Perm, int nInps, Vec_Int_t * vValues );
+extern int If_ManSatDeriveGiaFromBits( void * pNew, Ifn_Ntk_t * p, Vec_Int_t * vLeaves, Vec_Int_t * vValues );
/*=== ifUtil.c ============================================================*/
extern void If_ManCleanNodeCopy( If_Man_t * p );
extern void If_ManCleanCutData( If_Man_t * p );
diff --git a/src/map/if/ifDsd.c b/src/map/if/ifDsd.c
index c4cd2a3c..c71df9e7 100644
--- a/src/map/if/ifDsd.c
+++ b/src/map/if/ifDsd.c
@@ -90,6 +90,7 @@ struct If_DsdMan_t_
Gia_Man_t * pTtGia; // GIA to represent truth tables
Vec_Int_t * vCover; // temporary memory
void * pSat; // SAT solver
+ char * pCellStr; // symbolic cell description
int nObjsPrev; // previous number of objects
int fNewAsUseless; // set new as useless
int nUniqueHits; // statistics
@@ -195,6 +196,14 @@ void If_DsdManSetNewAsUseless( If_DsdMan_t * p )
p->nObjsPrev = If_DsdManObjNum(p);
p->fNewAsUseless = 1;
}
+word If_DsdManGetFuncPerm( If_DsdMan_t * p, int iDsd )
+{
+ return p->vPerms ? Vec_WrdEntry(p->vPerms, Abc_Lit2Var(iDsd)) : 0;
+}
+char * If_DsdManGetCellStr( If_DsdMan_t * p )
+{
+ return p->pCellStr;
+}
/**Function*************************************************************
@@ -339,6 +348,7 @@ void If_DsdManFree( If_DsdMan_t * p, int fVerbose )
Gia_ManStopP( &p->pTtGia );
Vec_IntFreeP( &p->vCover );
If_ManSatUnbuild( p->pSat );
+ ABC_FREE( p->pCellStr );
ABC_FREE( p->pStore );
ABC_FREE( p->pBins );
ABC_FREE( p );
@@ -720,6 +730,8 @@ void If_DsdManPrint( If_DsdMan_t * p, char * pFileName, int Number, int Support,
If_DsdManPrintDistrib( p );
printf( "Number of inputs = %d. LUT size = %d. Marks = %s. NewAsUseless = %s. Bookmark = %d.\n",
p->nVars, p->LutSize, If_DsdManHasMarks(p)? "yes" : "no", p->fNewAsUseless? "yes" : "no", p->nObjsPrev );
+ if ( p->pCellStr )
+ printf( "Symbolic cell description: %s\n", p->pCellStr );
if ( p->pTtGia )
fprintf( pFile, "Non-DSD AIG nodes = %8d\n", Gia_ManAndNum(p->pTtGia) );
fprintf( pFile, "Unique table misses = %8d\n", p->nUniqueMisses );
@@ -1061,6 +1073,14 @@ void If_DsdManSave( If_DsdMan_t * p, char * pFileName )
fwrite( Vec_IntArray(vSets), sizeof(int)*Num, 1, pFile );
}
}
+ Num = p->vPerms ? Vec_WrdSize(p->vPerms) : 0;
+ fwrite( &Num, 4, 1, pFile );
+ if ( Num )
+ fwrite( Vec_WrdArray(p->vPerms), sizeof(word)*Num, 1, pFile );
+ Num = p->pCellStr ? strlen(p->pCellStr) : 0;
+ fwrite( &Num, 4, 1, pFile );
+ if ( Num )
+ fwrite( p->pCellStr, sizeof(char)*Num, 1, pFile );
fclose( pFile );
}
If_DsdMan_t * If_DsdManLoad( char * pFileName )
@@ -1139,6 +1159,18 @@ If_DsdMan_t * If_DsdManLoad( char * pFileName )
assert( Num2 == Vec_PtrSize(p->vTtDecs[v]) );
}
ABC_FREE( pTruth );
+ RetValue = fread( &Num, 4, 1, pFile );
+ if ( Num )
+ {
+ p->vPerms = Vec_WrdStart( Num );
+ RetValue = fread( Vec_WrdArray(p->vPerms), sizeof(word)*Num, 1, pFile );
+ }
+ RetValue = fread( &Num, 4, 1, pFile );
+ if ( Num )
+ {
+ p->pCellStr = ABC_CALLOC( char, Num + 1 );
+ RetValue = fread( p->pCellStr, sizeof(char)*Num, 1, pFile );
+ }
fclose( pFile );
return p;
}
@@ -1187,6 +1219,7 @@ void If_DsdManCleanMarks( If_DsdMan_t * p, int fVerbose )
{
If_DsdObj_t * pObj;
int i;
+ ABC_FREE( p->pCellStr );
If_DsdVecForEachObj( &p->vObjs, pObj, i )
pObj->fMark = 0;
}
@@ -2371,13 +2404,6 @@ void If_DsdManTune( If_DsdMan_t * p, int LutSize, int fFast, int fAdd, int fSpec
}
-typedef struct Ifn_Ntk_t_ Ifn_Ntk_t;
-
-extern Ifn_Ntk_t * Ifn_NtkParse( char * pStr );
-extern int Ifn_NtkMatch( Ifn_Ntk_t * p, word * pTruth, int nVars, int nConfls, int fVerbose, int fVeryVerbose, word * pPerm );
-extern void Ifn_NtkPrint( Ifn_Ntk_t * p );
-extern int Ifn_NtkLutSizeMax( Ifn_Ntk_t * p );
-extern int Ifn_NtkInputNum( Ifn_Ntk_t * p );
/**Function*************************************************************
@@ -2408,6 +2434,8 @@ void Id_DsdManTuneStr1( If_DsdMan_t * p, char * pStruct, int nConfls, int fVerbo
ABC_FREE( pNtk );
return;
}
+ ABC_FREE( p->pCellStr );
+ p->pCellStr = Abc_UtilStrsav( pStruct );
if ( If_DsdManVarNum(p) < Ifn_NtkInputNum(pNtk) )
printf( "Warning: The support of DSD manager (%d) is less than the support of the structure (%d).\n", If_DsdManVarNum(p), Ifn_NtkInputNum(pNtk) );
LutSize = Ifn_NtkLutSizeMax(pNtk);
@@ -2544,6 +2572,8 @@ void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs,
ABC_FREE( pNtk );
return;
}
+ ABC_FREE( p->pCellStr );
+ p->pCellStr = Abc_UtilStrsav( pStruct );
if ( If_DsdManVarNum(p) < Ifn_NtkInputNum(pNtk) )
printf( "Warning: The support of DSD manager (%d) is less than the support of the structure (%d).\n", If_DsdManVarNum(p), Ifn_NtkInputNum(pNtk) );
// check the largest LUT
diff --git a/src/map/if/ifTune.c b/src/map/if/ifTune.c
index 6e48448b..defafcb4 100644
--- a/src/map/if/ifTune.c
+++ b/src/map/if/ifTune.c
@@ -58,8 +58,6 @@ static char * Ifn_Symbs[16] = {
};
typedef struct Ifn_Obj_t_ Ifn_Obj_t;
-typedef struct Ifn_Ntk_t_ Ifn_Ntk_t;
-
struct Ifn_Obj_t_
{
unsigned Type : 3; // node type
@@ -621,9 +619,10 @@ sat_solver * Ifn_ManSatBuild( Ifn_Ntk_t * p, Vec_Int_t ** pvPiVars, Vec_Int_t **
Gia_ManStop( p2 );
return pSat;
}
-void * If_ManSatBuildFromCell( char * pStr, Vec_Int_t ** pvPiVars, Vec_Int_t ** pvPoVars, void ** ppNtk )
+void * If_ManSatBuildFromCell( char * pStr, Vec_Int_t ** pvPiVars, Vec_Int_t ** pvPoVars, Ifn_Ntk_t ** ppNtk )
{
Ifn_Ntk_t * p = Ifn_NtkParse( pStr );
+ Ifn_Prepare( p, NULL, p->nInps );
*ppNtk = p;
if ( p == NULL )
return NULL;
@@ -651,7 +650,7 @@ void Ifn_ManSatPrintPerm( char * pPerms, int nVars )
}
int Ifn_ManSatCheckOne( sat_solver * pSat, Vec_Int_t * vPoVars, word * pTruth, int nVars, int * pPerm, int nInps, Vec_Int_t * vLits )
{
- int v, Value, m, mNew, nMints = (1 << nVars);
+ int v, Value, m, mNew, nMints = (1 << nVars); // (1 << nInps);
assert( (1 << nInps) == Vec_IntSize(vPoVars) );
assert( nVars <= nInps );
// remap minterms
@@ -685,7 +684,7 @@ void Ifn_ManSatDeriveOne( sat_solver * pSat, Vec_Int_t * vPiVars, Vec_Int_t * vV
Vec_IntForEachEntry( vPiVars, iVar, i )
Vec_IntPush( vValues, sat_solver_var_value(pSat, iVar) );
}
-int Ifn_ManSatFindCofigBits( sat_solver * pSat, Vec_Int_t * vPiVars, Vec_Int_t * vPoVars, word * pTruth, int nVars, word Perm, int nInps, Vec_Int_t * vValues )
+int If_ManSatFindCofigBits( void * pSat, Vec_Int_t * vPiVars, Vec_Int_t * vPoVars, word * pTruth, int nVars, word Perm, int nInps, Vec_Int_t * vValues )
{
// extract permutation
int RetValue, i, pPerm[IF_MAX_FUNC_LUTSIZE];
@@ -696,7 +695,7 @@ int Ifn_ManSatFindCofigBits( sat_solver * pSat, Vec_Int_t * vPiVars, Vec_Int_t *
assert( pPerm[i] < nVars );
}
// perform SAT check
- RetValue = Ifn_ManSatCheckOne( pSat, vPoVars, pTruth, nVars, pPerm, nInps, vValues );
+ RetValue = Ifn_ManSatCheckOne( (sat_solver *)pSat, vPoVars, pTruth, nVars, pPerm, nInps, vValues );
Vec_IntClear( vValues );
if ( RetValue == 0 )
return 0;
@@ -708,7 +707,7 @@ int Ifn_ManSatFindCofigBitsTest( Ifn_Ntk_t * p, word * pTruth, int nVars, word P
Vec_Int_t * vValues = Vec_IntAlloc( 100 );
Vec_Int_t * vPiVars, * vPoVars;
sat_solver * pSat = Ifn_ManSatBuild( p, &vPiVars, &vPoVars );
- int RetValue = Ifn_ManSatFindCofigBits( pSat, vPiVars, vPoVars, pTruth, nVars, Perm, p->nInps, vValues );
+ int RetValue = If_ManSatFindCofigBits( pSat, vPiVars, vPoVars, pTruth, nVars, Perm, p->nInps, vValues );
Vec_IntPrint( vValues );
// cleanup
sat_solver_delete( pSat );
@@ -718,6 +717,78 @@ int Ifn_ManSatFindCofigBitsTest( Ifn_Ntk_t * p, word * pTruth, int nVars, word P
return RetValue;
}
+/**Function*************************************************************
+
+ Synopsis [Derive GIA using programmable bits.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int If_ManSatDeriveGiaFromBits( void * pGia, Ifn_Ntk_t * p, Vec_Int_t * vValues, Vec_Int_t * vCover )
+{
+ Gia_Man_t * pNew = (Gia_Man_t *)pGia;
+ int i, Id, k, iLit, iVar = 0, nVarsNew, pVarMap[1000];
+ assert( Gia_ManCiNum(pNew) == p->nInps && p->nParsVIni < 1000 );
+ Gia_ManForEachCiId( pNew, Id, i )
+ pVarMap[i] = Abc_Var2Lit( Id, 0 );
+ for ( i = p->nInps; i < p->nObjs; i++ )
+ {
+ int Type = p->Nodes[i].Type;
+ int nFans = p->Nodes[i].nFanins;
+ int * pFans = p->Nodes[i].Fanins;
+ int iFanin = p->Nodes[i].iFirst;
+ assert( nFans <= 6 );
+ if ( Type == IFN_DSD_AND )
+ {
+ iLit = 1;
+ for ( k = 0; k < nFans; k++ )
+ iLit = Gia_ManHashAnd( pNew, iLit, pVarMap[pFans[k]] );
+ pVarMap[i] = iLit;
+ }
+ else if ( Type == IFN_DSD_XOR )
+ {
+ iLit = 0;
+ for ( k = 0; k < nFans; k++ )
+ iLit = Gia_ManHashXor( pNew, iLit, pVarMap[pFans[k]] );
+ pVarMap[i] = iLit;
+ }
+ else if ( Type == IFN_DSD_MUX )
+ {
+ assert( nFans == 3 );
+ pVarMap[i] = Gia_ManHashMux( pNew, pVarMap[pFans[0]], pVarMap[pFans[1]], pVarMap[pFans[2]] );
+ }
+ else if ( Type == IFN_DSD_PRIME )
+ {
+ int pFaninLits[16];
+ // collect truth table
+ word uTruth = 0;
+ int nMints = (1 << nFans);
+ for ( k = 0; k < nMints; k++ )
+ if ( Vec_IntEntry( vValues, iVar++ ) )
+ uTruth |= ((word)1 << k);
+ // collect function
+ for ( k = 0; k < nFans; k++ )
+ pFaninLits[k] = pVarMap[pFans[k]];
+ // implement the function
+ nVarsNew = Abc_TtMinBase( &uTruth, pFaninLits, nFans, 6 );
+ if ( nVarsNew == 0 )
+ pVarMap[i] = (int)(uTruth & 1);
+ else
+ {
+ extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
+ Vec_Int_t Leaves = { nVarsNew, nVarsNew, pFaninLits };
+ pVarMap[i] = Kit_TruthToGia( pNew, (unsigned *)uTruth, nVarsNew, vCover, &Leaves, 1 ); // hashing enabled!!!
+ }
+ }
+ else assert( 0 );
+ }
+ assert( iVar == Vec_IntSize(vValues) );
+ return pVarMap[p->nObjs - 1];
+}
/**Function*************************************************************