diff options
Diffstat (limited to 'src/misc/util/abc_global.h')
-rw-r--r-- | src/misc/util/abc_global.h | 133 |
1 files changed, 125 insertions, 8 deletions
diff --git a/src/misc/util/abc_global.h b/src/misc/util/abc_global.h index 3c6ca9aa..aca9a509 100644 --- a/src/misc/util/abc_global.h +++ b/src/misc/util/abc_global.h @@ -24,10 +24,11 @@ //////////////////////////////////////////////////////////////////////// /// INCLUDES /// //////////////////////////////////////////////////////////////////////// - + #ifdef _WIN32 #define inline __inline // compatible with MS VS 6.0 #pragma warning(disable : 4152) // warning C4152: nonstandard extension, function/data pointer conversion in expression +#pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union #pragma warning(disable : 4244) // warning C4244: '+=' : conversion from 'int ' to 'unsigned short ', possible loss of data #pragma warning(disable : 4514) // warning C4514: 'Vec_StrPop' : unreferenced inline function has been removed #pragma warning(disable : 4710) // warning C4710: function 'Vec_PtrGrow' not inlined @@ -51,13 +52,62 @@ #include <crtdbg.h> #endif +#if !defined(___unused) +#if defined(__GNUC__) +#define ___unused __attribute__ ((__unused__)) +#else +#define ___unused +#endif +#endif + +/* +#ifdef __cplusplus +#error "C++ code" +#else +#error "C code" +#endif +*/ + +#include <time.h> +#include <stdarg.h> + +#ifndef __cplusplus +typedef int bool; +#endif + //////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// +/// NAMESPACES /// //////////////////////////////////////////////////////////////////////// +//#define ABC_NAMESPACE xxx + #ifdef __cplusplus -extern "C" { -#endif +# ifdef ABC_NAMESPACE +# define ABC_NAMESPACE_HEADER_START namespace ABC_NAMESPACE { +# define ABC_NAMESPACE_HEADER_END } +# define ABC_NAMESPACE_IMPL_START namespace ABC_NAMESPACE { +# define ABC_NAMESPACE_IMPL_END } +# define ABC_NAMESPACE_PREFIX ABC_NAMESPACE:: +# else +# define ABC_NAMESPACE_HEADER_START extern "C" { +# define ABC_NAMESPACE_HEADER_END } +# define ABC_NAMESPACE_IMPL_START +# define ABC_NAMESPACE_IMPL_END +# define ABC_NAMESPACE_PREFIX +# endif // #ifdef ABC_NAMESPACE +#else +# define ABC_NAMESPACE_HEADER_START +# define ABC_NAMESPACE_HEADER_END +# define ABC_NAMESPACE_IMPL_START +# define ABC_NAMESPACE_IMPL_END +# define ABC_NAMESPACE_PREFIX +#endif // #ifdef __cplusplus + +//////////////////////////////////////////////////////////////////////// +/// PARAMETERS /// +//////////////////////////////////////////////////////////////////////// + +ABC_NAMESPACE_HEADER_START //////////////////////////////////////////////////////////////////////// /// BASIC TYPES /// @@ -144,10 +194,13 @@ typedef unsigned __int64 ABC_UINT64_T; #error unknown platform #endif /* defined(PLATFORM) */ +typedef ABC_UINT64_T word; + //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// + #define ABC_ABS(a) ((a) < 0 ? -(a) : (a)) #define ABC_MAX(a,b) ((a) > (b) ? (a) : (b)) #define ABC_MIN(a,b) ((a) < (b) ? (a) : (b)) @@ -157,8 +210,8 @@ typedef unsigned __int64 ABC_UINT64_T; #define ABC_PRTr(a,t) (printf("%s = ", (a)), printf("%7.2f sec\r", (float)(t)/(float)(CLOCKS_PER_SEC))) #define ABC_PRTn(a,t) (printf("%s = ", (a)), printf("%6.2f sec ", (float)(t)/(float)(CLOCKS_PER_SEC))) #define ABC_PRTP(a,t,T) (printf("%s = ", (a)), printf("%7.2f sec (%6.2f %%)\n", (float)(t)/(float)(CLOCKS_PER_SEC), (T)? 100.0*(t)/(T) : 0.0)) -#define ABC_PRM(a,f) (printf("%s = ", (a)), printf("%7.2f Mb ", 1.0*(f)/(1<<20))) - +#define ABC_PRM(a,f) (printf("%s = ", (a)), printf("%7.3f Mb ", 1.0*(f)/(1<<20))) +#define ABC_PRMP(a,f,F) (printf("%s = ", (a)), printf("%7.3f Mb (%6.2f %%) ", (1.0*(f)/(1<<20)), ((F)? 100.0*(f)/(F) : 0.0) ) ) //#define ABC_USE_MEM_REC 1 @@ -171,7 +224,9 @@ typedef unsigned __int64 ABC_UINT64_T; ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \ ((type *) malloc(sizeof(type) * (num)))) #else +ABC_NAMESPACE_HEADER_END #include "utilMem.h" +ABC_NAMESPACE_HEADER_START #define ABC_ALLOC(type, num) ((type *) Util_MemRecAlloc(malloc(sizeof(type) * (num)))) #define ABC_CALLOC(type, num) ((type *) Util_MemRecAlloc(calloc((num), sizeof(type)))) #define ABC_FALLOC(type, num) ((type *) memset(Util_MemRecAlloc(malloc(sizeof(type) * (num))), 0xff, sizeof(type) * (num))) @@ -181,9 +236,71 @@ typedef unsigned __int64 ABC_UINT64_T; ((type *) Util_MemRecAlloc(malloc(sizeof(type) * (num))))) #endif -#ifdef __cplusplus + +enum Abc_VerbLevel +{ + ABC_PROMPT = -2, + ABC_ERROR = -1, + ABC_WARNING = 0, + ABC_STANDARD = 1, + ABC_VERBOSE = 2 +}; + +static inline void Abc_Print( int level, const char * format, ... ) +{ + va_list args; +// if ( level > -2 ) +// return; + if ( level == ABC_ERROR ) + printf( "Error: " ); + else if ( level == ABC_WARNING ) + printf( "Warning: " ); + va_start( args, format ); + vprintf( format, args ); + va_end( args ); +} + +static inline void Abc_PrintTime( int level, const char * pStr, int time ) +{ + if ( level == ABC_ERROR ) + printf( "Error: " ); + else if ( level == ABC_WARNING ) + printf( "Warning: " ); + ABC_PRT( pStr, time ); } -#endif + +static inline void Abc_PrintTimeP( int level, const char * pStr, int time, int Time ) +{ + if ( level == ABC_ERROR ) + printf( "Error: " ); + else if ( level == ABC_WARNING ) + printf( "Warning: " ); + ABC_PRTP( pStr, time, Time ); +} + +static inline void Abc_PrintMemoryP( int level, const char * pStr, int time, int Time ) +{ + if ( level == ABC_ERROR ) + printf( "Error: " ); + else if ( level == ABC_WARNING ) + printf( "Warning: " ); + ABC_PRMP( pStr, time, Time ); +} + + +// sequential counter-example +typedef struct Abc_Cex_t_ Abc_Cex_t; +struct Abc_Cex_t_ +{ + int iPo; // the zero-based number of PO, for which verification failed + int iFrame; // the zero-based number of the time-frame, for which verificaiton failed + int nRegs; // the number of registers in the miter + int nPis; // the number of primary inputs in the miter + int nBits; // the number of words of bit data used + unsigned pData[0]; // the cex bit data (the number of bits: nRegs + (iFrame+1) * nPis) +}; + +ABC_NAMESPACE_HEADER_END #endif |