Skip to content

Commit 59bb4de

Browse files
committed
Misc changes.
1 parent 5305d93 commit 59bb4de

File tree

3 files changed

+328
-0
lines changed

3 files changed

+328
-0
lines changed

src/aig/gia/giaCut.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,46 @@ Vec_Ptr_t * Gia_ManMatchCutsMany( Vec_Mem_t * vTtMem, Vec_Int_t * vMap, int nFun
11681168
return vRes;
11691169
}
11701170

1171+
/**Function*************************************************************
1172+
1173+
Synopsis [Function enumeration.]
1174+
1175+
Description []
1176+
1177+
SideEffects []
1178+
1179+
SeeAlso []
1180+
1181+
***********************************************************************/
1182+
void Gia_ManDumpCuts( Gia_Man_t * p, int nCutSize, int nCutNum, int fVerbose )
1183+
{
1184+
FILE * pFile = fopen( "input.txt", "wb" ); if ( !pFile ) return;
1185+
Gia_Sto_t * pSto = Gia_ManMatchCutsInt( p, nCutSize, nCutNum, 0 );
1186+
Vec_Int_t * vLevel; int i, k, c, * pCut, nCuts = 0, nNodes = 0;
1187+
Vec_WecForEachLevel( pSto->vCuts, vLevel, i ) if ( Vec_IntSize(vLevel) ) {
1188+
if ( !Gia_ObjIsAnd(Gia_ManObj(p, i)) )
1189+
continue;
1190+
Sdb_ForEachCut( Vec_IntArray(vLevel), pCut, k ) {
1191+
if ( pCut[0] == 1 )
1192+
continue;
1193+
fprintf( pFile, "%d ", i );
1194+
for ( c = 1; c <= pCut[0]; c++ )
1195+
fprintf( pFile, "%d ", pCut[c] );
1196+
fprintf( pFile, "1\n" );
1197+
nCuts += pCut[0];
1198+
nNodes++;
1199+
}
1200+
}
1201+
Gia_Obj_t * pObj;
1202+
Gia_ManForEachCo( p, pObj, i ) {
1203+
fprintf( pFile, "%d %d 0\n", Gia_ObjId(p, pObj), Gia_ObjFaninId0p(p, pObj) );
1204+
}
1205+
fclose( pFile );
1206+
Gia_StoFree( pSto );
1207+
if ( fVerbose )
1208+
printf( "Dumped %d cuts for %d nodes into file \"input.txt\".\n", nCuts, nNodes );
1209+
}
1210+
11711211
/**Function*************************************************************
11721212
11731213
Synopsis [Function enumeration.]

src/aig/gia/giaSimBase.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,21 @@ void Gia_ManSimPatWrite( char * pFileName, Vec_Wrd_t * vSimsIn, int nWords )
288288
SeeAlso []
289289
290290
***********************************************************************/
291+
Vec_Wrd_t * Gia_ManDeriveNodeFuncs( Gia_Man_t * p )
292+
{
293+
int nWords = Abc_Truth6WordNum( Gia_ManCiNum(p) );
294+
Vec_Wrd_t * vSims = Vec_WrdStart( nWords * Gia_ManObjNum(p) );
295+
Gia_Obj_t * pObj; int i;
296+
Gia_ManForEachCi( p, pObj, i )
297+
assert( Gia_ObjId(p, pObj) == i+1 );
298+
Vec_Ptr_t * vTruths = Vec_PtrAllocTruthTables( Gia_ManCiNum(p) );
299+
Gia_ManForEachCi( p, pObj, i )
300+
Abc_TtCopy( Vec_WrdEntryP(vSims, nWords*(i+1)), (word *)Vec_PtrEntry(vTruths, i), nWords, 0 );
301+
Vec_PtrFree( vTruths );
302+
Gia_ManForEachAnd( p, pObj, i )
303+
Gia_ManSimPatSimAnd( p, i, pObj, nWords, vSims );
304+
return vSims;
305+
}
291306
word * Gia_ManDeriveFuncs( Gia_Man_t * p )
292307
{
293308
int nVars2 = (Gia_ManCiNum(p) + 6)/2;

src/base/abci/abcDar.c

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
1919
***********************************************************************/
2020

21+
//#include <dirent.h>
22+
//#include <sys/stat.h>
23+
2124
#include "base/abc/abc.h"
2225
#include "base/main/main.h"
2326
#include "aig/gia/giaAig.h"
@@ -36,6 +39,7 @@
3639
#include "proof/pdr/pdr.h"
3740
#include "sat/bmc/bmc.h"
3841
#include "map/mio/mio.h"
42+
#include "misc/vec/vecMem.h"
3943

4044
ABC_NAMESPACE_IMPL_START
4145

@@ -4902,6 +4906,275 @@ Abc_Ntk_t * Abc_NtkDarTestNtk( Abc_Ntk_t * pNtk )
49024906

49034907
}
49044908

