21 #ifndef ABC__misc__util__abc_global_h
22 #define ABC__misc__util__abc_global_h
30 #define inline __inline // compatible with MS VS 6.0
31 #pragma warning(disable : 4152) // warning C4152: nonstandard extension, function/data pointer conversion in expression
32 #pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union
33 #pragma warning(disable : 4244) // warning C4244: '+=' : conversion from 'int ' to 'unsigned short ', possible loss of data
34 #pragma warning(disable : 4514) // warning C4514: 'Vec_StrPop' : unreferenced inline function has been removed
35 #pragma warning(disable : 4710) // warning C4710: function 'Vec_PtrGrow' not inlined
45 #define ABC_DLLEXPORT __declspec(dllexport)
46 #define ABC_DLLIMPORT __declspec(dllimport)
53 #define ABC_DLL ABC_DLLIMPORT
59 #define _CRTDBG_MAP_ALLOC
64 #if !defined(___unused)
66 #define ___unused __attribute__ ((__unused__))
92 # define ABC_NAMESPACE_HEADER_START namespace ABC_NAMESPACE {
93 # define ABC_NAMESPACE_HEADER_END }
94 # define ABC_NAMESPACE_IMPL_START namespace ABC_NAMESPACE {
95 # define ABC_NAMESPACE_IMPL_END }
96 # define ABC_NAMESPACE_PREFIX ABC_NAMESPACE::
98 # define ABC_NAMESPACE_HEADER_START extern "C" {
99 # define ABC_NAMESPACE_HEADER_END }
100 # define ABC_NAMESPACE_IMPL_START
101 # define ABC_NAMESPACE_IMPL_END
102 # define ABC_NAMESPACE_PREFIX
103 # endif // #ifdef ABC_NAMESPACE
105 # define ABC_NAMESPACE_HEADER_START
106 # define ABC_NAMESPACE_HEADER_END
107 # define ABC_NAMESPACE_IMPL_START
108 # define ABC_NAMESPACE_IMPL_END
109 # define ABC_NAMESPACE_PREFIX
110 #endif // #ifdef __cplusplus
127 #if defined(__ccdoc__)
128 typedef platform_dependent_type ABC_PTRDIFF_T;
130 typedef long ABC_PTRDIFF_T;
132 typedef long long ABC_PTRDIFF_T;
133 #elif defined(NT) || defined(LIN) || defined(WIN32)
134 typedef int ABC_PTRDIFF_T;
136 #error unknown platform
144 #if defined(__ccdoc__)
145 typedef platform_dependent_type ABC_PTRUINT_T;
147 typedef unsigned long ABC_PTRUINT_T;
149 typedef unsigned long long ABC_PTRUINT_T;
150 #elif defined(NT) || defined(LIN) || defined(WIN32)
151 typedef unsigned int ABC_PTRUINT_T;
153 #error unknown platform
161 #if defined(__ccdoc__)
162 typedef platform_dependent_type ABC_PTRINT_T;
164 typedef long ABC_PTRINT_T;
166 typedef long long ABC_PTRINT_T;
167 #elif defined(NT) || defined(LIN) || defined(WIN32)
168 typedef int ABC_PTRINT_T;
170 #error unknown platform
176 #if defined(__ccdoc__)
177 typedef platform_dependent_type ABC_INT64_T;
179 typedef long ABC_INT64_T;
180 #elif defined(NT64) || defined(LIN)
181 typedef long long ABC_INT64_T;
182 #elif defined(WIN32) || defined(NT)
183 typedef signed __int64 ABC_INT64_T;
185 #error unknown platform
191 #if defined(__ccdoc__)
192 typedef platform_dependent_type ABC_UINT64_T;
194 typedef unsigned long ABC_UINT64_T;
195 #elif defined(NT64) || defined(LIN)
196 typedef unsigned long long ABC_UINT64_T;
197 #elif defined(WIN32) || defined(NT)
198 typedef unsigned __int64 ABC_UINT64_T;
200 #error unknown platform
204 #define ABC_CONST(number) number ## ULL
205 #else // LIN64 and windows
206 #define ABC_CONST(number) number
216 #define ABC_INFINITY (100000000)
218 #define ABC_SWAP(Type, a, b) { Type t = a; a = b; b = t; }
220 #define ABC_PRT(a,t) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec\n", 1.0*(t)/(CLOCKS_PER_SEC)))
221 #define ABC_PRTr(a,t) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec\r", 1.0*(t)/(CLOCKS_PER_SEC)))
222 #define ABC_PRTn(a,t) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec ", 1.0*(t)/(CLOCKS_PER_SEC)))
223 #define ABC_PRTP(a,t,T) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec (%6.2f %%)\n", 1.0*(t)/(CLOCKS_PER_SEC), (T)? 100.0*(t)/(T) : 0.0))
224 #define ABC_PRM(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\n", 1.0*(f)/(1<<20)))
225 #define ABC_PRMr(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\r", 1.0*(f)/(1<<20)))
226 #define ABC_PRMn(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB ", 1.0*(f)/(1<<20)))
227 #define ABC_PRMP(a,f,F) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB (%6.2f %%)\n", (1.0*(f)/(1<<20)), ((F)? 100.0*(f)/(F) : 0.0) ) )
229 #define ABC_ALLOC(type, num) ((type *) malloc(sizeof(type) * (num)))
230 #define ABC_CALLOC(type, num) ((type *) calloc((num), sizeof(type)))
231 #define ABC_FALLOC(type, num) ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))
232 #define ABC_FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
233 #define ABC_REALLOC(type, obj, num) \
234 ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
235 ((type *) malloc(sizeof(type) * (num))))
237 static inline int Abc_AbsInt(
int a ) {
return a < 0 ? -a : a; }
238 static inline int Abc_MaxInt(
int a,
int b ) {
return a > b ? a : b; }
239 static inline int Abc_MinInt(
int a,
int b ) {
return a < b ? a : b; }
243 static inline float Abc_MaxFloat(
float a,
float b ) {
return a > b ? a : b; }
244 static inline float Abc_MinFloat(
float a,
float b ) {
return a < b ? a : b; }
246 static inline double Abc_MaxDouble(
double a,
double b ) {
return a > b ? a : b; }
247 static inline double Abc_MinDouble(
double a,
double b ) {
return a < b ? a : b; }
249 static inline int Abc_Float2Int(
float Val ) {
union {
int x;
float y; } v; v.y = Val;
return v.x; }
250 static inline float Abc_Int2Float(
int Num ) {
union {
int x;
float y; } v; v.x = Num;
return v.y; }
251 static inline int Abc_Base2Log(
unsigned n ) {
int r;
if ( n < 2 )
return n;
for ( r = 0, n--; n; n >>= 1, r++ ) {};
return r; }
252 static inline int Abc_Base10Log(
unsigned n ) {
int r;
if ( n < 2 )
return n;
for ( r = 0, n--; n; n /= 10, r++ ) {};
return r; }
253 static inline int Abc_Base16Log(
unsigned n ) {
int r;
if ( n < 2 )
return n;
for ( r = 0, n--; n; n /= 16, r++ ) {};
return r; }
255 static inline int Abc_BitWordNum(
int nBits ) {
return (nBits>>5) + ((nBits&31) > 0); }
256 static inline int Abc_TruthWordNum(
int nVars ) {
return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
257 static inline int Abc_Truth6WordNum(
int nVars ) {
return nVars <= 6 ? 1 : (1 << (nVars - 6)); }
258 static inline int Abc_InfoHasBit(
unsigned *
p,
int i ) {
return (p[(i)>>5] & (1<<((i) & 31))) > 0; }
259 static inline void Abc_InfoSetBit(
unsigned *
p,
int i ) { p[(i)>>5] |= (1<<((i) & 31)); }
260 static inline void Abc_InfoXorBit(
unsigned *
p,
int i ) { p[(i)>>5] ^= (1<<((i) & 31)); }
261 static inline unsigned Abc_InfoMask(
int nVar ) {
return (~(
unsigned)0) >> (32-nVar); }
263 static inline int Abc_Var2Lit(
int Var,
int fCompl ) {
return Var + Var + fCompl; }
267 static inline int Abc_LitNotCond(
int Lit,
int c ) {
return Lit ^ (int)(c > 0); }
272 static inline int Abc_Ptr2Int(
void *
p ) {
return (
int)(ABC_PTRINT_T)p; }
273 static inline void *
Abc_Int2Ptr(
int i ) {
return (
void *)(ABC_PTRINT_T)i; }
281 #if (defined(LIN) || defined(LIN64)) && !(__APPLE__ & __MACH__) && !defined(__MINGW32__)
283 if ( clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) < 0 )
286 res += (((
abctime) ts.tv_nsec) * CLOCKS_PER_SEC) / 1000000000;
294 #define BRIDGE_NETLIST 106
295 #define BRIDGE_ABS_NETLIST 107
300 extern char *
vnsprintf(
const char* format, va_list args);
301 extern char *
nsprintf(
const char* format, ...);
313 static inline void Abc_Print(
int level,
const char * format, ... )
322 printf(
"Warning: " );
330 va_start( args, format );
338 vprintf( format, args );
344 double v3 = (double)i/1000;
345 double v6 = (double)i/1000000;
349 if ( i > -1000 && i < 1000 )
352 else if ( v3 > -9.995 && v3 < 9.995 )
354 else if ( v3 > -99.95 && v3 < 99.95 )
356 else if ( v3 > -999.5 && v3 < 999.5 )
359 else if ( v6 > -9.995 && v6 < 9.995 )
361 else if ( v6 > -99.95 && v6 < 99.95 )
363 else if ( v6 > -999.5 && v6 < 999.5 )
393 while ((
unsigned) (i * i) <= p)
static unsigned Abc_InfoMask(int nVar)
int * Abc_QuickSortCost(int *pCosts, int nSize, int fDecrease)
ABC_DLL int Abc_FrameIsBridgeMode()
static int Abc_PrimeCudd(unsigned int p)
static int Abc_Lit2LitV(int *pMap, int Lit)
static int Abc_Ptr2Int(void *p)
static float Abc_MinFloat(float a, float b)
static int Abc_Base16Log(unsigned n)
int Gia_ManToBridgeText(FILE *pFile, int Size, unsigned char *pBuffer)
static float Abc_AbsFloat(float a)
static word Abc_MinWord(word a, word b)
static char * Abc_UtilStrsav(char *s)
static int Abc_AbsInt(int a)
static int Abc_InfoHasBit(unsigned *p, int i)
static int Abc_Lit2LitL(int *pMap, int Lit)
static int Abc_Truth6WordNum(int nVars)
static void Abc_InfoXorBit(unsigned *p, int i)
static int Abc_Var2Lit(int Var, int fCompl)
void Abc_QuickSortCostData(int *pCosts, int nSize, int fDecrease, word *pData, int *pResult)
#define ABC_ALLOC(type, num)
static double Abc_AbsDouble(double a)
static int Abc_TruthWordNum(int nVars)
static void Abc_PrintMemoryP(int level, const char *pStr, int mem, int Mem)
static abctime Abc_Clock()
static int Abc_MaxInt(int a, int b)
static void Abc_PrintTimeP(int level, const char *pStr, abctime time, abctime Time)
static float Abc_MaxFloat(float a, float b)
static int Abc_LitNotCond(int Lit, int c)
#define ABC_PRTP(a, t, T)
static double Abc_MaxDouble(double a, double b)
static void Abc_PrintTime(int level, const char *pStr, abctime time)
int * Abc_MergeSortCost(int *pCosts, int nSize)
static int Abc_MinInt(int a, int b)
void Abc_MergeSort(int *pInput, int nSize)
static int Abc_LitIsCompl(int Lit)
static int Abc_Float2Int(float Val)
char * vnsprintf(const char *format, va_list args)
unsigned __int64 word
DECLARATIONS ///.
static int Abc_Base10Log(unsigned n)
void Abc_QuickSort1(word *pData, int nSize, int fDecrease)
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
void Abc_QuickSort3(word *pData, int nSize, int fDecrease)
void Abc_QuickSort2(word *pData, int nSize, int fDecrease)
static void Abc_Print(int level, const char *format,...)
#define ABC_NAMESPACE_HEADER_END
static void * Abc_Wrd2Ptr(word i)
static void Abc_InfoSetBit(unsigned *p, int i)
static int Abc_LitNot(int Lit)
#define ABC_PRMP(a, f, F)
static int Abc_Base2Log(unsigned n)
int Gia_ManToBridgeAbsNetlist(FILE *pFile, void *p, int pkg_type)
static int Abc_Lit2Var(int Lit)
static float Abc_Int2Float(int Num)
static double Abc_MinDouble(double a, double b)
static int Abc_BitWordNum(int nBits)
static int Abc_LitRegular(int Lit)
static void * Abc_Int2Ptr(int i)
static word Abc_Ptr2Wrd(void *p)
static void Abc_PrintInt(int i)
char * nsprintf(const char *format,...)
static word Abc_MaxWord(word a, word b)