summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2019-11-09 10:30:02 +0200
committerAlan Mishchenko <alanmi@berkeley.edu>2019-11-09 10:30:02 +0200
commite9896a23e3135cf884e95bb2c9fcfd433639eca6 (patch)
tree01c54cee20582a2953202be3e40a76f6c9baff3a /src
parente9de9902341274b328215b38c53b449ef49063cb (diff)
downloadabc-e9896a23e3135cf884e95bb2c9fcfd433639eca6.tar.gz
abc-e9896a23e3135cf884e95bb2c9fcfd433639eca6.tar.bz2
abc-e9896a23e3135cf884e95bb2c9fcfd433639eca6.zip
Adding macro to disable bridge output and APIs by popular demand.
Diffstat (limited to 'src')
-rw-r--r--src/base/acb/acbUtil.c4
-rw-r--r--src/misc/extra/extraUtilMisc.c144
-rw-r--r--src/misc/util/abc_global.h95
3 files changed, 231 insertions, 12 deletions
diff --git a/src/base/acb/acbUtil.c b/src/base/acb/acbUtil.c
index ecf84bb6..1b6f1039 100644
--- a/src/base/acb/acbUtil.c
+++ b/src/base/acb/acbUtil.c
@@ -652,8 +652,8 @@ int Acb_NtkExtract( char * pFileName0, char * pFileName1, int fVerbose,
*pvNodes = Acb_NtkCollectCopies( pNtkF, pGiaF, pvNodesR );
RetValue = 1;
}
- if ( pNtkF->pDesign ) Acb_ManFree( pNtkF->pDesign );
- if ( pNtkG->pDesign ) Acb_ManFree( pNtkG->pDesign );
+ if ( pNtkF ) Acb_ManFree( pNtkF->pDesign );
+ if ( pNtkG ) Acb_ManFree( pNtkG->pDesign );
return RetValue;
}
diff --git a/src/misc/extra/extraUtilMisc.c b/src/misc/extra/extraUtilMisc.c
index db24a418..1df6c5a3 100644
--- a/src/misc/extra/extraUtilMisc.c
+++ b/src/misc/extra/extraUtilMisc.c
@@ -21,6 +21,7 @@
#include <math.h>
#include "extra.h"
+#include "misc/vec/vec.h"
ABC_NAMESPACE_IMPL_START
@@ -2571,6 +2572,149 @@ void Extra_NtkPowerTest()
}
}
+
+/**Function*************************************************************
+
+ Synopsis [Tranposing bit matrix.]
+
+ Description [Borrowed from "Hacker's Delight", by Henry S. Warren Jr.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Extra_Transpose64Simple( word A[64], word B[64] )
+{
+ int i, k;
+ for ( i = 0; i < 64; i++ )
+ B[i] = 0;
+ for ( i = 0; i < 64; i++ )
+ for ( k = 0; k < 64; k++ )
+ if ( (A[i] >> k) & 1 )
+ B[k] |= ((word)1 << (63-i));
+}
+void Extra_Transpose32( unsigned a[32] )
+{
+ int j, k;
+ unsigned long m, t;
+ for ( j = 16, m = 0x0000FFFF; j; j >>= 1, m ^= m << j )
+ {
+ for ( k = 0; k < 32; k = ((k | j) + 1) & ~j )
+ {
+ t = (a[k] ^ (a[k|j] >> j)) & m;
+ a[k] ^= t;
+ a[k|j] ^= (t << j);
+ }
+ }
+}
+void Extra_Transpose64( word A[64] )
+{
+ int j, k;
+ word t, m = 0x00000000FFFFFFFF;
+ for ( j = 32; j != 0; j = j >> 1, m = m ^ (m << j) )
+ {
+ for ( k = 0; k < 64; k = (k + j + 1) & ~j )
+ {
+ t = (A[k] ^ (A[k+j] >> j)) & m;
+ A[k] = A[k] ^ t;
+ A[k+j] = A[k+j] ^ (t << j);
+ }
+ }
+}
+void Extra_Transpose64p( word * A[64] )
+{
+ int j, k;
+ word t, m = 0x00000000FFFFFFFF;
+ for ( j = 32; j != 0; j = j >> 1, m = m ^ (m << j) )
+ {
+ for ( k = 0; k < 64; k = (k + j + 1) & ~j )
+ {
+ t = (A[k][0] ^ (A[k+j][0] >> j)) & m;
+ A[k][0] = A[k][0] ^ t;
+ A[k+j][0] = A[k+j][0] ^ (t << j);
+ }
+ }
+}
+void Extra_BitMatrixTransposeP( Vec_Wrd_t * vSimsIn, int nWordsIn, Vec_Wrd_t * vSimsOut, int nWordsOut )
+{
+ word * pM[64]; int i, y, x;
+ assert( Vec_WrdSize(vSimsIn) == Vec_WrdSize(vSimsOut) );
+ assert( Vec_WrdSize(vSimsIn) / nWordsIn == 64 * nWordsOut );
+ assert( Vec_WrdSize(vSimsOut) / nWordsOut == 64 * nWordsIn );
+ for ( y = 0; y < nWordsIn; y++ )
+ for ( x = 0; x < nWordsOut; x++ )
+ {
+ for ( i = 0; i < 64; i++ )
+ {
+ pM[i] = Vec_WrdEntryP( vSimsOut, (64*y+i)*nWordsOut + x );
+ pM[i][0] = Vec_WrdEntry ( vSimsIn, (64*x+i)*nWordsIn + y );
+ }
+ Extra_Transpose64p( pM );
+ }
+}
+void Extra_BitMatrixTransposePP( Vec_Ptr_t * vSimsIn, int nWordsIn, Vec_Wrd_t * vSimsOut, int nWordsOut )
+{
+ word * pM[64]; int i, y, x;
+ assert( Vec_WrdSize(vSimsOut) / nWordsOut == 64 * nWordsIn );
+ for ( y = 0; y < nWordsIn; y++ )
+ for ( x = 0; x < nWordsOut; x++ )
+ {
+ for ( i = 0; i < 64; i++ )
+ {
+ pM[i] = Vec_WrdEntryP( vSimsOut, (64*y+i)*nWordsOut + x );
+ pM[i][0] = ((word *)Vec_PtrEntry( vSimsIn, 64*x+i ))[y];
+ }
+ Extra_Transpose64p( pM );
+ }
+}
+void Extra_BitMatrixTransposeTest()
+{
+ int nWordsIn = 1;
+ int nWordsOut = 2;
+ int i, k, nItems = 64 * nWordsIn * nWordsOut;
+
+ Vec_Wrd_t * vSimsIn = Vec_WrdStart( nItems );
+ Vec_Wrd_t * vSimsOut = Vec_WrdStart( nItems );
+
+ Abc_RandomW(1);
+ for ( i = 0; i < nItems; i++ )
+ Vec_WrdWriteEntry( vSimsIn, i, Abc_RandomW(0) );
+
+ Extra_BitMatrixTransposeP( vSimsIn, nWordsIn, vSimsOut, nWordsOut );
+
+ nItems = Vec_WrdSize(vSimsIn) / nWordsIn;
+ for ( i = 0; i < nItems; i++ )
+ {
+ if ( i%64 == 0 )
+ Abc_Print( 1, "\n" );
+ for ( k = 0; k < nWordsIn; k++ )
+ {
+ Extra_PrintBinary( stdout, (unsigned *)Vec_WrdEntryP(vSimsIn, i*nWordsIn+k), 64 );
+ Abc_Print( 1, " " );
+ }
+ Abc_Print( 1, "\n" );
+ }
+ Abc_Print( 1, "\n" );
+
+ nItems = Vec_WrdSize(vSimsOut) / nWordsOut;
+ for ( i = 0; i < nItems; i++ )
+ {
+ if ( i%64 == 0 )
+ Abc_Print( 1, "\n" );
+ for ( k = 0; k < nWordsOut; k++ )
+ {
+ Extra_PrintBinary( stdout, (unsigned *)Vec_WrdEntryP(vSimsOut, i*nWordsOut+k), 64 );
+ Abc_Print( 1, " " );
+ }
+ Abc_Print( 1, "\n" );
+ }
+ Abc_Print( 1, "\n" );
+
+ Vec_WrdFree( vSimsIn );
+ Vec_WrdFree( vSimsOut );
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/util/abc_global.h b/src/misc/util/abc_global.h
index 811103f2..aac1515b 100644
--- a/src/misc/util/abc_global.h
+++ b/src/misc/util/abc_global.h
@@ -25,6 +25,10 @@
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
+#ifndef ABC_USE_BRIDGE
+#define ABC_USE_BRIDGE
+#endif
+
#ifdef _WIN32
#ifndef __MINGW32__
#define inline __inline // compatible with MS VS 6.0
@@ -284,8 +288,10 @@ static inline int Abc_Base2Log( unsigned n ) { int r; if ( n <
static inline int Abc_Base10Log( unsigned n ) { int r; if ( n < 2 ) return (int)n; for ( r = 0, n--; n; n /= 10, r++ ) {}; return r; }
static inline int Abc_Base16Log( unsigned n ) { int r; if ( n < 2 ) return (int)n; for ( r = 0, n--; n; n /= 16, r++ ) {}; return r; }
static inline char * Abc_UtilStrsav( char * s ) { return s ? strcpy(ABC_ALLOC(char, strlen(s)+1), s) : NULL; }
+static inline int Abc_BitByteNum( int nBits ) { return (nBits>>3) + ((nBits&7) > 0); }
static inline int Abc_BitWordNum( int nBits ) { return (nBits>>5) + ((nBits&31) > 0); }
static inline int Abc_Bit6WordNum( int nBits ) { return (nBits>>6) + ((nBits&63) > 0); }
+static inline int Abc_TruthByteNum( int nVars ) { return nVars <= 3 ? 1 : (1 << (nVars - 3)); }
static inline int Abc_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
static inline int Abc_Truth6WordNum( int nVars ) { return nVars <= 6 ? 1 : (1 << (nVars - 6)); }
static inline int Abc_InfoHasBit( unsigned * p, int i ) { return (p[(i)>>5] & (unsigned)(1<<((i) & 31))) > 0; }
@@ -333,16 +339,6 @@ static inline abctime Abc_Clock()
#endif
}
-// bridge communication
-#define BRIDGE_NETLIST 106
-#define BRIDGE_ABS_NETLIST 107
-extern int Gia_ManToBridgeText( FILE * pFile, int Size, unsigned char * pBuffer );
-extern int Gia_ManToBridgeAbsNetlist( FILE * pFile, void * p, int pkg_type );
-
-// string printing
-extern char * vnsprintf(const char* format, va_list args);
-extern char * nsprintf(const char* format, ...);
-
// misc printing procedures
enum Abc_VerbLevel
@@ -353,6 +349,20 @@ enum Abc_VerbLevel
ABC_STANDARD = 1,
ABC_VERBOSE = 2
};
+
+
+#ifdef ABC_USE_BRIDGE
+
+// bridge communication
+#define BRIDGE_NETLIST 106
+#define BRIDGE_ABS_NETLIST 107
+extern int Gia_ManToBridgeText( FILE * pFile, int Size, unsigned char * pBuffer );
+extern int Gia_ManToBridgeAbsNetlist( FILE * pFile, void * p, int pkg_type );
+
+// string printing
+extern char * vnsprintf(const char* format, va_list args);
+extern char * nsprintf(const char* format, ...);
+
static inline void Abc_Print( int level, const char * format, ... )
{
extern ABC_DLL int Abc_FrameIsBridgeMode();
@@ -385,6 +395,23 @@ static inline void Abc_Print( int level, const char * format, ... )
va_end( args );
}
+#else
+
+static inline void Abc_Print( int level, const char * format, ... )
+{
+ va_list args;
+ va_start( args, format );
+ if ( level == ABC_ERROR )
+ printf( "Error: " );
+ else if ( level == ABC_WARNING )
+ printf( "Warning: " );
+ vprintf( format, args );
+ va_end( args );
+}
+
+#endif
+
+
static inline void Abc_PrintInt( int i )
{
double v3 = (double)i/1000;
@@ -410,6 +437,7 @@ static inline void Abc_PrintInt( int i )
Abc_Print( 1, "%4.0fm", v6 );
}
+
static inline void Abc_PrintTime( int level, const char * pStr, abctime time )
{
ABC_PRT( pStr, time );
@@ -452,6 +480,53 @@ static inline int Abc_PrimeCudd( unsigned int p )
} // end of Cudd_Prime
+// Creates a sequence of random numbers.
+// http://www.codeproject.com/KB/recipes/SimpleRNG.aspx
+
+#define NUMBER1 3716960521u
+#define NUMBER2 2174103536u
+
+static inline unsigned Abc_Random( int fReset )
+{
+ static unsigned int m_z = NUMBER1;
+ static unsigned int m_w = NUMBER2;
+ if ( fReset )
+ {
+ m_z = NUMBER1;
+ m_w = NUMBER2;
+ }
+ m_z = 36969 * (m_z & 65535) + (m_z >> 16);
+ m_w = 18000 * (m_w & 65535) + (m_w >> 16);
+ return (m_z << 16) + m_w;
+}
+static inline word Abc_RandomW( int fReset )
+{
+ return ((word)Abc_Random(fReset) << 32) | ((word)Abc_Random(fReset) << 0);
+}
+
+// the returned buffer has 32 unused bytes at the end, filled with zeros
+static inline void * Abc_FileReadContents( char * pFileName, int * pnFileSize )
+{
+ int RetValue, nFileSize;
+ char * pBuffer;
+ FILE * pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ return NULL;
+ // get the file size, in bytes
+ fseek( pFile, 0, SEEK_END );
+ nFileSize = ftell( pFile );
+ if ( pnFileSize )
+ *pnFileSize = nFileSize;
+ rewind( pFile );
+ // load the contents of the file into memory
+ pBuffer = ABC_ALLOC( char, nFileSize + 32 );
+ RetValue = fread( pBuffer, 1, nFileSize, pFile );
+ memset( pBuffer + nFileSize, 0, 32 );
+ assert( RetValue == nFileSize );
+ fclose( pFile );
+ return (void *)pBuffer;
+}
+
// sorting
extern void Abc_MergeSort( int * pInput, int nSize );