4909+
#if 0
4910+
4911+
/**Function*************************************************************
4912+
4913+
Synopsis []
4914+
4915+
Description []
4916+
4917+
SideEffects []
4918+
4919+
SeeAlso []
4920+
4921+
***********************************************************************/
4922+
int Data_ListDirsFilesCompareNames( char ** pp1, char ** pp2 )
4923+
{
4924+
return strcmp( *pp1, *pp2 );
4925+
}
4926+
char ** Data_ListDirsFiles(const char *path, const char *ext)
4927+
{
4928+
int iItems = 0, nItems = 1000;
4929+
char ** pRes = (char **)calloc( sizeof(char*), nItems );
4930+
DIR *dir;
4931+
struct dirent *entry;
4932+
struct stat statbuf;
4933+
4934+
// Open the directory
4935+
if ((dir = opendir(path)) == NULL) {
4936+
perror("opendir");
4937+
return NULL;
4938+
}
4939+
4940+
// Read each entry in the directory
4941+
while ((entry = readdir(dir)) != NULL) {
4942+
char full_path[1024];
4943+
snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name);
4944+
4945+
// Get the status of the entry
4946+
if (stat(full_path, &statbuf) == -1) {
4947+
perror("stat");
4948+
continue;
4949+
}
4950+
4951+
if (ext == NULL) {
4952+
// If no file extension is provided, list subdirectories
4953+
if (S_ISDIR(statbuf.st_mode)) {
4954+
// Skip "." and ".." directories
4955+
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
4956+
continue;
4957+
}
4958+
4959+
// Print the directory name
4960+
//printf("%s\n", entry->d_name);
4961+
assert( iItems < nItems );
4962+
pRes[iItems] = (char *)calloc( sizeof(char), strlen(entry->d_name)+1 );
4963+
memcpy( pRes[iItems++], entry->d_name, strlen(entry->d_name) );
4964+
}
4965+
} else {
4966+
// If file extension is provided, list files with that extension
4967+
if (S_ISREG(statbuf.st_mode)) { // Check if it's a regular file
4968+
const char *dot = strrchr(entry->d_name, '.');
4969+
if (dot && strcmp(dot + 1, ext) == 0) {
4970+
// Print the file name
4971+
//printf("%s\n", entry->d_name);
4972+
assert( iItems <= nItems );
4973+
if ( iItems == nItems ) {
4974+
pRes = ABC_REALLOC( char *, pRes, nItems *= 2 );
4975+
memset( pRes + nItems/2, 0, sizeof(char *) * nItems/2 );
4976+
}
4977+
pRes[iItems] = (char *)calloc( sizeof(char), strlen(entry->d_name)+1 );
4978+
memcpy( pRes[iItems++], entry->d_name, strlen(entry->d_name) );
4979+
}
4980+
}
4981+
}
4982+
}
4983+
4984+
qsort( (void *)pRes, (size_t)iItems, sizeof(char *), (int (*)(const void *, const void *)) Data_ListDirsFilesCompareNames );
4985+
4986+
// Close the directory
4987+
closedir(dir);
4988+
if ( iItems == 0 )
4989+
ABC_FREE( pRes );
4990+
return pRes;
4991+
}
4992+
4993+
/**Function*************************************************************
4994+
4995+
Synopsis []
4996+
4997+
Description []
4998+
4999+
SideEffects []
5000+
5001+
SeeAlso []
5002+
5003+
***********************************************************************/
5004+
Vec_Int_t * Gia_ManDeriveNodeClasses( Gia_Man_t * p, Vec_Wrd_t * vSims )
5005+
{
5006+
abctime clkStart = Abc_Clock();
5007+
int nVars = Gia_ManCiNum(p);
5008+
int nWords = Abc_Truth6WordNum( nVars );
5009+
Vec_Mem_t * vTtMem = Vec_MemAllocForTTSimple( nVars );
5010+
Vec_Int_t * vRes = Vec_IntStartFull( Gia_ManObjNum(p) );
5011+
Gia_Obj_t * pObj; int i;
5012+
for ( i = 0; i <= nVars; i++ ) {
5013+
int iFunc = Vec_MemHashInsert( vTtMem, Vec_WrdEntryP(vSims, i*nWords) );
5014+
assert( iFunc == i );
5015+
Vec_IntWriteEntry( vRes, i, i );
5016+
}
5017+
Gia_ManForEachAnd( p, pObj, i )
5018+
{
5019+
word * pTruth = Vec_WrdEntryP( vSims, i*nWords );
5020+
if ( pTruth[0] & 1 )
5021+
for ( int k = 0; k < nWords; k++ )
5022+
pTruth[k] = ~pTruth[k];
5023+
int iFunc = Vec_MemHashInsert(vTtMem, pTruth);
5024+
//assert( iFunc > nVars );
5025+
Vec_IntWriteEntry( vRes, i, iFunc );
5026+
}
5027+
printf( "Detected %d unique functions among %d nodes. ", Vec_MemEntryNum(vTtMem) - nVars - 1, Gia_ManAndNum(p) );
5028+
Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
5029+
Vec_MemFree( vTtMem );
5030+
return vRes;
5031+
}
5032+
int Gia_ManExploreNode_rec( Gia_Man_t * p, int Obj, int Repr, Vec_Int_t * vFuncs )
5033+
{
5034+
if ( Obj == Repr || Vec_IntEntry(vFuncs, Obj) == -1 )
5035+
return 0;
5036+
if ( Obj < Repr )
5037+
return 1;
5038+
if ( Gia_ObjIsTravIdCurrentId(p, Obj) )
5039+
return 1;
5040+
Gia_ObjSetTravIdCurrentId(p, Obj);
5041+
Gia_Obj_t * pObj = Gia_ManObj(p, Obj);
5042+
if ( !Gia_ManExploreNode_rec( p, Gia_ObjFaninId0(pObj, Obj), Repr, vFuncs ) )
5043+
return 0;
5044+
if ( !Gia_ManExploreNode_rec( p, Gia_ObjFaninId1(pObj, Obj), Repr, vFuncs ) )
5045+
return 0;
5046+
if ( Vec_IntEntry(vFuncs, Obj) != Obj ) {
5047+
if ( !Gia_ManExploreNode_rec( p, Vec_IntEntry(vFuncs, Obj), Repr, vFuncs ) )
5048+
return 0;
5049+
}
5050+
return 1;
5051+
}
5052+
int Gia_ManChoiceCheck( Gia_Man_t * p, Gia_Obj_t * pObj, int i, Vec_Int_t * vFuncs )
5053+
{
5054+
if ( Vec_IntEntry(vFuncs, Gia_ObjFaninId0p(p, pObj)) == -1 || Vec_IntEntry(vFuncs, Gia_ObjFaninId1p(p, pObj)) == -1 )
5055+
return 0;
5056+
if ( i == Vec_IntEntry(vFuncs, i) )
5057+
return 1;
5058+
assert( i > Vec_IntEntry(vFuncs, i) );
5059+
Gia_ManIncrementTravId( p );
5060+
if ( !Gia_ManExploreNode_rec(p, i, Vec_IntEntry(vFuncs, i), vFuncs) )
5061+
return 0;
5062+
return 1;
5063+
}
5064+
void Gia_ManChoicesClean( Gia_Man_t * p, Vec_Int_t * vFuncs )
5065+
{
5066+
Gia_Obj_t * pObj; int i;
5067+
Gia_ManForEachAnd( p, pObj, i )
5068+
if ( Vec_IntEntry(vFuncs, i) <= Gia_ManCiNum(p) || !Gia_ManChoiceCheck(p, pObj, i, vFuncs) )
5069+
Vec_IntWriteEntry( vFuncs, i, -1 );
5070+
}
5071+
Gia_Man_t * Gia_ManTransformToChoices( Gia_Man_t * p )
5072+
{
5073+
Vec_Wrd_t * Gia_ManDeriveNodeFuncs( Gia_Man_t * p );
5074+
Vec_Wrd_t * vSims = Gia_ManDeriveNodeFuncs( p );
5075+
Vec_Int_t * vFuncs = Gia_ManDeriveNodeClasses( p, vSims );
5076+
Gia_ManChoicesClean( p, vFuncs );
5077+
Vec_WrdFree( vSims );
5078+
5079+
Gia_Man_t * pNew = Gia_ManStart( Gia_ManObjNum(p) );
5080+
pNew->pName = Abc_UtilStrsav( p->pName );
5081+
pNew->pSibls = ABC_CALLOC( int, Gia_ManObjNum(p) );
5082+
Gia_ManHashAlloc( pNew );
5083+
Gia_Obj_t * pObj; int i;
5084+
Gia_ManSetPhase(p);
5085+
Gia_ManConst0(p)->Value = 0;
5086+
Gia_ManForEachCi( p, pObj, i )
5087+
pObj->Value = Gia_ManAppendCi( pNew );
5088+
Gia_ManForEachAnd( p, pObj, i ) {
5089+
if ( Vec_IntEntry(vFuncs, i) == -1 )
5090+
continue;
5091+
else if ( Vec_IntEntry(vFuncs, i) == i )
5092+
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
5093+
else {
5094+
int iFunc = Vec_IntEntry(vFuncs, i);
5095+
pNew->pSibls[i] = pNew->pSibls[iFunc];
5096+
pNew->pSibls[iFunc] = i;
5097+
pObj->Value = Abc_Var2Lit( iFunc, pObj->fPhase ^ Gia_ManObj(p, iFunc)->fPhase );
5098+
//printf( "Adding choice %d -> %d\n", iFunc, i );
5099+
}
5100+
}
5101+
Gia_ManForEachCo( p, pObj, i )
5102+
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
5103+
Vec_IntFree( vFuncs );
5104+
return pNew;
5105+
}
5106+
void Gia_ManTestAppend( Gia_Man_t * pNew, Gia_Man_t * pTwo )
5107+
{
5108+
Gia_Obj_t * pObj; int i;
5109+
assert( Gia_ManCiNum(pNew) == Gia_ManCiNum(pTwo) );
5110+
Gia_ManConst0(pTwo)->Value = 0;
5111+
Gia_ManForEachCand( pTwo, pObj, i )
5112+
{
5113+
if ( Gia_ObjIsAnd(pObj) )
5114+
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
5115+
else if ( Gia_ObjIsCi(pObj) )
5116+
pObj->Value = Gia_Obj2Lit( pNew, Gia_ManCi( pNew, Gia_ObjCioId(pObj) ) );
5117+
}
5118+
}
5119+
Gia_Man_t * Abc_NtkDarTestFiles()
5120+
{
5121+
char full_path[1024];
5122+
const char *directory_path = "temp";
5123+
const char *ext = "aig";
5124+
char ** pItems = Data_ListDirsFiles(directory_path, ext);
5125+
if ( pItems == NULL ) {
5126+
printf( "There are no files in directory \"%s\".\n", directory_path );
5127+
return NULL;
5128+
}
5129+
5130+
//for ( i = 0; pItems[i]; i++ )
5131+
// printf( "%d : %s\n", i, pItems[i] );
5132+
5133+
Gia_Obj_t * pObj; int i;
5134+
Gia_Man_t * pNew = NULL;
5135+
Gia_Man_t * pTemp = NULL;
5136+
for ( i = 0; pItems[i]; i++ )
5137+
{
5138+
snprintf(full_path, sizeof(full_path), "%s/%s", directory_path, pItems[i]);
5139+
Gia_Man_t * pTwo = Gia_AigerRead( full_path, 0, 0, 0 );
5140+
if ( i == 0 ) {
5141+
pNew = Gia_ManStart( 10000 );
5142+
pNew->pName = Abc_UtilStrsav( pTwo->pName );
5143+
pNew->pSpec = Abc_UtilStrsav( pTwo->pSpec );
5144+
for ( int k = 0; k < Gia_ManCiNum(pTwo); k++ )
5145+
Gia_ManAppendCi( pNew );
5146+
}
5147+
Gia_ManTestAppend( pNew, pTwo );
5148+
if ( i == 0 )
5149+
pTemp = pTwo;
5150+
else
5151+
Gia_ManStop( pTwo );
5152+
if ( i < 4 )
5153+
printf( "%d : %s\n", i, pItems[i] );
5154+
}
5155+
printf( "Finished reading %d files.\n", i );
5156+
Gia_ManForEachCo( pTemp, pObj, i )
5157+
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
5158+
Gia_ManStop( pTemp );
5159+
5160+
Gia_ManPrintStats( pNew, NULL );
5161+
5162+
pNew = Gia_ManTransformToChoices( pTemp = pNew );
5163+
Gia_ManStop( pTemp );
5164+
5165+
Gia_ManPrintStats( pNew, NULL );
5166+
5167+
for ( i = 0; pItems[i]; i++ )
5168+
free( pItems[i] );
5169+
free( pItems );
5170+
5171+
//Gia_AigerWrite( pNew, "all.aig", 0, 0, 0 );
5172+
//Gia_ManStop( pNew );
5173+
return pNew;
5174+
}
5175+
5176+
#endif
5177+
49055178
////////////////////////////////////////////////////////////////////////
49065179
/// END OF FILE ///
49075180
////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)