summaryrefslogtreecommitdiffstats
path: root/src/misc/vec
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2020-05-15 22:11:10 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2020-05-15 22:11:10 -0700
commit0ae0744e73b978593a054e8bf80c35723c9f4b03 (patch)
tree9f01ea20fbfb39d4ed73117aa412ed0e54c4319b /src/misc/vec
parenta8bd59bd685cafc2926c314727dedee874632254 (diff)
downloadabc-0ae0744e73b978593a054e8bf80c35723c9f4b03.tar.gz
abc-0ae0744e73b978593a054e8bf80c35723c9f4b03.tar.bz2
abc-0ae0744e73b978593a054e8bf80c35723c9f4b03.zip
Experimental resubstitution.
Diffstat (limited to 'src/misc/vec')
-rw-r--r--src/misc/vec/vecInt.h2
-rw-r--r--src/misc/vec/vecWrd.h119
2 files changed, 121 insertions, 0 deletions
diff --git a/src/misc/vec/vecInt.h b/src/misc/vec/vecInt.h
index 7125593b..01fb3175 100644
--- a/src/misc/vec/vecInt.h
+++ b/src/misc/vec/vecInt.h
@@ -63,6 +63,8 @@ struct Vec_Int_t_
for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
#define Vec_IntForEachEntryTwo( vVec1, vVec2, Entry1, Entry2, i ) \
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
+#define Vec_IntForEachEntryTwoStart( vVec1, vVec2, Entry1, Entry2, i, Start ) \
+ for ( i = Start; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
#define Vec_IntForEachEntryDoubleStart( vVec, Entry1, Entry2, i, Start ) \
diff --git a/src/misc/vec/vecWrd.h b/src/misc/vec/vecWrd.h
index e123c054..3e25c066 100644
--- a/src/misc/vec/vecWrd.h
+++ b/src/misc/vec/vecWrd.h
@@ -167,6 +167,32 @@ static inline Vec_Wrd_t * Vec_WrdStartRandom( int nSize )
vSims->pArray[i] = Abc_RandomW(0);
return vSims;
}
+static inline Vec_Wrd_t * Vec_WrdStartTruthTables( int nVars )
+{
+ Vec_Wrd_t * p;
+ unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
+ int i, k, nWords;
+ nWords = nVars <= 6 ? 1 : (1 << (nVars - 6));
+ p = Vec_WrdStart( nWords * nVars );
+ for ( i = 0; i < nVars; i++ )
+ {
+ unsigned * pTruth = (unsigned *)(p->pArray + nWords * i);
+ if ( i < 5 )
+ {
+ for ( k = 0; k < 2*nWords; k++ )
+ pTruth[k] = Masks[i];
+ }
+ else
+ {
+ for ( k = 0; k < 2*nWords; k++ )
+ if ( k & (1 << (i-5)) )
+ pTruth[k] = ~(unsigned)0;
+ else
+ pTruth[k] = 0;
+ }
+ }
+ return p;
+}
/**Function*************************************************************
@@ -1201,6 +1227,99 @@ static inline void Vec_WrdAppend( Vec_Wrd_t * vVec1, Vec_Wrd_t * vVec2 )
Vec_WrdPush( vVec1, Entry );
}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Gia_ManSimPatWriteOne( FILE * pFile, word * pSim, int nWords )
+{
+ int k, Digit, nDigits = nWords*16;
+ for ( k = 0; k < nDigits; k++ )
+ {
+ Digit = (int)((pSim[k/16] >> ((k%16) * 4)) & 15);
+ if ( Digit < 10 )
+ fprintf( pFile, "%d", Digit );
+ else
+ fprintf( pFile, "%c", 'A' + Digit-10 );
+ }
+ fprintf( pFile, "\n" );
+}
+static inline void Vec_WrdPrintHex( Vec_Wrd_t * p, int nWords )
+{
+ int i, nNodes = Vec_WrdSize(p) / nWords;
+ assert( Vec_WrdSize(p) % nWords == 0 );
+ for ( i = 0; i < nNodes; i++ )
+ Gia_ManSimPatWriteOne( stdout, Vec_WrdEntryP(p, i*nWords), nWords );
+}
+static inline void Vec_WrdDumpHex( char * pFileName, Vec_Wrd_t * p, int nWords, int fVerbose )
+{
+ int i, nNodes = Vec_WrdSize(p) / nWords;
+ FILE * pFile = fopen( pFileName, "wb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for writing.\n", pFileName );
+ return;
+ }
+ assert( Vec_WrdSize(p) % nWords == 0 );
+ for ( i = 0; i < nNodes; i++ )
+ Gia_ManSimPatWriteOne( pFile, Vec_WrdEntryP(p, i*nWords), nWords );
+ fclose( pFile );
+ if ( fVerbose )
+ printf( "Written %d words of simulation data for %d objects into file \"%s\".\n", nWords, Vec_WrdSize(p)/nWords, pFileName );
+}
+static inline int Vec_WrdReadHexOne( char c )
+{
+ int Digit = 0;
+ if ( c >= '0' && c <= '9' )
+ Digit = c - '0';
+ else if ( c >= 'A' && c <= 'F' )
+ Digit = c - 'A' + 10;
+ else if ( c >= 'a' && c <= 'f' )
+ Digit = c - 'a' + 10;
+ else assert( 0 );
+ assert( Digit >= 0 && Digit < 16 );
+ return Digit;
+}
+static inline Vec_Wrd_t * Vec_WrdReadHex( char * pFileName, int * pnWords, int fVerbose )
+{
+ Vec_Wrd_t * p = NULL;
+ int c, nWords = -1, nChars = 0; word Num = 0;
+ FILE * pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for reading.\n", pFileName );
+ return NULL;
+ }
+ p = Vec_WrdAlloc( 1000 );
+ while ( (c = fgetc(pFile)) != EOF )
+ {
+ if ( c == '\n' && nWords == -1 )
+ nWords = Vec_WrdSize(p);
+ if ( c == '\n' || c == '\r' || c == '\t' || c == ' ' )
+ continue;
+ Num |= (word)Vec_WrdReadHexOne((char)c) << (nChars * 4);
+ if ( ++nChars < 16 )
+ continue;
+ Vec_WrdPush( p, Num );
+ nChars = 0;
+ Num = 0;
+ }
+ assert( Vec_WrdSize(p) % nWords == 0 );
+ fclose( pFile );
+ if ( pnWords )
+ *pnWords = nWords;
+ if ( fVerbose )
+ printf( "Read %d words of simulation data for %d objects.\n", nWords, Vec_WrdSize(p)/nWords );
+ return p;
+}
+
ABC_NAMESPACE_HEADER_END